TF aws_security_group:属性“ingress”的值不合适:需要属性“prefix_list_ids”、“security_groups”和“self”

Jos*_*rán 7 terraform terraform-provider-aws terraform0.12+

我正在学习 Terraform 和 AWS,但在创建资源时遇到了麻烦aws_security_group

\n

我从Terraform 文档复制了此资源的示例,然后配置了我的数据(我想通过 SSH 访问我的 EC2 资源。我知道这不是一个好的做法,但我只是在学习,我会测试后销毁)

\n
resource "aws_security_group" "allow_tls_ssh" {\n  name        = "allow_tls"\n  description = "Allow TLS inbound traffic"\n  vpc_id      = aws_vpc.vpc.id\n\n  ingress = [\n    {\n      description      = "TLS from VPC"\n      from_port        = 443\n      to_port          = 443\n      protocol         = "tcp"\n      cidr_blocks      = [aws_vpc.vpc.cidr_block]\n      ipv6_cidr_blocks = [aws_vpc.vpc.ipv6_cidr_block]\n      prefix_list_ids  = []\n      security_groups  = []\n      self = false\n    },\n    {\n      description      = "SSH from VPC"\n      from_port        = 22\n      to_port          = 22\n      protocol         = "tcp"\n      cidr_blocks      = [aws_vpc.vpc.cidr_block]\n      ipv6_cidr_blocks = [aws_vpc.vpc.ipv6_cidr_block]\n      prefix_list_ids  = []\n      security_groups  = []\n      self = false\n    },\n    {\n      description      = "HTTP from VPC"\n      from_port        = 80\n      to_port          = 80\n      protocol         = "tcp"\n      cidr_blocks      = [aws_vpc.vpc.cidr_block]\n      ipv6_cidr_blocks = [aws_vpc.vpc.ipv6_cidr_block]\n      prefix_list_ids  = []\n      security_groups  = []\n      self = false\n    }\n  ]\n\n  tags = {\n    Name = "allow_tls_ssh"\n  }\n}\n
Run Code Online (Sandbox Code Playgroud)\n

然后,当我terraform apply得到:

\n
\n(...)\n\n\xe2\x94\x82   59:     }\n\xe2\x94\x82   60:   ]\n\xe2\x94\x82     \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\n\xe2\x94\x82     \xe2\x94\x82 aws_vpc.vpc.cidr_block will be known only after apply\n\xe2\x94\x82     \xe2\x94\x82 aws_vpc.vpc.ipv6_cidr_block will be known only after apply\n\xe2\x94\x82 \n\xe2\x94\x82 Inappropriate value for attribute "ingress": element 0: attributes "prefix_list_ids", "security_groups", and "self" are required.\n\xe2\x95\xb5\n
Run Code Online (Sandbox Code Playgroud)\n

这个错误让我很困惑。为什么我在创建安全组时必须指定 security_groups?

\n

小智 -1

在尝试创建安全组来打开所有流量时,我也遇到了同样的问题,但是,我通过尝试下面的“null”找到了解决方案。我已经将它用于所有流量,如果您想指定某些流量,请随意修改它。