@@ -19,9 +19,9 @@ resource "aws_vpc" "vpc_1" {
1919 enable_dns_hostnames = true
2020
2121 tags = {
22- Key = " TEAM"
22+ Key = " TEAM"
2323 Value = " devcos-team05"
24- Name = " vpc-1"
24+ Name = " team5- vpc-1"
2525 }
2626}
2727
@@ -33,9 +33,9 @@ resource "aws_subnet" "subnet_1" {
3333 map_public_ip_on_launch = true # 퍼블릭 IP 자동 할당
3434
3535 tags = {
36- Key = " TEAM"
36+ Key = " TEAM"
3737 Value = " devcos-team05"
38- Name = " subnet-1-public"
38+ Name = " team5- subnet-1-public"
3939 }
4040}
4141
@@ -46,9 +46,9 @@ resource "aws_subnet" "subnet_2" {
4646 availability_zone = " ap-northeast-2a"
4747
4848 tags = {
49- Key = " TEAM"
49+ Key = " TEAM"
5050 Value = " devcos-team05"
51- Name = " subnet-2-private"
51+ Name = " team5- subnet-2-private"
5252 }
5353}
5454
@@ -59,9 +59,9 @@ resource "aws_subnet" "subnet_3" {
5959 availability_zone = " ap-northeast-2b"
6060
6161 tags = {
62- Key = " TEAM"
62+ Key = " TEAM"
6363 Value = " devcos-team05"
64- Name = " subnet-3-private"
64+ Name = " team5- subnet-3-private"
6565 }
6666}
6767
@@ -70,9 +70,9 @@ resource "aws_internet_gateway" "igw_1" {
7070 vpc_id = aws_vpc. vpc_1 . id
7171
7272 tags = {
73- Key = " TEAM"
73+ Key = " TEAM"
7474 Value = " devcos-team05"
75- Name = " igw-1"
75+ Name = " team5- igw-1"
7676 }
7777}
7878
@@ -87,9 +87,9 @@ resource "aws_route_table" "rt_1" {
8787 }
8888
8989 tags = {
90- Key = " TEAM"
90+ Key = " TEAM"
9191 Value = " devcos-team05"
92- Name = " rt-1"
92+ Name = " team5- rt-1"
9393 }
9494}
9595
@@ -116,13 +116,13 @@ resource "aws_route_table_association" "association_3" {
116116}
117117
118118resource "aws_security_group" "sg_1" {
119- name = " team5-sg-1"
120- vpc_id = aws_vpc. vpc_1 . id
119+ name = " team5-sg-1"
120+ vpc_id = aws_vpc. vpc_1 . id
121121
122122 tags = {
123- Key = " TEAM"
123+ Key = " TEAM"
124124 Value = " devcos-team05"
125- Name = " sg-1"
125+ Name = " team5- sg-1"
126126 }
127127
128128 ingress {
@@ -143,9 +143,9 @@ resource "aws_security_group" "sg_1" {
143143# EC2 역할 생성
144144resource "aws_iam_role" "ec2_role_1" {
145145 tags = {
146- Key = " TEAM"
146+ Key = " TEAM"
147147 Value = " devcos-team05"
148- Name = " ec2-role-1"
148+ Name = " team5- ec2-role-1"
149149 }
150150
151151 # 이 역할에 대한 신뢰 정책 설정. EC2 서비스가 이 역할을 가정할 수 있도록 설정
@@ -175,9 +175,9 @@ resource "aws_iam_role_policy_attachment" "ec2_ssm" {
175175# IAM 인스턴스 프로파일 생성
176176resource "aws_iam_instance_profile" "instance_profile_1" {
177177 tags = {
178- Key = " TEAM"
178+ Key = " TEAM"
179179 Value = " devcos-team05"
180- Name = " instance-profile-1"
180+ Name = " team5- instance-profile-1"
181181 }
182182
183183 role = aws_iam_role. ec2_role_1 . name
@@ -187,18 +187,48 @@ resource "aws_iam_instance_profile" "instance_profile_1" {
187187locals {
188188 ec2_user_data_base = <<- END_OF_FILE
189189#!/bin/bash
190- yum install docker -y
191- systemctl enable docker
192- systemctl start docker
193-
194- yum install git -y
195-
190+ # 가상 메모리 4GB 설정
196191sudo dd if=/dev/zero of=/swapfile bs=128M count=32
197192sudo chmod 600 /swapfile
198193sudo mkswap /swapfile
199194sudo swapon /swapfile
200195sudo sh -c 'echo "/swapfile swap swap defaults 0 0" >> /etc/fstab'
201196
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+
202232
203233END_OF_FILE
204234}
@@ -217,9 +247,9 @@ resource "aws_instance" "ec2_1" {
217247 iam_instance_profile = aws_iam_instance_profile. instance_profile_1 . name
218248
219249 tags = {
220- Key = " TEAM"
250+ Key = " TEAM"
221251 Value = " devcos-team05"
222- Name = " ec2-1"
252+ Name = " team5- ec2-1"
223253 }
224254
225255 # 루트 불륨 설정
@@ -236,14 +266,14 @@ EOF
236266
237267# RDS용 Security Group
238268resource "aws_security_group" "rds_sg_1" {
239- name = " team5-rds-sg-1"
269+ name = " team5-rds-sg-1"
240270 description = " Allow All"
241271 vpc_id = aws_vpc. vpc_1 . id
242272
243273 ingress {
244- from_port = 3306
245- to_port = 3306
246- protocol = " tcp"
274+ from_port = 3306
275+ to_port = 3306
276+ protocol = " tcp"
247277 cidr_blocks = [" 0.0.0.0/0" ]
248278 }
249279
@@ -255,9 +285,9 @@ resource "aws_security_group" "rds_sg_1" {
255285 }
256286
257287 tags = {
258- Key = " TEAM"
288+ Key = " TEAM"
259289 Value = " devcos-team05"
260- Name = " rds-sg-1"
290+ Name = " team5- rds-sg-1"
261291 }
262292}
263293
@@ -267,9 +297,9 @@ resource "aws_db_subnet_group" "db_subnet_group" {
267297 subnet_ids = [aws_subnet . subnet_2 . id , aws_subnet . subnet_3 . id ]
268298
269299 tags = {
270- Key = " TEAM"
300+ Key = " TEAM"
271301 Value = " devcos-team05"
272- Name = " db-subnet-group"
302+ Name = " team5- db-subnet-group"
273303 }
274304}
275305
@@ -294,12 +324,12 @@ resource "aws_db_instance" "mysql" {
294324 # 자동 백업 보관 기간
295325 backup_retention_period = 1
296326
297- # 삭제 시 최종 스냅샷 생성 여부 (개발용은 true, 운영은 false 권장)
327+ # 삭제 시 최종 스냅샷 생성 여부
298328 skip_final_snapshot = true
299329
300330 tags = {
301- Key = " TEAM"
331+ Key = " TEAM"
302332 Value = " devcos-team05"
303- Name = " mysql"
333+ Name = " team5- mysql"
304334 }
305335}
0 commit comments