I have a VPC defined in terraform:
//vpc.tf
resource "aws_vpc" "my_vpc" {
cidr_block = "10.0.0.0/16"
}
And I am trying to create a security group:
// securityGroup.tf
resource "aws_security_group" "allow_tls" {
name = "allow_tls"
description = "Allow TLS inbound traffic"
vpc_id = aws_vpc.my_vpc.id
ingress {
description = "TLS from VPC"
from_port = 443
to_port = 443
protocol = "tcp"
cidr_blocks = [aws_vpc.my_vpc.cidr_block]
ipv6_cidr_blocks = [aws_vpc.my_vpc.ipv6_cidr_block]
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
ipv6_cidr_blocks = ["::/0"]
}
}
However, when I run terraform plan
I get the error Error: "" is not a valid CIDR block: invalid CIDR address:
I thought that the cidr_block
defined in my vpc would be available to the securityGroup, but that seems to not be the case. How do I correctly reference the cidr_block
from my vpc?
Full error output:
│ Error: "" is not a valid CIDR block: invalid CIDR address:
│
│ with module.shared.aws_security_group.allow_tls,
│ on modules/shared/securityGroup.tf line 1, in resource "aws_security_group" "allow_tls":
│ 1: resource "aws_security_group" "allow_tls" {