
처음 시작하는 Infrastructure as Code: AWS & 테라폼을 수강하며 정리한 내용입니다.
vpc.tf 파일에 IGW 리소스를 이어서 작성resource "aws_vpc" "main" {
cidr_block = "10.0.0.0/16"
tags = {
Name = "terraform-101"
}
}
resource "aws_subnet" "public_subnet" {
vpc_id = aws_vpc.main.id
cidr_block = "10.0.0.0/24"
availability_zone = "ap-northeast-2a"
tags = {
Name = "terraform-101-public-subnet"
}
}
resource "aws_subnet" "private_subnet" {
vpc_id = aws_vpc.main.id
cidr_block = "10.0.10.0/24"
tags = {
Name = "terraform-101-private-subnet"
}
}
resource "aws_internet_gateway" "igw" {
vpc_ic = aws_vpc.main.id
tags = {
Name = "terraform-101-igw"
}
}
terraform plan으로 변경될 사항 확인
terraform apply로 변경될 사항 적용
vim.tf 파일에 Elastic IP와 NAT Gateway 리소스 작성resource "aws_eip" "nat" {
domain = "vpc"
lifecycle {
create_before_destroy = true
}
}
resource "aws_nat_gateway" "nat_gateway" {
allocation_id = aws_eip.nat.id
subnet_id = aws_subnet.public_subnet.id
tags = {
Name = "terraform-NATGW"
}
}
terraform plan 명령어 실행

terraform apply 명령어 실행

주의사항: NAT Gateway는 비용이 발생하는 서비스여서 AWS 등록된 결제 수단으로 비용이 청구될 수 있음


