AWS中具有实例Az ID的Terraform标签实例

时间:2019-03-09 02:03:22

标签: terraform terraform-provider-aws

有人可以帮助我实现使用实例可用区ID标记实例吗?

resource aws_instance this{
  ..
  tag {
    key = az
    Value = <this.Instance_az_id>
  }
}

示例键az和值us-east-2a

预先感谢

1 个答案:

答案 0 :(得分:-1)

您可以从定义实例时指定的子网中获取可用区。

resource "aws_instance" "this" {
  subnet_id = "${aws_subnet.a.id}" 
  tags {
    az = "${aws_subnet.a.availability_zone}"
  }
}

resource "aws_subnet" "a" {
  vpc_id = "${aws_vpc.main.id}"
  cidr_block = "10.0.1.0/24"
  availability_zone = "us-east-1a"
}

即使您没有为子网定义AZ,这仍然可以工作(尽管运行这样的设置很危险。)