【发布时间】:2019-06-15 15:51:35
【问题描述】:
terraform/env/res/main.tf:
resource "aws_security_group" "allow_all" {
name = "allow_all"
description = "Allow all inbound traffic"
vpc_id = "${aws_vpc.main.id}"
ingress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}
terraform/mod/sec/main.tf:
resource aws_elb " elb" {
name = "elb-example"
subnets = ["${data.aws_subnet_ids.all.ids}"]
security_groups = ["${aws_security_group.allow_all.id}"] // SG
internal = false
listener = [
{
instance_port = "80"
instance_protocol = "HTTP"
lb_port = "80"
lb_protocol = "HTTP"
},
{
instance_port = "8080"
instance_protocol = "HTTP"
lb_port = "8080"
lb_protocol = "HTTP"
},
]
health_check = [
{
target = "HTTP:80/"
interval = 30
healthy_threshold = 2
unhealthy_threshold = 2
timeout = 5
},
]
access_logs = [
{
bucket = "my-access-logs-bucket"
},
]
lifecycle {
prevent_destroy = true
}
}
遇到错误未定义变量 aws_security_group.allow_all 在变量 aws_security_group.allow_all_id 中。此外,是否可以验证字符串并添加额外的安全组。三元条件是我能想到的。您能否提出其他替代方案?
【问题讨论】:
-
您的文件在您使用数据源的地方是什么样的?
-
我正在创建一个 aws_elb 资源并在其中访问此安全组。资源 "aws_elb" "myelb" { security_groups_1 = [ "${aws_security_group.allow_all.id}" ] @yd
-
编辑问题以显示整个第二个文件并显示每个文件的文件路径。如果这是很多代码,那么您应该考虑尝试将其剥离为 minimal reproducible example
-
你能在你的代码上运行
terraform fmt吗?
标签: terraform