Terraform conditional statements

 


 

Exmaple :- Create a EC2 instance if the env is prod

provider "aws" {
  region ="us-east-1"
}

variable "env" {
  default="prod"
}
resource "aws_instance" "name" {
  ami =var.ami
  instance_type=var.instance_type
  count = "${var.env=="prod" ? 1 :0}"
}

Comments