하마롱크의 블로그
AWS에서 Terraform 기본 구성(1) 본문
1. Provider 블록 추가 및 SSH Key Pair 배포
- public key는 하드코딩을 하기 보다는 해당 파일을 지정
provider "aws" {
region = "ap-northeast-2"
}
resource "aws_key_pair" "test_key" {
key_name = "test-key"
public_key = file("../../.ssh/id_rsa.pub")
}
2. VPC 생성
resource "aws_vpc" "test_vpc" {
cidr_block = "10.0.0.0/16"
tags = {
Name = "test-vpc"
}
}
3. Subnet 생성
# 가용영역 a의 Public Subnet
resource "aws_subnet" "test_puba" {
vpc_id = aws_vpc.test_vpc.id
cidr_block = "10.0.0.0/24"
availability_zone = "ap-northeast-2a"
tags = {
Name = "test-puba"
}
}
# 가용영역 a의 Private Subnet
resource "aws_subnet" "test_pria" {
vpc_id = aws_vpc.test_vpc.id
cidr_block = "10.0.1.0/24"
availability_zone = "ap-northeast-2a"
tags = {
Name = "test-pria"
}
}
# 가용영역 c의 Public Subnet
resource "aws_subnet" "test_pubc" {
vpc_id = aws_vpc.test_vpc.id
cidr_block = "10.0.2.0/24"
availability_zone = "ap-northeast-2c"
tags = {
Name = "test-pubc"
}
}
# 가용영역 c의 Private Subnet
resource "aws_subnet" "test_pric" {
vpc_id = aws_vpc.test_vpc.id
cidr_block = "10.0.3.0/24"
availability_zone = "ap-northeast-2c"
tags = {
Name = "test-pric"
}
}
4. Internet Gateway 생성
resource "aws_internet_gateway" "test_ig" {
vpc_id = aws_vpc.test_vpc.id
tags = {
Name = "test-ig"
}
}
5. Public Routing Table 생성
resource "aws_route_table" "test_rt" {
vpc_id = aws_vpc.test_vpc.id
route {
cidr_block = "0.0.0.0/0"
gateway_id = aws_internet_gateway.test_ig.id
}
tags = {
Name = "test-rt"
}
}
6. Public Subnet 연결
resource "aws_route_table_association" "test-rtas_a" {
subnet_id = aws_subnet.test_puba.id
route_table_id = aws_route_table.test_rt.id
}
resource "aws_route_table_association" "test-rtas_c" {
subnet_id = aws_subnet.test_pubc.id
route_table_id = aws_route_table.test_rt.id
}
'Terraform' 카테고리의 다른 글
테라폼 모듈(Terraform Module) (0) | 2021.11.02 |
---|---|
AWS에서 Terraform 기본 구성(3) (0) | 2021.10.30 |
AWS에서 Terraform 기본 구성(2) (0) | 2021.10.29 |
테라폼(Terraform) (0) | 2021.10.27 |