Skip to content

Commit e3ffd12

Browse files
authored
Infra: AWS 초기세팅
* Infra: 테라폼 기본 세팅 - main.tf 파일 생성 - .gitignore에 terraform에 대한 민감한 정보를 등록 * Infra: AWS 초기 설정 - 간단한 구조 1. VPC (1) 2. Subnet (2) -> Private, Public 3. EC2 (1)
1 parent 41a38ba commit e3ffd12

File tree

2 files changed

+128
-1
lines changed

2 files changed

+128
-1
lines changed

.gitignore

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,10 @@ out/
3939
### Custom ###
4040
db_dev.mv.db
4141
db_dev.trace.db
42-
.env
42+
.env
43+
44+
### Terraform ###
45+
/infra/terraform/.terraform
46+
/infra/terraform/.terraform.lock.hcl
47+
/infra/terraform/terraform.tfstate
48+
/infra/terraform/terraform.tfstate.backup

infra/terraform/main.tf

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
terraform {
2+
// aws 라이브러리 불러옴
3+
required_providers {
4+
aws = {
5+
source = "hashicorp/aws"
6+
}
7+
}
8+
}
9+
10+
# 디폴드 리전 설정
11+
provider "aws" {
12+
region = "ap-northeast-2"
13+
}
14+
15+
# VPC_1
16+
resource "aws_vpc" "vpc_1" {
17+
cidr_block = "10.0.0.0/16"
18+
enable_dns_support = true
19+
enable_dns_hostnames = true
20+
21+
tags = {
22+
Name = "team5-vpc-1"
23+
}
24+
}
25+
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)