bcosta12
bcosta12

Reputation: 2452

Terraform setting options for a variable dynamically

I am converting a AWS CloudFormation to Terraform template.

When I am creating a VPC in AWS CloudFormation I can set a pre-defined values, such as the Availability Zones, enabling me to choose which Availability Zones to use in certain deployment, like below:

Parameters:
  AvailabilityZones:
    Description: 'List of Availability Zones to use for the subnets in the VPC. Note:
      The logical order is preserved.'
    Type: List<AWS::EC2::AvailabilityZone::Name>

enter image description here

What can be done in Terraform to simulate this behavior (pre-defined values based on a list of given values)?

Upvotes: 1

Views: 291

Answers (1)

Martin Atkins
Martin Atkins

Reputation: 74694

The most direct analog to this CloudFormation feature in Terraform is Input Variables, which allow you to define something essentially equivalent to what you have in CloudFormation:

variable "availability_zone" {
  type        = list(string)
  description = "List of Availability Zones to use for the subnets in the VPC. Note: The logical order is preserved."
}

One difference compared to CloudFormation is that Terraform doesn't have a first-class type for "availablity zone name", and so a string containing the name is how the AWS provider's typical representation of an availability zone.

I'm not sure exactly what you are asking but I think you were also asking about the specific CloudFormation UI you took a screenshot of, where the UI itself understands the concept of an availability zone and so it can provide extra help like autocompletion. Terraform module input variables are typically configured in code rather than via a web UI, so there isn't any direct analog to that CloudFormation feature in Terraform.

Upvotes: 3

Related Questions