Skip to content

Commit 7238bfd

Browse files
authored
Add support for ECS task role (#7)
* add task definition iam role support * removed syntax error * fix null value error * fixed conditional for ecs_task_role_arn * Updated README and example
1 parent 4187e39 commit 7238bfd

File tree

4 files changed

+10
-3
lines changed

4 files changed

+10
-3
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ No modules.
7777
|------|-------------|------|---------|:--------:|
7878
| <a name="input_ecs_cluster_arn"></a> [ecs\_cluster\_arn](#input\_ecs\_cluster\_arn) | The ECS Cluster where the scheduled task will run | `any` | n/a | yes |
7979
| <a name="input_ecs_execution_task_role_arn"></a> [ecs\_execution\_task\_role\_arn](#input\_ecs\_execution\_task\_role\_arn) | (Required) The task definition execution role. The Amazon Resource Name (ARN) of the IAM role to be used for this target when the rule is triggered. | `any` | n/a | yes |
80+
| <a name="input_ecs_task_role_arn"></a> [ecs\_task\_role\_arn](#input\_ecs\_task\_role\_arn) | (Optional) The task definition role. The Amazon Resource Name (ARN) of the IAM role to be used for this target when the rule is triggered. | `any` | `null` | no |
8081
| <a name="input_event_rule_description"></a> [event\_rule\_description](#input\_event\_rule\_description) | (Optional) The description of the rule. | `any` | `null` | no |
8182
| <a name="input_event_rule_event_bus_name"></a> [event\_rule\_event\_bus\_name](#input\_event\_rule\_event\_bus\_name) | (Optional) The event bus to associate with this rule. If you omit this, the default event bus is used. | `any` | `null` | no |
8283
| <a name="input_event_rule_event_pattern"></a> [event\_rule\_event\_pattern](#input\_event\_rule\_event\_pattern) | (Optional) The event pattern described a JSON object. At least one of schedule\_expression or event\_pattern is required. | `any` | `null` | no |

examples/test/main.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,6 @@ module "task" {
3030
ecs_cluster_arn = module.cluster.aws_ecs_cluster_cluster_arn
3131
event_target_ecs_target_subnets = module.base-network.public_subnets_ids
3232
event_target_ecs_target_task_definition_arn = module.td.aws_ecs_task_definition_td_arn
33-
ecs_execution_task_role_arn = "Put your role ARN here"
33+
ecs_execution_task_role_arn = "Put your execution role ARN here"
34+
ecs_task_role_arn = "Put your role ARN here"
3435
}

main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ data "aws_iam_policy_document" "scheduled_task_cw_event_role_cloudwatch_policy"
2020
}
2121
statement {
2222
actions = ["iam:PassRole"]
23-
resources = [var.ecs_execution_task_role_arn]
23+
resources = var.ecs_task_role_arn == null ? [var.ecs_execution_task_role_arn] : [var.ecs_execution_task_role_arn, var.ecs_task_role_arn]
2424
}
2525
}
2626

variables.tf

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ variable "ecs_execution_task_role_arn" {
6969
description = "(Required) The task definition execution role. The Amazon Resource Name (ARN) of the IAM role to be used for this target when the rule is triggered."
7070
}
7171

72+
variable "ecs_task_role_arn" {
73+
description = "(Optional) The task definition role. The Amazon Resource Name (ARN) of the IAM role to be used for this target when the rule is triggered."
74+
default = null
75+
}
76+
7277
variable "event_target_ecs_target_group" {
7378
description = "(Optional) Specifies an ECS task group for the task. The maximum length is 255 characters."
7479
default = null
@@ -104,4 +109,4 @@ variable "event_target_ecs_target_assign_public_ip" {
104109
description = "(Optional) Assign a public IP address to the ENI. Default false."
105110
type = bool
106111
default = false
107-
}
112+
}

0 commit comments

Comments
 (0)