Skip to content

Commit

Permalink
- Added more roles to ecs web task definition
Browse files Browse the repository at this point in the history
- Renamed web task definition
  • Loading branch information
Ronaldo Macapobre committed Jul 29, 2024
1 parent c17801f commit 379cfe7
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 20 deletions.
16 changes: 8 additions & 8 deletions infrastructure/cloud/environments/sandbox/webapp.tf
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ module "networking" {
}

module "container" {
source = "../../modules/container"
environment = var.environment
app_name = var.app_name
ecs_task_execution_iam_role_arn = module.security.ecs_task_execution_iam_role_arn
subnet_id = module.networking.subnet_id
ecs_sg_id = module.networking.ecs_sg_id
lb_listener = module.networking.lb_listener
lb_tg_arn = module.networking.lb_tg_arn
source = "../../modules/container"
environment = var.environment
app_name = var.app_name
ecs_web_task_execution_iam_role_arn = module.security.ecs_web_task_execution_iam_role_arn
subnet_id = module.networking.subnet_id
ecs_sg_id = module.networking.ecs_sg_id
lb_listener = module.networking.lb_listener
lb_tg_arn = module.networking.lb_tg_arn
}
2 changes: 1 addition & 1 deletion infrastructure/cloud/modules/container/ecr.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
resource "aws_ecr_repository" "ecr_repository" {
name = "${var.app_name}-repo-${var.environment}"
name = "${var.app_name}-ecr-repo-${var.environment}"
image_tag_mutability = "MUTABLE"
force_delete = true

Expand Down
4 changes: 2 additions & 2 deletions infrastructure/cloud/modules/container/ecs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ resource "aws_ecs_task_definition" "ecs_web_task_definition" {
}
])

execution_role_arn = var.ecs_task_execution_iam_role_arn
task_role_arn = var.ecs_task_execution_iam_role_arn
execution_role_arn = var.ecs_web_task_execution_iam_role_arn
task_role_arn = var.ecs_web_task_execution_iam_role_arn
}

resource "aws_ecs_service" "ecs_web_service" {
Expand Down
4 changes: 2 additions & 2 deletions infrastructure/cloud/modules/container/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ variable "app_name" {
type = string
}

variable "ecs_task_execution_iam_role_arn" {
description = "ECS Task Execution IAM Role ARN"
variable "ecs_web_task_execution_iam_role_arn" {
description = "ECS Task Execution IAM Role ARN for Web app"
}

variable "subnet_id" {
Expand Down
16 changes: 11 additions & 5 deletions infrastructure/cloud/modules/security/iam.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
resource "aws_iam_role" "ecs_task_execution_role" {
name = "${var.app_name}-ecs-task-execution-role-${var.environment}"
resource "aws_iam_role" "ecs_web_task_execution_role" {
name = "${var.app_name}-ecs-web-task-execution-role-${var.environment}"

assume_role_policy = jsonencode({
Version = "2012-10-17"
Expand All @@ -9,13 +9,19 @@ resource "aws_iam_role" "ecs_task_execution_role" {
Principal = {
Service = "ecs-tasks.amazonaws.com"
}
Action = "sts:AssumeRole"
Action = [
"sts:AssumeRole",
"ecr:BatchGetImage",
"ecr:GetDownloadUrlForLayer",
"ecr:GetAuthorizationToken"
]
}
]
})
}

resource "aws_iam_role_policy_attachment" "ecs_task_execution_role_policy" {
role = aws_iam_role.ecs_task_execution_role.name
resource "aws_iam_role_policy_attachment" "ecs_web_task_execution_role_policy" {
role = aws_iam_role.ecs_web_task_execution_role.name
policy_arn = "arn:aws:iam::aws:policy/service-role/AmazonECSTaskExecutionRolePolicy"
}

4 changes: 2 additions & 2 deletions infrastructure/cloud/modules/security/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ output "kms_key_alias" {
value = aws_kms_alias.kms_alias.name
}

output "ecs_task_execution_iam_role_arn" {
value = aws_iam_role.ecs_task_execution_role.arn
output "ecs_web_task_execution_iam_role_arn" {
value = aws_iam_role.ecs_web_task_execution_role.arn
}

0 comments on commit 379cfe7

Please sign in to comment.