
처음 시작하는 Infrastructure as Code: AWS & 테라폼을 수강하며 정리한 내용입니다.
vpc.tf 파일에 Route Table 리소스를 이어서 작성resource "aws_route_table" "public" {
vpc_id = aws_vpc.main.id
tags = {
Name = "terraform-101-rt-public"
}
}
resource "aws_route_table" "private" {
vpc_id = aws_vpc.main.id
tags = {
Name = "terraform-101-rt-private"
}
}
terraform plan으로 확인 후 terraform apply로 리소스 생성
vpc.tf 파일에 association 내용 추가 resource "aws_route_table" "public" {
vpc_id = aws_vpc.main.id
tags = {
Name = "terraform-101-rt-public"
}
}
resource "aws_route_table_association" "route_table_association_public" {
subnet_id = aws_subnet.public_subnet.id
route_table_id = aws_route_table.public.id
}
resource "aws_route_table" "private" {
vpc_id = aws_vpc.main.id
tags = {
Name = "terraform-101-rt-private"
}
}
resource "aws_route_table_association" "route_table_association_private" {
subnet_id = aws_subnet.private_subnet.id
route_table_id = aws_route_table.private.id
}
terraform plan으로 확인 후 terraform apply로 적용

0.0.0.0/0에 대해 IGW로 연결, 이를 통해 Public 서브넷이 제 역할을 할 수 있게 됨resource "aws_route_table" "public" {
vpc_id = aws_vpc.main.id
route {
cidr_block = "0.0.0.0/0"
gateway_id = aws_internet_gateway.igw.id
}
tags = {
Name = "terraform-101-rt-public"
}
}
terraform plan으로 확인 후 terraform apply로 적용
resource "aws_route" "private_nat" {
route_table_id = aws_route_table.private.id
destination_cidr_block = "0.0.0.0/0"
nat_gateway_id = aws_nat_gateway.nat_gateway.id
}
terraform plan으로 확인 후 terraform apply로 적용


terraform plan 명령어를 입력하면 다시 규칙을 추가할 것이라고 표시됨
plan이나 apply 명령어를 입력할 때 실제 리소스를 검사terraform apply로 다시 리소스를 생성