Cloud Infra Architecture (AWS)/AWS Terraform
Terraform IGW, Nat gateway 생성
seongduck
2024. 2. 4. 19:29
Terraform VPC, subnet 생성
1) Provicder.tf 생성 vim provider " provider "aws" { region = "ap-northeast-1" } " 2) VPC 생성 vim vpc.tf " resource "aws_vpc" "main" { cidr_block = "ip대역" tage = { Name = "vpc-dev-ircp" } } 3) terraform init - plan - apply terraform init terraform
seongduck.tistory.com
위의 글에서 이어서 진행ㄷ
기존에 vpc.tf에 만들어 놨던 파일을 열어 작업을 진행한다.
1) IGW 생성
vim vpc.tf
"
resource "aws_internet_gateway" "igw-dev-ircp-public-gw-01" {
vpc_id = aws_vpc.main.id
tags = {
Name = "igw-dev-ircp-public-gw-01"
}
}
"
terraform plan
terraform apply
2) Nat gateway 생성
vim vpc.tf
"
resource "aws_eip" "nat" {
vpc = true
lifecycle {
create_before_destroy = true
}
}
"
// EIP 생성
resource "aws_nat_gateway" "nat-dev-ircp-public-gw-01" {
allocation_id = aws_eip.nat.id
subnet_id = aws_subnet.sbn-dev-ircp-public-resource-az2a.id
tags = {
Name = "nat-dev-ircp-public-gw-01"
}
}
terraform plan
terraform apply