반응형
Terraform으로 AWS Internet Gateway 생성하기
아키텍처 흐름
[ Internet ]
↓
[ Internet Gateway ]
↓
[ Route Table (0.0.0.0/0) ]
↓
[ Public Subnet ]
1. 사전 조건
- VPC 생성 완료
- Subnet 구성 완료 (Public / Private)
2. Internet Gateway 리소스 정의
vim igw.tf
resource "aws_internet_gateway" "igw" {
vpc_id = aws_vpc.sangchul_vpc11.id
tags = {
Name = "${var.vpc_name}-igw"
Environment = var.env
Owner = "iac"
Service = "network"
Role = "internet-gateway"
CreatedBy = "Terraform"
}
}
3. 실행 절차
3.1 실행 계획 확인 (권장)
terraform plan -out=tfplan
3.2 IGW 생성
terraform apply tfplan
또는
terraform apply
aws_vpc.sangchul_vpc11: Refreshing state... [id=vpc]
aws_subnet.sangchul_vpc11-sb14: Refreshing state... [id=subnet]
aws_subnet.sangchul_vpc11-sb13: Refreshing state... [id=subnet]
aws_subnet.sangchul_vpc11-sb3: Refreshing state... [id=subnet]
aws_subnet.sangchul_vpc11-sb4: Refreshing state... [id=subnet]
An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
+ create
Terraform will perform the following actions:
...
Plan: 1 to add, 0 to change, 0 to destroy.
Do you want to perform these actions?
Terraform will perform the actions described above.
Only 'yes' will be accepted to approve.
Enter a value: yes
aws_internet_gateway.sangchul_vpc11-igw: Creating...
aws_internet_gateway.sangchul_vpc11-igw: Creation complete after 5s [id=igw]
Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
4. 생성 결과 확인
terraform show
또는 AWS CLI
aws ec2 describe-internet-gateways \
--filters "Name=attachment.vpc-id,Values=$(terraform output -raw vpc_id)"
5. Output 설정 (권장)
vim outputs.tf
output "igw_id" {
value = aws_internet_gateway.igw.id
}
728x90
반응형
'퍼블릭 클라우드' 카테고리의 다른 글
| Terraform 리소스 그래프 생성 방법 (0) | 2021.02.01 |
|---|---|
| Terraform으로 AWS Route Table 구성하기 (0) | 2021.01.29 |
| Terraform으로 AWS Subnet 생성하기 (0) | 2021.01.29 |
| Terraform으로 AWS VPC 생성하기 (0) | 2021.01.29 |
| Terraform AWS Provider 설정 방법 (Profile 기반) (0) | 2021.01.29 |