Skip to content

Commit a413ddf

Browse files
author
rohit-ng
committed
refactor: extract iam module to main
1 parent 59fe88f commit a413ddf

File tree

3 files changed

+21
-16
lines changed

3 files changed

+21
-16
lines changed

iam.tf

Lines changed: 0 additions & 15 deletions
This file was deleted.

locals.tf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,20 @@ locals {
1212
port = 5432
1313
}
1414

15+
16+
1517
ecs = {
1618
user_data = <<EOF
1719
#!/bin/bash
1820
echo ECS_CLUSTER=${var.cluster_name} >> /etc/ecs/ecs.config;
1921
EOF
2022
ecs_node_sg_name = "kong"
23+
iam = {
24+
name_prefix = "kong-ecs-exec"
25+
ecs_exec_policy_arn = ["arn:aws:iam::aws:policy/service-role/AmazonECSTaskExecutionRolePolicy"]
26+
principal_type = "Service"
27+
principal_identifiers = ["ecs-tasks.amazonaws.com"]
28+
}
2129
}
2230

2331
kong = {

main.tf

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,18 @@ module "ecs_task_security_group" {
177177
tags = local.default_tags
178178
}
179179

180+
################################################################################
181+
# ECS Execution IAM Role
182+
################################################################################
183+
184+
module "ecs_exec_role" {
185+
source = "./modules/iam"
186+
name_prefix = local.ecs.iam.name_prefix
187+
principal_type = local.ecs.iam.principal_type
188+
principal_identifiers = local.ecs.iam.principal_identifiers
189+
policy_arns = local.ecs.iam.ecs_exec_policy_arn
190+
}
191+
180192
################################################################################
181193
# ECS Kong
182194
################################################################################
@@ -213,7 +225,7 @@ module "ecs_kong" {
213225
network_mode = local.kong.network_mode
214226
cpu = var.cpu_for_kong_task
215227
memory = var.memory_for_kong_task
216-
task_role_arn = module.ecs_task_role.role_arn
228+
task_role_arn = module.ecs_exec_role.role_arn
217229
execution_role_arn = module.ecs_exec_role.role_arn
218230

219231
container_definitions = [

0 commit comments

Comments
 (0)