Skip to content

Commit ceee1cd

Browse files
authored
Merge pull request #223 from fdmsantos/create_execution_role_ec2_tasks_feature
Add ability to create Execution Role for Tasks deployed in EC2
2 parents 548bdc4 + 898d67a commit ceee1cd

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ No modules.
160160
| <a name="input_cloudwatch_alarm_name"></a> [cloudwatch\_alarm\_name](#input\_cloudwatch\_alarm\_name) | Generic name used for CPU and Memory Cloudwatch Alarms | `string` | `""` | no |
161161
| <a name="input_container_definitions"></a> [container\_definitions](#input\_container\_definitions) | Container definitions provided as valid JSON document. Default uses golang:alpine running a simple hello world. | `string` | `""` | no |
162162
| <a name="input_container_image"></a> [container\_image](#input\_container\_image) | The image of the container. | `string` | `"golang:alpine"` | no |
163+
| <a name="input_ec2_create_task_execution_role"></a> [ec2\_create\_task\_execution\_role](#input\_ec2\_create\_task\_execution\_role) | Set to true to create ecs task execution role to ECS EC2 Tasks. | `bool` | `false` | no |
163164
| <a name="input_ecr_repo_arns"></a> [ecr\_repo\_arns](#input\_ecr\_repo\_arns) | The ARNs of the ECR repos. By default, allows all repositories. | `list(string)` | <pre>[<br> "*"<br>]</pre> | no |
164165
| <a name="input_ecs_cluster"></a> [ecs\_cluster](#input\_ecs\_cluster) | ECS cluster object for this task. | <pre>object({<br> arn = string<br> name = string<br> })</pre> | n/a | yes |
165166
| <a name="input_ecs_instance_role"></a> [ecs\_instance\_role](#input\_ecs\_instance\_role) | The name of the ECS instance role. | `string` | `""` | no |

main.tf

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -354,14 +354,20 @@ resource "aws_iam_role" "task_role" {
354354
}
355355

356356
resource "aws_iam_role" "task_execution_role" {
357-
count = var.ecs_use_fargate ? 1 : 0
357+
# if ecs_use_fargate is True, create aws_iam_role resource
358+
# if ecs_use_fargate is False, check whether value of ec2_create_task_execution_role is True/False.
359+
# if True, set to 1 creating the resource, if False, set to 0, not creating the resource
360+
count = var.ecs_use_fargate ? 1 : var.ec2_create_task_execution_role ? 1 : 0
358361

359362
name = "ecs-task-execution-role-${var.name}-${var.environment}"
360363
assume_role_policy = data.aws_iam_policy_document.ecs_assume_role_policy.json
361364
}
362365

363366
resource "aws_iam_role_policy" "task_execution_role_policy" {
364-
count = var.ecs_use_fargate ? 1 : 0
367+
# if ecs_use_fargate is True, create aws_iam_role_policy resource
368+
# if ecs_use_fargate is False, check whether value of ec2_create_task_execution_role is True/False.
369+
# if True, set to 1 creating the resource, if False, set to 0, not creating the resource
370+
count = var.ecs_use_fargate ? 1 : var.ec2_create_task_execution_role ? 1 : 0
365371

366372
name = "${aws_iam_role.task_execution_role[0].name}-policy"
367373
role = aws_iam_role.task_execution_role[0].name

variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,12 @@ variable "ecs_subnet_ids" {
9292
type = list(string)
9393
}
9494

95+
variable "ec2_create_task_execution_role" {
96+
description = "Set to true to create ecs task execution role to ECS EC2 Tasks."
97+
type = bool
98+
default = false
99+
}
100+
95101
variable "assign_public_ip" {
96102
description = "Whether this instance should be accessible from the public internet. Default is false."
97103
default = false

0 commit comments

Comments
 (0)