-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvpc.tf
105 lines (84 loc) · 2.08 KB
/
vpc.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# ./vpc.tf
# VPC 생성
resource "aws_vpc" "k8s_vpc" {
cidr_block = "10.0.0.0/16"
enable_dns_hostnames = true
enable_dns_support = true
tags = {
Name = "k8s-vpc"
}
}
# 퍼블릭 서브넷 생성
resource "aws_subnet" "public_subnet" {
vpc_id = aws_vpc.k8s_vpc.id
cidr_block = "10.0.1.0/24"
availability_zone = var.availability_zone
map_public_ip_on_launch = true
tags = {
Name = "k8s-public-subnet"
}
}
# 프라이빗 서브넷 생성
resource "aws_subnet" "private_subnet" {
vpc_id = aws_vpc.k8s_vpc.id
cidr_block = "10.0.2.0/24"
availability_zone = var.availability_zone
tags = {
Name = "k8s-private-subnet"
}
}
# 인터넷 게이트웨이 생성
resource "aws_internet_gateway" "k8s_igw" {
vpc_id = aws_vpc.k8s_vpc.id
tags = {
Name = "k8s-igw"
}
}
# EIP for NAT Gateway
resource "aws_eip" "nat_eip" {
domain = "vpc"
tags = {
Name = "k8s-nat-eip"
}
}
# NAT 게이트웨이 생성
resource "aws_nat_gateway" "k8s_nat" {
allocation_id = aws_eip.nat_eip.id
subnet_id = aws_subnet.public_subnet.id
tags = {
Name = "k8s-nat"
}
depends_on = [aws_internet_gateway.k8s_igw]
}
# 퍼블릭 라우팅 테이블
resource "aws_route_table" "public_rt" {
vpc_id = aws_vpc.k8s_vpc.id
route {
cidr_block = "0.0.0.0/0"
gateway_id = aws_internet_gateway.k8s_igw.id
}
tags = {
Name = "k8s-public-rt"
}
}
# 프라이빗 라우팅 테이블
resource "aws_route_table" "private_rt" {
vpc_id = aws_vpc.k8s_vpc.id
route {
cidr_block = "0.0.0.0/0"
nat_gateway_id = aws_nat_gateway.k8s_nat.id
}
tags = {
Name = "k8s-private-rt"
}
}
# 퍼블릭 서브넷 라우팅 테이블 연결
resource "aws_route_table_association" "public_rta" {
subnet_id = aws_subnet.public_subnet.id
route_table_id = aws_route_table.public_rt.id
}
# 프라이빗 서브넷 라우팅 테이블 연결
resource "aws_route_table_association" "private_rta" {
subnet_id = aws_subnet.private_subnet.id
route_table_id = aws_route_table.private_rt.id
}