TF aws_security_group:属性“ingress”的值不合适:需要属性“prefix_list_ids”、“security_groups”和“self”
Posted
技术标签:
【中文标题】TF aws_security_group:属性“ingress”的值不合适:需要属性“prefix_list_ids”、“security_groups”和“self”【英文标题】:TF aws_security_group: Inappropriate value for attribute "ingress": attributes "prefix_list_ids", "security_groups", and "self" are required 【发布时间】:2021-11-06 05:48:33 【问题描述】:我正在学习 Terraform 和 AWS,但在创建 aws_security_group
资源时遇到了麻烦。
我从Terraform Docs 复制了此资源的一个示例,然后我配置了我的数据(我想通过 SSH 访问我的 EC2 资源。我知道这不是一个好习惯,但我只是在学习,我我要在测试后销毁)
resource "aws_security_group" "allow_tls_ssh"
name = "allow_tls"
description = "Allow TLS inbound traffic"
vpc_id = aws_vpc.vpc.id
ingress = [
description = "TLS from VPC"
from_port = 443
to_port = 443
protocol = "tcp"
cidr_blocks = [aws_vpc.vpc.cidr_block]
ipv6_cidr_blocks = [aws_vpc.vpc.ipv6_cidr_block]
prefix_list_ids = []
security_groups = []
self = false
,
description = "SSH from VPC"
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = [aws_vpc.vpc.cidr_block]
ipv6_cidr_blocks = [aws_vpc.vpc.ipv6_cidr_block]
prefix_list_ids = []
security_groups = []
self = false
,
description = "HTTP from VPC"
from_port = 80
to_port = 80
protocol = "tcp"
cidr_blocks = [aws_vpc.vpc.cidr_block]
ipv6_cidr_blocks = [aws_vpc.vpc.ipv6_cidr_block]
prefix_list_ids = []
security_groups = []
self = false
]
tags =
Name = "allow_tls_ssh"
然后,当我terraform apply
我得到:
(...)
│ 59:
│ 60: ]
│ ├────────────────
│ │ aws_vpc.vpc.cidr_block will be known only after apply
│ │ aws_vpc.vpc.ipv6_cidr_block will be known only after apply
│
│ Inappropriate value for attribute "ingress": element 0: attributes "prefix_list_ids", "security_groups", and "self" are required.
╵
这个错误让我很困惑。为什么我在创建时必须指明 security_groups?
【问题讨论】:
***.com/a/69080432/2291321 会回答您的问题吗?基本上它取决于你使用attribute as block style。 【参考方案1】:在尝试创建安全组以打开所有流量时,我也遇到了同样的问题,但是,我通过尝试下面的“null”找到了解决方案。我已经将它用于所有流量,如果您想指定某些流量,请随时修改它。
【讨论】:
正如目前所写,您的答案尚不清楚。请edit 添加其他详细信息,以帮助其他人了解这如何解决所提出的问题。你可以找到更多关于如何写好答案的信息in the help center。以上是关于TF aws_security_group:属性“ingress”的值不合适:需要属性“prefix_list_ids”、“security_groups”和“self”的主要内容,如果未能解决你的问题,请参考以下文章
学习笔记TF023:下载缓存属性字典惰性属性覆盖数据流图资源