@@ -19,7 +19,9 @@ resource "aws_vpc" "vpc_1" {
1919 enable_dns_hostnames = true
2020
2121 tags = {
22- Name = " team5-vpc-1"
22+ Key = " TEAM"
23+ Value = " devcos-team05"
24+ Name = " team5-vpc-1"
2325 }
2426}
2527
@@ -31,7 +33,9 @@ resource "aws_subnet" "subnet_1" {
3133 map_public_ip_on_launch = true # 퍼블릭 IP 자동 할당
3234
3335 tags = {
34- Name = " team5-subnet-1-public"
36+ Key = " TEAM"
37+ Value = " devcos-team05"
38+ Name = " team5-subnet-1-public"
3539 }
3640}
3741
@@ -42,7 +46,9 @@ resource "aws_subnet" "subnet_2" {
4246 availability_zone = " ap-northeast-2a"
4347
4448 tags = {
45- Name = " team5-subnet-2-private"
49+ Key = " TEAM"
50+ Value = " devcos-team05"
51+ Name = " team5-subnet-2-private"
4652 }
4753}
4854
@@ -53,7 +59,9 @@ resource "aws_subnet" "subnet_3" {
5359 availability_zone = " ap-northeast-2b"
5460
5561 tags = {
56- Name = " team5-subnet-3-private"
62+ Key = " TEAM"
63+ Value = " devcos-team05"
64+ Name = " team5-subnet-3-private"
5765 }
5866}
5967
@@ -62,7 +70,9 @@ resource "aws_internet_gateway" "igw_1" {
6270 vpc_id = aws_vpc. vpc_1 . id
6371
6472 tags = {
65- Name = " team5-igw-1"
73+ Key = " TEAM"
74+ Value = " devcos-team05"
75+ Name = " team5-igw-1"
6676 }
6777}
6878
@@ -77,7 +87,9 @@ resource "aws_route_table" "rt_1" {
7787 }
7888
7989 tags = {
80- Name = " team5-rt-1"
90+ Key = " TEAM"
91+ Value = " devcos-team05"
92+ Name = " team5-rt-1"
8193 }
8294}
8395
@@ -104,8 +116,14 @@ resource "aws_route_table_association" "association_3" {
104116}
105117
106118resource "aws_security_group" "sg_1" {
107- name = " team5-sg-1"
108- vpc_id = aws_vpc. vpc_1 . id
119+ name = " team5-sg-1"
120+ vpc_id = aws_vpc. vpc_1 . id
121+
122+ tags = {
123+ Key = " TEAM"
124+ Value = " devcos-team05"
125+ Name = " team5-sg-1"
126+ }
109127
110128 ingress {
111129 from_port = 0
@@ -124,7 +142,11 @@ resource "aws_security_group" "sg_1" {
124142
125143# EC2 역할 생성
126144resource "aws_iam_role" "ec2_role_1" {
127- name = " team5-ec2-role-1"
145+ tags = {
146+ Key = " TEAM"
147+ Value = " devcos-team05"
148+ Name = " team5-ec2-role-1"
149+ }
128150
129151 # 이 역할에 대한 신뢰 정책 설정. EC2 서비스가 이 역할을 가정할 수 있도록 설정
130152 assume_role_policy = << EOF
@@ -152,26 +174,62 @@ resource "aws_iam_role_policy_attachment" "ec2_ssm" {
152174
153175# IAM 인스턴스 프로파일 생성
154176resource "aws_iam_instance_profile" "instance_profile_1" {
155- name = " team5-instance-profile-1"
177+ tags = {
178+ Key = " TEAM"
179+ Value = " devcos-team05"
180+ Name = " team5-instance-profile-1"
181+ }
182+
156183 role = aws_iam_role. ec2_role_1 . name
157184}
158185
159186# EC2 실행마다 적용할 작업
160187locals {
161188 ec2_user_data_base = <<- END_OF_FILE
162189#!/bin/bash
163- yum install docker -y
164- systemctl enable docker
165- systemctl start docker
166-
167- yum install git -y
168-
190+ # 가상 메모리 4GB 설정
169191sudo dd if=/dev/zero of=/swapfile bs=128M count=32
170192sudo chmod 600 /swapfile
171193sudo mkswap /swapfile
172194sudo swapon /swapfile
173195sudo sh -c 'echo "/swapfile swap swap defaults 0 0" >> /etc/fstab'
174196
197+ # git 설치
198+ yum install git -y
199+
200+ #도커 설치 및 실행/활성화
201+ yum install docker -y
202+ systemctl enable docker
203+ systemctl start docker
204+
205+ # 도커 네트워크 생성
206+ docker network create common
207+
208+ # redis 설치
209+ docker run -d \
210+ --name redis_1 \
211+ --network common \
212+ -p 6379:6379 \
213+ -e TZ=Asia/Seoul \
214+ -v /dockerProjects/redis_1/volumes/data:/data \
215+ redis --requirepass ${ var . password_1 }
216+
217+ # NginX 설치
218+ docker run -d \
219+ --name npm_1 \
220+ --restart unless-stopped \
221+ --network common \
222+ -p 80:80 \
223+ -p 443:443 \
224+ -p 81:81 \
225+ -e TZ=Asia/Seoul \
226+ 227+ -e INITIAL_ADMIN_PASSWORD=${ var . password_1 } \
228+ -v /dockerProjects/npm_1/volumes/data:/data \
229+ -v /dockerProjects/npm_1/volumes/etc/letsencrypt:/etc/letsencrypt \
230+ jc21/nginx-proxy-manager:latest
231+
232+
175233END_OF_FILE
176234}
177235
@@ -189,7 +247,9 @@ resource "aws_instance" "ec2_1" {
189247 iam_instance_profile = aws_iam_instance_profile. instance_profile_1 . name
190248
191249 tags = {
192- Name = " team5-ec2-1"
250+ Key = " TEAM"
251+ Value = " devcos-team05"
252+ Name = " team5-ec2-1"
193253 }
194254
195255 # 루트 불륨 설정
@@ -211,9 +271,9 @@ resource "aws_security_group" "rds_sg_1" {
211271 vpc_id = aws_vpc. vpc_1 . id
212272
213273 ingress {
214- from_port = 3306
215- to_port = 3306
216- protocol = " tcp"
274+ from_port = 3306
275+ to_port = 3306
276+ protocol = " tcp"
217277 cidr_blocks = [" 0.0.0.0/0" ]
218278 }
219279
@@ -225,7 +285,9 @@ resource "aws_security_group" "rds_sg_1" {
225285 }
226286
227287 tags = {
228- Name = " team5-rds-sg-1"
288+ Key = " TEAM"
289+ Value = " devcos-team05"
290+ Name = " team5-rds-sg-1"
229291 }
230292}
231293
@@ -235,7 +297,9 @@ resource "aws_db_subnet_group" "db_subnet_group" {
235297 subnet_ids = [aws_subnet . subnet_2 . id , aws_subnet . subnet_3 . id ]
236298
237299 tags = {
238- Name = " team5-db-subnet-group"
300+ Key = " TEAM"
301+ Value = " devcos-team05"
302+ Name = " team5-db-subnet-group"
239303 }
240304}
241305
@@ -260,10 +324,12 @@ resource "aws_db_instance" "mysql" {
260324 # 자동 백업 보관 기간
261325 backup_retention_period = 1
262326
263- # 삭제 시 최종 스냅샷 생성 여부 (개발용은 true, 운영은 false 권장)
327+ # 삭제 시 최종 스냅샷 생성 여부
264328 skip_final_snapshot = true
265329
266330 tags = {
267- Name = " team5-rds-mysql"
331+ Key = " TEAM"
332+ Value = " devcos-team05"
333+ Name = " team5-mysql"
268334 }
269335}
0 commit comments