我正在尝试获取与ID为“ i-0abcdefgh1234”的实例相关联的安全组,但输出未给出结果。
data "aws_instance" "ec2" {
instance_id = "i-0abcdefgh1234"
filter {
name = "tag:Name"
values = ["name-of-the-server"]
}
}
output "sg" {
value = "${data.aws_instance.ec2.*.security_groups}"
}
data.aws_instance.ec2: Refreshing state...
------------------------------------------------------------------------
No changes. Infrastructure is up-to-date.
This means that Terraform did not detect any differences between your
configuration and real physical resources that exist. As a result, no
actions need to be performed.
在下面有无*时尝试过
value = "${data.aws_instance.ec2.*.security_groups}"
答案 0 :(得分:0)
数据源的插值语法为data.TYPE.NAME.ATTRIBUTE
。参见this
在您的情况下,它将为${data.aws_instance.ec2.security_groups}
但是,由于documentation的状态-“某些值并不总是被设置,并且可能无法用于插值。”