如何有条件地创建 aws_eip 和 aws_eip_association?
how to conditionally create aws_eip and aws_eip_association?
我需要能够有条件地创建一个 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_eip
和 aws_eip_association
似乎不支持 count
属性,所以我不清楚这是否可行?
有什么想法吗?
如评论中所述,所有 Terraform 原始资源都支持计数。以下 aws_eip 的示例:
resource "aws_eip" "eip" {
instance = "${element(aws_instance.manager.*.id,count.index)}"
count = "${var.eip_count}"
vpc = true
}
我需要能够有条件地创建一个 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_eip
和 aws_eip_association
似乎不支持 count
属性,所以我不清楚这是否可行?
有什么想法吗?
如评论中所述,所有 Terraform 原始资源都支持计数。以下 aws_eip 的示例:
resource "aws_eip" "eip" {
instance = "${element(aws_instance.manager.*.id,count.index)}"
count = "${var.eip_count}"
vpc = true
}