terraform script with veriables

Limited Time Offer!

For Less Than the Cost of a Starbucks Coffee, Access All DevOpsSchool Videos on YouTube Unlimitedly.
Master DevOps, SRE, DevSecOps Skills!

Enroll Now

code for creating ec2 instance and git repo

terraform {
  required_providers {
    aws = {
      source = "hashicorp/aws"
      version = "3.49.0"
    }
    github = {
      source  = "integrations/github"
      version = "~> 4.0"
    }
  }
}
provider "aws" {
  region     = "us-west-2"
  access_key = "  "
  secret_key = " "
}

resource "aws_instance" "first-ec2" {
  ami           = "ami-03d5c68bab01f3496" # us-west-2
  instance_type = "t2.micro"
  
  tags = {
    Name = "godwin"
  }
}

git repo using string variable

provider "github" {
  token = "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" # or `GITHUB_TOKEN`
}

variable "reponame" {
  type = string
  description = "This is for demo of string variable"
  default = "test_repo"
}

resource "github_repository" "example" {
  name        = "${var.reponame}"
  description = "My awesome codebase"
  private = false
}

git repo creating using list variable

variable "gitrepos" {
    type    = list
    default = ["my_test1","my_test2","my_test3"]
    description = "This is for demo of list variable"
}






resource "github_repository" "repo1" {
  name = "${var.gitrepos[0]}"
  description = "My awesome codebase"
  private = false
}



resource "github_repository" "repo2" {
  name = "${var.gitrepos[1]}"
  description = "My awesome codebase"
  private = false
}