Skip to content

Commit

Permalink
[update]
Browse files Browse the repository at this point in the history
  • Loading branch information
alvo254 committed Jun 10, 2024
1 parent dce891f commit f5d1b4a
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 43 deletions.
40 changes: 24 additions & 16 deletions modules/ecs/container_definitions.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
]
}
46 changes: 19 additions & 27 deletions modules/ecs/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,32 @@ 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"
requires_compatibilities = ["FARGATE"]
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" {
Expand All @@ -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"
// }
// ]
// }
// ]
// }

0 comments on commit f5d1b4a

Please sign in to comment.