以下是Terraform脚本。
variable "vpc_ids" {
default = [
"vpc-**********",
"vpc-**********",
"vpc-**********",
"vpc-**********",
]
type = "list"
}
data "aws_security_groups" "test" {
filter {
name = "vpc-id"
values = "${var.vpc_ids}"
}
}
data "aws_security_group" "selected" {
count = "${length(data.aws_security_groups.test.ids)}"
id = "${element(data.aws_security_groups.test.ids, count.index)}"
}
output "sec_groups" {
value = "${data.aws_security_group.selected.0.description}"
// value = "${join(",", data.aws_security_group.selected.*.description)}"
}
最后,我使用的是说明,但它没有提供安全组的入站和出站规则。
有人知道如何使用数据源来制定入站和出站规则吗?
答案 0 :(得分:0)
data "aws_security_group"
没有任何规则属性:
https://www.terraform.io/docs/providers/aws/d/security_group.html#attributes-reference
也许您对具有规则的resource "aws_security_group"
感到困惑:
https://www.terraform.io/docs/providers/aws/r/security_group.html#attributes-reference
要在安全组存在时使用该资源,必须首先将其导入。