Skip to content

Commit 49f1dff

Browse files
feat: Add support for setting the condition field in Event Bus permissions (terraform-aws-modules#84)
Co-authored-by: Anton Babenko <[email protected]>
1 parent df8797e commit 49f1dff

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

examples/with-permissions/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ Note that this example may create resources which cost money. Run `terraform des
4242
|------|------|
4343
| [aws_cloudwatch_event_bus.external](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudwatch_event_bus) | resource |
4444
| [random_pet.this](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/pet) | resource |
45+
| [aws_organizations_organization.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/organizations_organization) | data source |
4546

4647
## Inputs
4748

examples/with-permissions/main.tf

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ provider "aws" {
99
skip_requesting_account_id = true
1010
}
1111

12+
data "aws_organizations_organization" "this" {}
13+
1214
module "eventbridge" {
1315
source = "../../"
1416

@@ -23,8 +25,9 @@ module "eventbridge" {
2325
action = "events:PutEvents"
2426
}
2527

26-
"* PublicAccessToExternalBus" = {
28+
"* OrgAccessToExternalBus" = {
2729
event_bus_name = aws_cloudwatch_event_bus.external.name
30+
condition_org = data.aws_organizations_organization.this.id
2831
}
2932
}
3033

main.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,16 @@ resource "aws_cloudwatch_event_permission" "this" {
248248

249249
action = lookup(each.value, "action", null)
250250
event_bus_name = try(each.value["event_bus_name"], aws_cloudwatch_event_bus.this[0].name, var.bus_name, null)
251+
252+
dynamic "condition" {
253+
for_each = try([each.value.condition_org], [])
254+
255+
content {
256+
key = "aws:PrincipalOrgID"
257+
type = "StringEquals"
258+
value = condition.value
259+
}
260+
}
251261
}
252262

253263
resource "aws_cloudwatch_event_connection" "this" {

0 commit comments

Comments
 (0)