Terraform Scripts On Variables

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

Number

variable "num_of_groups" {
  type = number
  description = "Number variable"
  default = 3
}

resource "aws_iam_group" "developers" {

  count = "${var.num_of_groups}"
  name = "developers.${count.index}"

}

String

variable "instance_name" {
  description = "Value of the Name tag for the EC2 instance"
  type        = string
  default     = "ExampleAppServerInstance"
}
 resource "aws_instance" "app_server" {
   ami           = "ami-08d70e59c07c61a3a"
   instance_type = "t2.micro"

   tags = {
-    Name = "ExampleAppServerInstance"
   Name = var.instance_name
   }
 }

List

variable "gitrepos" {
    type    = list
    default = ["harish_1", "harish_2", "harish_3"]
    description = "list variable"
}


resource "github_repository" "repo1" {
  name = "${var.gitrepos[0]}"
  description = "creating first repository"
  private = false
}

resource "github_repository" "repo2" {
  name = "${var.gitrepos[1]}"
  description = "creating secondrepository"
  private = false
}

resource "github_repository" "repo3" {
  name = "${var.gitrepos[2]}"
  description = "creating third repository"
  private = false
}

Map

variable "user_name" {
   type = map
  default = {
      "user1" = "hari_1"
      "user2" = "hari_2"
      "user3" = "hari_3"
}
}
resource "aws_iam_user" "iamuser" {
  for_each = var.user_name
  name = "${each.value}-iam"
}

Boolean

variable "set_password" {
  type    = bool
  default = false
}

resource "git_password" "example" {
  create_password = "${var.set_password}"
}