gpt4 book ai didi

amazon-web-services - Terraform:创建 SG 时属性 "ingress"的值不合适

转载 作者:行者123 更新时间:2023-12-04 12:12:22 25 4
gpt4 key购买 nike

我正在使用 terraform 创建一个安全组,并且在运行 terraform 计划时。它给了我一个错误,比如某些字段是必需的,而所有这些字段都是可选的。
地形版本:v1.0.5
AWS 提供商版本:v3.57.0

main.tf

resource "aws_security_group" "sg_oregon" {
name = "tf-sg"
description = "Allow web traffics"
vpc_id = aws_vpc.vpc_terraform.id

ingress = [
{
description = "HTTP"
from_port = 80
to_port = 80
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
},
{
description = "HTTPS"
from_port = 443
to_port = 443
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
},

{
description = "SSH"
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
]


egress = [
{
description = "for all outgoing traffics"
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
ipv6_cidr_blocks = ["::/0"]

}
]

tags = {
Name = "sg-for-subnet"
}
}

error in console

│ Inappropriate value for attribute "ingress": element 0: attributes "ipv6_cidr_blocks", "prefix_list_ids", "security_groups", and "self" are required.

│ Inappropriate value for attribute "egress": element 0: attributes "prefix_list_ids", "security_groups", and "self" are required.
我正在关注此文档: https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group
任何帮助,将不胜感激。

最佳答案

由于您使用的是 Attributes as Blocks你必须为所有选项提供值 :

resource "aws_security_group" "sg_oregon" {
name = "tf-sg"
description = "Allow web traffics"
vpc_id = aws_vpc.vpc_terraform.id

ingress = [
{
description = "HTTP"
from_port = 80
to_port = 80
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
ipv6_cidr_blocks = []
prefix_list_ids = []
security_groups = []
self = false
},
{
description = "HTTPS"
from_port = 443
to_port = 443
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
ipv6_cidr_blocks = []
prefix_list_ids = []
security_groups = []
self = false
},

{
description = "SSH"
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
ipv6_cidr_blocks = []
prefix_list_ids = []
security_groups = []
self = false
}
]


egress = [
{
description = "for all outgoing traffics"
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
ipv6_cidr_blocks = ["::/0"]
prefix_list_ids = []
security_groups = []
self = false
}
]

tags = {
Name = "sg-for-subnet"
}
}

关于amazon-web-services - Terraform:创建 SG 时属性 "ingress"的值不合适,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69079945/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com