I'm learning Terraform and AWS and I'm having trouble by creating an aws_security_group resource.
I copied from the Terraform Docs an example of this resource, then I configured with my data (I want to access my EC2 resources via SSH. I know that is not a good practice but I'm only learning and I'm going to destroy after the test)
resource "aws_security_group" "allow_tls_ssh" {
name = "allow_tls"
description = "Allow TLS inbound traffic"
vpc_id = aws_vpc.vpc.id
ingress = [
{
description = "TLS from VPC"
from_port = 443
to_port = 443
protocol = "tcp"
cidr_blocks = [aws_vpc.vpc.cidr_block]
ipv6_cidr_blocks = [aws_vpc.vpc.ipv6_cidr_block]
prefix_list_ids = []
security_groups = []
self = false
},
{
description = "SSH from VPC"
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = [aws_vpc.vpc.cidr_block]
ipv6_cidr_blocks = [aws_vpc.vpc.ipv6_cidr_block]
prefix_list_ids = []
security_groups = []
self = false
},
{
description = "HTTP from VPC"
from_port = 80
to_port = 80
protocol = "tcp"
cidr_blocks = [aws_vpc.vpc.cidr_block]
ipv6_cidr_blocks = [aws_vpc.vpc.ipv6_cidr_block]
prefix_list_ids = []
security_groups = []
self = false
}
]
tags = {
Name = "allow_tls_ssh"
}
}
Then, when I terraform apply I get:
(...)
│ 59: }
│ 60: ]
│ ├────────────────
│ │ aws_vpc.vpc.cidr_block will be known only after apply
│ │ aws_vpc.vpc.ipv6_cidr_block will be known only after apply
│
│ Inappropriate value for attribute "ingress": element 0: attributes "prefix_list_ids", "security_groups", and "self" are required.
╵
This error confuses me. Why do I have to indicate security_groups when I'm creating one?