Skip to content

Commit 1dcad03

Browse files
authored
feat: Allow specifying ecs policy passrole resources (#131)
1 parent 27ec125 commit 1dcad03

File tree

5 files changed

+19
-2
lines changed

5 files changed

+19
-2
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,7 @@ No modules.
502502
| <a name="input_create_schedules"></a> [create\_schedules](#input\_create\_schedules) | Controls whether EventBridge Schedule resources should be created | `bool` | `true` | no |
503503
| <a name="input_create_schemas_discoverer"></a> [create\_schemas\_discoverer](#input\_create\_schemas\_discoverer) | Controls whether default schemas discoverer should be created | `bool` | `false` | no |
504504
| <a name="input_create_targets"></a> [create\_targets](#input\_create\_targets) | Controls whether EventBridge Target resources should be created | `bool` | `true` | no |
505+
| <a name="input_ecs_pass_role_resources"></a> [ecs\_pass\_role\_resources](#input\_ecs\_pass\_role\_resources) | List of approved roles to be passed | `list(string)` | `[]` | no |
505506
| <a name="input_ecs_target_arns"></a> [ecs\_target\_arns](#input\_ecs\_target\_arns) | The Amazon Resource Name (ARN) of the AWS ECS Tasks you want to use as EventBridge targets | `list(string)` | `[]` | no |
506507
| <a name="input_event_source_name"></a> [event\_source\_name](#input\_event\_source\_name) | The partner event source that the new event bus will be matched with. Must match name. | `string` | `null` | no |
507508
| <a name="input_kinesis_firehose_target_arns"></a> [kinesis\_firehose\_target\_arns](#input\_kinesis\_firehose\_target\_arns) | The Amazon Resource Name (ARN) of the Kinesis Firehose Delivery Streams you want to use as EventBridge targets | `list(string)` | `[]` | no |

examples/with-ecs-scheduling/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ Note that this example may create resources which cost money. Run `terraform des
4242
| Name | Type |
4343
|------|------|
4444
| [random_pet.this](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/pet) | resource |
45+
| [aws_caller_identity.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/caller_identity) | data source |
46+
| [aws_region.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/region) | data source |
4547
| [aws_security_group.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/security_group) | data source |
4648
| [aws_subnets.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/subnets) | data source |
4749
| [aws_vpc.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/vpc) | data source |

examples/with-ecs-scheduling/main.tf

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ data "aws_subnets" "default" {
2626
}
2727
}
2828

29+
data "aws_caller_identity" "current" {}
30+
data "aws_region" "current" {}
31+
2932
####################
3033
# Actual Eventbridge
3134
####################
@@ -38,7 +41,12 @@ module "eventbridge" {
3841
create_role = true
3942
role_name = "ecs-eventbridge-${random_pet.this.id}"
4043
attach_ecs_policy = true
41-
ecs_target_arns = [module.ecs_cluster.services["hello-world"].task_definition_arn]
44+
ecs_target_arns = [
45+
module.ecs_cluster.services["hello-world"].task_definition_arn,
46+
"arn:aws:ecs:${data.aws_region.current.id}:${data.aws_caller_identity.current.account_id}:task/${random_pet.this.id}/*"
47+
]
48+
49+
ecs_pass_role_resources = [module.ecs_cluster.services["hello-world"].task_exec_iam_role_arn]
4250

4351
# Fire every five minutes
4452
rules = {

iam.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ data "aws_iam_policy_document" "ecs" {
245245
sid = "PassRole"
246246
effect = "Allow"
247247
actions = ["iam:PassRole"]
248-
resources = ["*"]
248+
resources = coalescelist(var.ecs_pass_role_resources, ["*"])
249249
}
250250
}
251251

variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,12 @@ variable "role_tags" {
244244
default = {}
245245
}
246246

247+
variable "ecs_pass_role_resources" {
248+
description = "List of approved roles to be passed"
249+
type = list(string)
250+
default = []
251+
}
252+
247253
###########
248254
# Policies
249255
###########

0 commit comments

Comments
 (0)