Skip to content

Commit bcff6dc

Browse files
committed
Infra: AWS 인스턴스 Tags 추가
- tags { Key = "Team" Value = "devcos-teamxx" Name = "인스턴스 name" }
1 parent 74d2005 commit bcff6dc

File tree

2 files changed

+52
-15
lines changed

2 files changed

+52
-15
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,5 @@ db_dev.trace.db
4646
/infra/terraform/.terraform
4747
/infra/terraform/.terraform.lock.hcl
4848
/infra/terraform/terraform.tfstate
49-
/infra/terraform/terraform.tfstate.backup
49+
/infra/terraform/terraform.tfstate.backup
50+
/infra/terraform/secrets.tf

infra/terraform/main.tf

Lines changed: 50 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -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 = "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 = "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 = "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 = "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 = "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 = "rt-1"
8193
}
8294
}
8395

@@ -104,9 +116,15 @@ resource "aws_route_table_association" "association_3" {
104116
}
105117

106118
resource "aws_security_group" "sg_1" {
107-
name = "team5-sg-1"
119+
name = "team5-sg-1"
108120
vpc_id = aws_vpc.vpc_1.id
109121

122+
tags = {
123+
Key = "TEAM"
124+
Value = "devcos-team05"
125+
Name = "sg-1"
126+
}
127+
110128
ingress {
111129
from_port = 0
112130
to_port = 0
@@ -124,7 +142,11 @@ resource "aws_security_group" "sg_1" {
124142

125143
# EC2 역할 생성
126144
resource "aws_iam_role" "ec2_role_1" {
127-
name = "team5-ec2-role-1"
145+
tags = {
146+
Key = "TEAM"
147+
Value = "devcos-team05"
148+
Name = "ec2-role-1"
149+
}
128150

129151
# 이 역할에 대한 신뢰 정책 설정. EC2 서비스가 이 역할을 가정할 수 있도록 설정
130152
assume_role_policy = <<EOF
@@ -152,7 +174,12 @@ resource "aws_iam_role_policy_attachment" "ec2_ssm" {
152174

153175
# IAM 인스턴스 프로파일 생성
154176
resource "aws_iam_instance_profile" "instance_profile_1" {
155-
name = "team5-instance-profile-1"
177+
tags = {
178+
Key = "TEAM"
179+
Value = "devcos-team05"
180+
Name = "instance-profile-1"
181+
}
182+
156183
role = aws_iam_role.ec2_role_1.name
157184
}
158185

@@ -172,6 +199,7 @@ sudo mkswap /swapfile
172199
sudo swapon /swapfile
173200
sudo sh -c 'echo "/swapfile swap swap defaults 0 0" >> /etc/fstab'
174201
202+
175203
END_OF_FILE
176204
}
177205

@@ -189,7 +217,9 @@ resource "aws_instance" "ec2_1" {
189217
iam_instance_profile = aws_iam_instance_profile.instance_profile_1.name
190218

191219
tags = {
192-
Name = "team5-ec2-1"
220+
Key = "TEAM"
221+
Value = "devcos-team05"
222+
Name = "ec2-1"
193223
}
194224

195225
# 루트 불륨 설정
@@ -206,7 +236,7 @@ EOF
206236

207237
# RDS용 Security Group
208238
resource "aws_security_group" "rds_sg_1" {
209-
name = "team5-rds-sg-1"
239+
name = "team5-rds-sg-1"
210240
description = "Allow All"
211241
vpc_id = aws_vpc.vpc_1.id
212242

@@ -225,7 +255,9 @@ resource "aws_security_group" "rds_sg_1" {
225255
}
226256

227257
tags = {
228-
Name = "team5-rds-sg-1"
258+
Key = "TEAM"
259+
Value = "devcos-team05"
260+
Name = "rds-sg-1"
229261
}
230262
}
231263

@@ -235,7 +267,9 @@ resource "aws_db_subnet_group" "db_subnet_group" {
235267
subnet_ids = [aws_subnet.subnet_2.id, aws_subnet.subnet_3.id]
236268

237269
tags = {
238-
Name = "team5-db-subnet-group"
270+
Key = "TEAM"
271+
Value = "devcos-team05"
272+
Name = "db-subnet-group"
239273
}
240274
}
241275

@@ -264,6 +298,8 @@ resource "aws_db_instance" "mysql" {
264298
skip_final_snapshot = true
265299

266300
tags = {
267-
Name = "team5-rds-mysql"
301+
Key = "TEAM"
302+
Value = "devcos-team05"
303+
Name = "mysql"
268304
}
269305
}

0 commit comments

Comments
 (0)