【发布时间】:2021-11-17 07:35:14
【问题描述】:
尝试制作一个简单的 vpc/安全组模块集。 VPC 资源在这里:
resource "aws_vpc" "main" {
cidr_block = var.cidr
}
安全组资源在这里:
resource "aws_security_group" "default" {
name = var.sg-name
vpc_id = aws_vpc.main.id
description = var.sg-description
}
resource "aws_security_group_rule" "ingress" {
count = length(var.allowed_ip)
type = "ingress"
from_port = element(var.allowed_ports, count.index)
to_port = element(var.allowed_ports, count.index)
protocol = var.protocol
cidr_blocks = var.allowed_ip
security_group_id = aws_security_group.default.id
}
resource "aws_security_group_rule" "egress" {
type = "egress"
from_port = 0
to_port = 65535
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
security_group_id = aws_security_group.default.id
}
模块在这里:
module "vpc" {
source = "../"
cidr = "10.0.0.0/16"
}
module "security_group" {
source = "../"
sg-name = "Test"
sg-description = "Test Description"
protocol = "tcp"
allowed_ip = ["10.10.0.0/20", "10.20.0.0/20"]
allowed_ports = [22, 443]
}
当我运行 Terraform Plan 时,我收到此错误:
错误:预期 cidr_block 包含有效值,得到:错误: 无效的 CIDR 地址:
在 ..\vpc.tf 第 2 行,在资源“aws_vpc”“main”中:2:
cidr_block = var.cidr
我做了很多研究,但无法完全确定问题所在。有人有什么想法吗?
【问题讨论】:
-
我认为您的目录结构有些奇怪。您源上的那些目录路径是否正确?
标签: amazon-web-services terraform terraform-provider-aws