Skip to content

Commit 38a36e6

Browse files
committed
fix: 잘못 참조된 변수 수정
1 parent d0199f1 commit 38a36e6

File tree

5 files changed

+58
-59
lines changed

5 files changed

+58
-59
lines changed

terraform/dev/ecs/task/variables.tf

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ variable "ecs_task_definitions" {
1414
})), [])
1515

1616
container_definitions = list(object({
17-
name = string
18-
image = string
19-
cpu = number
20-
memory = number
21-
essential = bool
22-
stopTimeout = number
17+
name = string
18+
image = string
19+
cpu = number
20+
memory = number
21+
essential = bool
22+
stopTimeout = optional(number)
2323

2424
command = optional(list(string))
2525

terraform/dev/ecs/variables.tf

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,17 @@ variable "ecs_task_definitions" {
3232
})), [])
3333

3434
container_definitions = list(object({
35-
name = string
36-
image = string
37-
cpu = number
38-
memory = number
39-
essential = bool
40-
stopTimeout = number
35+
name = string
36+
image = string
37+
cpu = number
38+
memory = number
39+
essential = bool
40+
stopTimeout = optional(number)
4141

4242
command = optional(list(string))
4343

4444
portMappings = list(object({
45-
name = string
45+
name = optional(string)
4646
containerPort = number
4747
hostPort = number
4848
protocol = string

terraform/dev/locals.tf

Lines changed: 27 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -63,25 +63,40 @@ locals {
6363
}
6464

6565
container_definitions_map = {
66-
for svc, task_def in local.task_definitions_with_roles : svc =>
67-
(svc == "api-dev" ?
66+
for svc, task_def in local.task_definitions_with_roles : svc => flatten([
6867
[
6968
{
70-
name = "api-dev"
71-
image = "${local.ecr_repo_urls["dev"]}:placeholder"
69+
name = svc
70+
image = svc == "api-dev" ? "${local.ecr_repo_urls["dev"]}:placeholder" : task_def.container_image
7271
cpu = task_def.cpu
7372
memory = contains(keys(task_def), "memory") ? task_def.memory : null
73+
memoryReservation = lookup(task_def, "memoryReservation", null)
7474
essential = true
75-
command = [
75+
command = svc == "api-dev" ? tolist([
7676
"java", "-javaagent:/dd-java-agent.jar",
7777
"-Ddd.logs.injection=true", "-Ddd.runtime-metrics.enabled=true",
7878
"-Ddd.service=eatda-api", "-Ddd.env=dev", "-Ddd.version=v1",
7979
"-Ddd.agent.host=127.0.0.1",
8080
"-Dspring.profiles.active=dev", "-jar", "/api.jar"
81+
]) : tolist([])
82+
portMappings = [
83+
for m in lookup(task_def, "port_mappings", []) :
84+
{ containerPort = m.container_port, hostPort = m.host_port, protocol = m.protocol }
85+
]
86+
environment = [for k, v in lookup(task_def, "environment", {}) : { name = k, value = v }]
87+
secrets = [for s in lookup(task_def, "secrets", []) : { name = s.name, valueFrom = s.valueFrom }]
88+
mountPoints = [
89+
for vol in lookup(task_def, "volumes", []) : {
90+
sourceVolume = vol.name
91+
containerPath = (
92+
(svc == "mysql-dev" && vol.name == "dev-mysql-volume") ? "/var/lib/mysql" : vol.containerPath
93+
)
94+
readOnly = false
95+
}
8196
]
82-
portMappings = [{ containerPort = 8080, hostPort = 0, protocol = "tcp" }]
83-
mountPoints = [{ sourceVolume = "dev-api-volume", containerPath = "/logs", readOnly = false }]
84-
},
97+
}
98+
],
99+
svc == "api-dev" ? [
85100
{
86101
name = "datadog-agent"
87102
image = "public.ecr.aws/datadog/agent:latest"
@@ -102,32 +117,11 @@ locals {
102117
{ sourceVolume = "proc", containerPath = "/host/proc", readOnly = true },
103118
{ sourceVolume = "cgroup", containerPath = "/host/sys/fs/cgroup", readOnly = true }
104119
]
120+
command = tolist([])
121+
portMappings = []
105122
}
106-
]
107-
:
108-
[
109-
{
110-
name = svc
111-
image = task_def.container_image
112-
cpu = task_def.cpu
113-
memory = task_def.memory
114-
essential = true
115-
portMappings = [
116-
for m in lookup(task_def, "port_mappings", []) :
117-
{ containerPort = m.container_port, hostPort = m.host_port, protocol = m.protocol }
118-
]
119-
environment = [for k, v in lookup(task_def, "environment", {}) : { name = k, value = v }]
120-
secrets = [for s in lookup(task_def, "secrets", []) : { name = s.name, valueFrom = s.valueFrom }]
121-
mountPoints = [
122-
for vol in lookup(task_def, "volumes", []) : {
123-
sourceVolume = vol.name
124-
containerPath = (svc == "mysql-dev" && vol.name == "dev-mysql-volume") ? "/var/lib/mysql" :
125-
vol.containerPath
126-
readOnly = false
127-
}
128-
]
129-
}
130-
])
123+
] : []
124+
])
131125
}
132126

133127
final_ecs_definitions_for_module = {

terraform/dev/terraform.tfvars

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,24 +31,28 @@ ecs_task_definitions_base = {
3131
environment = {}
3232
volumes = [
3333
{
34-
name = "dev-api-volume"
35-
host_path = "/home/ec2-user/logs/"
36-
readOnly = false
34+
name = "dev-api-volume"
35+
host_path = "/home/ec2-user/logs/"
36+
containerPath = "/logs"
37+
readOnly = false
3738
},
3839
{
39-
name = "docker_sock"
40-
host_path = "/var/run/docker.sock"
41-
readOnly = true
40+
name = "docker_sock"
41+
host_path = "/var/run/docker.sock"
42+
containerPath = "/var/run/docker.sock"
43+
readOnly = true
4244
},
4345
{
44-
name = "proc"
45-
host_path = "/proc/"
46-
readOnly = true
46+
name = "proc"
47+
host_path = "/proc/"
48+
containerPath = "/host/proc"
49+
readOnly = true
4750
},
4851
{
49-
name = "cgroup"
50-
host_path = "/sys/fs/cgroup/"
51-
readOnly = true
52+
name = "cgroup"
53+
host_path = "/sys/fs/cgroup/"
54+
containerPath = "/host/sys/fs/cgroup"
55+
readOnly = true
5256
}
5357
]
5458
}

terraform/dev/variables.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ variable "ecs_services" {
1111
variable "ecs_task_definitions_base" {
1212
type = map(object({
1313
cpu = number
14-
memory = number
14+
memory = optional(number)
15+
memoryReservation = optional(number)
1516
network_mode = string
1617
environment = map(string)
1718
requires_compatibilities = optional(list(string))

0 commit comments

Comments
 (0)