Skip to content

Commit 4f67a68

Browse files
committed
Infra: AWS 초기 설정
- 간단한 구조 1. VPC (1) 2. Subnet (2) -> Private, Public 3. EC2 (1)
1 parent 717e722 commit 4f67a68

File tree

1 file changed

+101
-2
lines changed

1 file changed

+101
-2
lines changed

infra/terraform/main.tf

Lines changed: 101 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,110 @@ provider "aws" {
1212
region = "ap-northeast-2"
1313
}
1414

15-
resource "aws_vpc" "example" {
15+
# VPC_1
16+
resource "aws_vpc" "vpc_1" {
1617
cidr_block = "10.0.0.0/16"
18+
enable_dns_support = true
19+
enable_dns_hostnames = true
1720

1821
tags = {
19-
Name = "example"
22+
Name = "team5-vpc-1"
2023
}
2124
}
2225

26+
# 퍼블릭 서브넷 (Subnet_1)
27+
resource "aws_subnet" "subnet_1" {
28+
vpc_id = aws_vpc.vpc_1.id
29+
cidr_block = "10.0.1.0/24"
30+
availability_zone = "ap-northeast-2a"
31+
map_public_ip_on_launch = true # 퍼블릭 IP 자동 할당
32+
33+
tags = {
34+
Name = "team5-subnet-1-public"
35+
}
36+
}
37+
38+
# 프라이빗 서브넷 (Subnet_2)
39+
resource "aws_subnet" "subnet_2" {
40+
vpc_id = aws_vpc.vpc_1.id
41+
cidr_block = "10.0.2.0/24"
42+
availability_zone = "ap-northeast-2b"
43+
44+
tags = {
45+
Name = "team5-subnet-2-private"
46+
}
47+
}
48+
49+
# 인터넷 게이트 웨이
50+
resource "aws_internet_gateway" "igw_1" {
51+
vpc_id = aws_vpc.vpc_1.id
52+
53+
tags = {
54+
Name = "team5-igw-1"
55+
}
56+
}
57+
58+
# 라우팅 테이블
59+
resource "aws_route_table" "rt_1" {
60+
vpc_id = aws_vpc.vpc_1.id
61+
62+
# 모든 트래픽에 대해 인터넷 게이트웨이로 보냄
63+
route {
64+
cidr_block = "0.0.0.0/0"
65+
gateway_id = aws_internet_gateway.igw_1.id
66+
}
67+
68+
tags = {
69+
Name = "team5-rt-1"
70+
}
71+
}
72+
73+
resource "aws_route_table_association" "association_1" {
74+
# 연결할 서브넷
75+
subnet_id = aws_subnet.subnet_1.id
76+
77+
# 연결할 라우트 테이블 지정
78+
route_table_id = aws_route_table.rt_1.id
79+
}
80+
81+
resource "aws_route_table_association" "association_2" {
82+
# 연결할 서브넷
83+
subnet_id = aws_subnet.subnet_2.id
84+
85+
# 연결할 라우트 테이블 지정
86+
route_table_id = aws_route_table.rt_1.id
87+
}
88+
89+
resource "aws_security_group" "sg_1" {
90+
name = "team5-sg-1"
91+
description = "Allow SSH and HTTP"
92+
vpc_id = aws_vpc.vpc_1.id
93+
94+
ingress {
95+
from_port = 0
96+
to_port = 0
97+
protocol = "all" # 모든 프로토콜
98+
cidr_blocks = ["0.0.0.0/0"] # 모든 IP 허용
99+
}
100+
101+
egress {
102+
from_port = 0
103+
to_port = 0
104+
protocol = "all" # 모든 프로토콜
105+
cidr_blocks = ["0.0.0.0/0"] # 모든 IP 허용
106+
}
107+
}
108+
109+
resource "aws_instance" "ec2_1" {
110+
ami = "ami-077ad873396d76f6a"
111+
instance_type = "t2.micro"
112+
113+
subnet_id = aws_subnet.subnet_1.id
114+
vpc_security_group_ids = [aws_security_group.sg_1.id]
115+
116+
associate_public_ip_address = true
117+
118+
tags = {
119+
Name = "team5-ec2-1"
120+
}
121+
}

0 commit comments

Comments
 (0)