diff --git a/modules/ecs/container_definitions.json b/modules/ecs/container_definitions.json index 6ba1511..79efb2e 100644 --- a/modules/ecs/container_definitions.json +++ b/modules/ecs/container_definitions.json @@ -1,17 +1,25 @@ -[ - { - "name": "app", - "image": "alvin254/fitnesshero", - "cpu": 256, - "memory": 512, - "essential": true, - "portMappings": [ - { - "containerPort": 3000, - "hostPort": 3000, - "protocol": "tcp" - } - ] - } -] +{ + "family": "app", + "networkMode": "awsvpc", + "requiresCompatibilities": ["FARGATE"], + "executionRoleArn": "arn:aws:iam::aws:policy/service-role/AmazonECSTaskExecutionRolePolicy", + "cpu": "256", + "memory": "512", + "containerDefinitions": [ + { + "name": "app", + "image": "alvin254/fitnesshero", + "cpu": 256, + "memory": 512, + "essential": true, + "portMappings": [ + { + "containerPort": 3000, + "hostPort": 3000, + "protocol": "tcp" + } + ] + } + ] +} diff --git a/modules/ecs/main.tf b/modules/ecs/main.tf index 2f1e95b..8e7d9d1 100644 --- a/modules/ecs/main.tf +++ b/modules/ecs/main.tf @@ -36,7 +36,24 @@ resource "aws_iam_role_policy_attachment" "ecs_cloudwatch_logs_policy" { role = aws_iam_role.ecs_exec_role.name policy_arn = "arn:aws:iam::aws:policy/CloudWatchLogsFullAccess" } - +locals { + container_definitions = jsonencode([ + { + name = "app" + image = "alvin254/fitnesshero" + cpu = 256 + memory = 512 + essential = true + portMappings = [ + { + containerPort = 3000 + hostPort = 3000 + protocol = "tcp" + } + ] + } + ]) +} resource "aws_ecs_task_definition" "cloudific" { family = "app" network_mode = "awsvpc" @@ -44,7 +61,7 @@ resource "aws_ecs_task_definition" "cloudific" { execution_role_arn = aws_iam_role.ecs_exec_role.arn cpu = "256" // CPU value defined at task level memory = "512" // Memory value defined at task level - container_definitions = file("${path.module}/container_definitions.json") + container_definitions = local.container_definitions } resource "aws_ecs_service" "app_service" { @@ -60,28 +77,3 @@ resource "aws_ecs_service" "app_service" { assign_public_ip = true } } - -// { -// "family": "app", -// "networkMode": "awsvpc", -// "requiresCompatibilities": ["FARGATE"], -// "executionRoleArn": "arn:aws:iam::your_account_id:role/ecsExecRole", -// "cpu": "256", -// "memory": "512", -// "containerDefinitions": [ -// { -// "name": "app", -// "image": "alvin254/fitnesshero", -// "cpu": 256, -// "memory": 512, -// "essential": true, -// "portMappings": [ -// { -// "containerPort": 3000, -// "hostPort": 3000, -// "protocol": "tcp" -// } -// ] -// } -// ] -// }