V3 Variables in Terraform

V3 Variables in Terraform

 V3 Variables in Terraform





provider.tf file contents
  provider "aws" {
  region     = "us-west-2"
  access_key = "xyz"
  secret_key = "xyz"
}

variables.tf file contents
  
 
 variable "file_names" {
    default = ["devops.txt","chef.txt","terraform.txt"]
    type=list
}

variable "f_content" {
    default = "hi devops"
}

main.tf file contains
resource "local_file" "foo" {
    count=3
    filename = var.file_names[count.index]
    content = var.f_content
}

Lab-Task

main.tf file contains
resource "aws_instance" "web" {
  count=3
  ami           = var.os_id
  instance_type = "t2.micro"

  tags = {
    Name = var.vms_names[count.index]
  }
}

variables.tf file contains
variable "os_id" {
    default = "ami-083ac7c7ecf9bb9b0"
}

variable "vms_names" {
    type=list
    default = ["web1","app1","db1"]
}

variable "env" {
  default = "prod"
}

Presentation Link : Variables in Terraform

Post a Comment

0 Comments