Warm tip: This article is reproduced from serverfault.com, please click

Terraform

发布于 2020-11-30 18:52:01

I am looking to launch a subnet in the 'a' or 'b' availability zone of any region I specify - is there a way I can allow terraform to do this?

Something along the lines of this:

variable "az" {
  default = {
    a = 1
    b = 2
  }
}

resource "aws_subnet" "example" {
  vpc_id = aws_vpc.vpc.id
  availability_zone = var.az.(places subnets in either of the specified AZs)
}
Questioner
J. Patwary
Viewed
0
Mark B 2020-12-01 03:36:40

You could simply take the current region name, and append the a or b characters to it, like so:

data "aws_region" "current" {}

locals {
 az1 = "${data.aws_region.current.name}a"
 az2 = "${data.aws_region.current.name}b"
}