【发布时间】:2020-12-08 06:59:59
【问题描述】:
我有创建 N 个安全组的 terraform 脚本:
variable "security_groups" {
default = {
"sg1" = "Security group 1"
"sg2" = "Security group 2"
}
}
resource "aws_security_group" "example" {
for_each = var.security_groups
name = each.key
description = each.value
vpc_id = aws_vpc.example.id
revoke_rules_on_delete = false
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}
..我还有另一个创建 IAM 策略的 Terraform 脚本,
这个必须引用资源部分中第一个脚本创建的 N 个安全组:
resource "aws_iam_policy" "operator_policy" {
name = "${var.iam_prefix}-operator"
path = "/"
description = "Policy for operator"
policy = <<-EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"ec2:AuthorizeSecurityGroupEgress",
"ec2:AuthorizeSecurityGroupIngress",
"ec2:UpdateSecurityGroupRuleDescriptionsEgress",
"ec2:UpdateSecurityGroupRuleDescriptionsIngress",
"ec2:RevokeSecurityGroupEgress",
"ec2:RevokeSecurityGroupIngress"
],
"Effect": "Allow",
"Resource": [
"sg1 ARN",
"sgN ARN"
]
}
]
}
EOF
}
是否可行?
【问题讨论】:
标签: amazon-web-services terraform