Cloud/Terraform

Terraform - Internet Gateway 생성 및 Public subnet용 Route table 구성

잇(IT) 2022. 7. 9. 19:11

resource "aws_internet_gateway" "gw" {
  vpc_id = aws_vpc.main.id

  tags = {
    Name = "main"
  }
}

resource "aws_route_table" "example" {
  vpc_id = aws_vpc.example.id

  route {
    cidr_block = "10.0.1.0/24"
    gateway_id = aws_internet_gateway.example.id
  }

  route {
    ipv6_cidr_block        = "::/0"
    egress_only_gateway_id = aws_egress_only_internet_gateway.example.id
  }

  tags = {
    Name = "example"
  }
}

- 해당 라우팅 테이블에 인터넷 게이트 웨이를 넣을 것이기 때문에 id를 지정해준다.

 

resource "aws_route_table_association" "a" {
  subnet_id      = aws_subnet.foo.id
  route_table_id = aws_route_table.bar.id
}

- 라우팅 테이블 associate 즉, 해당 라우팅 테이블에 해당 서브넷을 포함 시킨다.

728x90