Home > OS >  Question About Terraform Language (Count)
Question About Terraform Language (Count)

Time:10-06

data "aws_availability_zones" "available" {
  state = "available"
}

resource "aws_subnet" "subnet" {
  count = length(data.aws.availability_zones.available.names)

  # ...
}

let say the legion in my area has 4 availability zones. (A,B,C,D)

and the code creates a subnet on each AZs.

but I want to create a subnet on A and B only.

can I achieve that goal by editing this line?

  count = length(data.aws.availability_zones.available.names)

Or the only answer is adding another resource?

thank you for your time

CodePudding user response:

If you want to use only the first two AZs, then you can do:

resource "aws_subnet" "subnet" {
  count = 2
  availability_zone = data.aws_availability_zones.available.names[count.index]
  #...
}

  • Related