테라폼으로 vpc 만들던 중 db server의 인바운드 규칙을 설정하려다가 계속 실패했다.
# webserver
resource "aws_security_group" "web_server_sg" {
name = "web_server_sg"
description = "security group for web server"
vpc_id = aws_vpc.vpc.id
ingress {
description = "For ssh port"
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
description = "For http port"
from_port = 80
to_port = 80
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
description = "For https port"
from_port = 443
to_port = 443
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
egress {
protocol = "-1"
from_port = 0
to_port = 0
cidr_blocks = ["0.0.0.0/0"]
}
tags = {
Name = "web_server_sg"
}
}
# dbserver
resource "aws_security_group" "DB_server_sg" {
name = "DB_server_sg"
description = "security group for DB server"
vpc_id = aws_vpc.vpc.id
ingress {
description = "For sql port"
from_port = 3306
to_port = 3306
protocol = "tcp"
#cidr_blocks = [aws_security_group.web_server_sg.id]
security_groups = [aws_security_group.web_server_sg.id]
}
egress {
protocol = "-1"
from_port = 0
to_port = 0
cidr_blocks = ["0.0.0.0/0"]
}
tags = {
Name = "DB_server_sg"
}
}
cidr_blocks = [aws_security_group.web_server_sg.id]
이렇게 cidr_blocks 라는 변수를 그대로 놔두고 값만 바꿔보고 있었는데 값은 문제가 없이
Error: "vpc-03fba27eec8bf4b12" is not a valid CIDR block: invalid CIDR address: vpc-03fba27eec8bf4b12
이런식으로 잘 나왔다
그래서 다른 글들을 찾아보다
https://potato-yong.tistory.com/114
이 분이 작성한 글을 보다보니 ingress에 security group이 있는 걸 보고 다시 만들어 봤다.
security_groups = [aws_security_group.web_server_sg.id]
다행히도 설정해둔대로 잘 만들어 졌다