如何有条件地创建aws_eip和aws_eip_association?

问题描述 投票:0回答:1

我需要能够有条件地创建一个EIP并将其关联到实例:

resource "aws_eip" "gateway" {
  vpc = true

  tags = {
    Name = "${var.project_id}-gateway"
    Project = "${var.project_id}"
    user = "${var.user}"
  }
}

resource "aws_eip_association" "eip_assoc_gateway" {
  instance_id   = aws_instance.gateway.id
  allocation_id = aws_eip.gateway.id
}

resource "aws_instance" "gateway" {
...
}

不幸的是,aws_eipaws_eip_association似乎不支持count属性,所以我不清楚这是否可能吗?

有什么想法吗?

terraform terraform-provider-aws
1个回答
0
投票

如评论中所述,所有Terraform基本资源均支持count。下面的aws_eip示例:

resource "aws_eip" "eip" {
  instance   = "${element(aws_instance.manager.*.id,count.index)}"
  count = "${var.eip_count}"
  vpc = true

}
© www.soinside.com 2019 - 2024. All rights reserved.