amazon-web-services - Terraform:创建 SG 时属性“入口”的值不合适
问题描述
我正在使用 terraform 创建一个安全组,并且在运行 terraform 计划时。它给了我一个错误,例如某些字段是必需的,并且所有这些字段都是可选的。
地形版本:v1.0.5
AWS 提供商版本:v3.57.0
主文件
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"
}
}
控制台中的错误
│ 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
任何帮助,将不胜感激。
解决方案
由于您将属性用作块,因此您必须为所有选项提供值:
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"
}
}
推荐阅读
- asp.net - asp.net core 和 postgresql 迁移中的调用目标引发了异常
- amazon-s3 - 如何有效地检索具有特定数据的 kinesis 数据分析 S3 接收器文件
- sql - 有没有办法通过数组的内容过滤 BigQuery 中的行?
- java - 如果 xml 格式不正确,则 Java DOM xml 阅读器
- python - Windows 操作系统上的 python-snappy 安装错误
- java - 如何在 Hibernate 中获取具有偏移量和计数的行?
- c# - 如何使用蛋糕构建系统查找项目类型?
- regex - 如何使用 sed 替换 http 或 https?
- javascript - Discord.JS bulkDelete 14 天错误预防?
- shell - 在 xml 文件中,如果该属性不存在,则使用 shell 脚本将属性附加到节点元素