以下代码在layout.html.twig
但是,当ec2_instance_count = 1
出现以下错误。
ec2_instance_count = 2
我认为这与if语句Error: Error running plan: 1 error(s) occurred:
* module.build_ec2_app.aws_ebs_volume.ebs_volume: 1 error(s) occurred:
* module.build_ec2_app.aws_ebs_volume.ebs_volume: Resource 'aws_instance.ec2' not found for variable 'aws_instance.ec2.availability_zone'
但是,即使我将两种资源上的var.ec2_create_volume == "true" ? 1 : 0
更改为"true" ? 1 : 0
,当"true" ? 2 : 0
时仍然会出现错误
ec2_instance_count = 2
答案 0 :(得分:1)
这里的问题是,当SELECT s.SS || y.YYYY AS SSYYYY
FROM
(
SELECT to_number(to_char(SYSDATE, 'YYYY')) + LEVEL - 1 AS YYYY
FROM dual
CONNECT BY LEVEL <= 4
) y
CROSS JOIN (
SELECT DECODE(level, 1, 'FA', 2, 'WI', 3, 'SP', 4, 'SU') AS SS
FROM dual
CONNECT BY LEVEL <= 4
) s
ORDER BY y.YYYY, s.SS
的{{1}}增加到2时,资源属性导出将从字符串更改为列表,而您仍将其引用为字符串。您可以在at the documentation here上看到更多信息。
通过更新count
和aws_instance.ec2
资源以期望列表而不是字符串并相应地迭代volume_attachment
资源,可以解决问题:
ebs_volume
请注意,即使aws_instance
为1,这仍然可以正常工作。这里的建议是也将# Create EBS volume
resource "aws_ebs_volume" "ebs_volume" {
count = "${var.ec2_create_volume == "true" ? 1 : 0}"
availability_zone = "${aws_instance.ec2.*.availability_zone[count.index]}"
size = "${var.ec2_ebs_volume_size}"
}
# Attach EBS Volume
resource "aws_volume_attachment" "volume_attachment" {
count = "${var.ec2_create_volume == "true" ? 1 : 0}"
device_name = "${var.ec2_device_name}"
volume_id = "${aws_ebs_volume.ebs_volume.*.id[count.index]}"
instance_id = "${aws_instance.ec2.*.id[count.index]}"
}
资源的count
与其他资源的count
同步两个,以确保它们相同。
aws_instance
将输入var锁定在一起可以确保您在更改实例数量时具有所需的行为,并且因此不会出现不希望的问题和副作用。