diff --git a/README.md b/README.md index 95cc8b5..73faf7a 100644 --- a/README.md +++ b/README.md @@ -65,6 +65,11 @@ module "appsync" { endpoint = "https://opensearch-my-domain.eu-west-1.es.amazonaws.com" region = "eu-west-1" } + + eventbridge1 = { + type = "AMAZON_EVENTBRIDGE" + event_bus_arn = "aws:arn:events:us-west-1:135367859850:event-bus/eventbridge1" + } } resolvers = { @@ -178,6 +183,7 @@ No modules. | [domain\_name\_description](#input\_domain\_name\_description) | A description of the Domain Name. | `string` | `null` | no | | [dynamodb\_allowed\_actions](#input\_dynamodb\_allowed\_actions) | List of allowed IAM actions for datasources type AMAZON\_DYNAMODB | `list(string)` |
[| no | | [elasticsearch\_allowed\_actions](#input\_elasticsearch\_allowed\_actions) | List of allowed IAM actions for datasources type AMAZON\_ELASTICSEARCH | `list(string)` |
"dynamodb:GetItem",
"dynamodb:PutItem",
"dynamodb:DeleteItem",
"dynamodb:UpdateItem",
"dynamodb:Query",
"dynamodb:Scan",
"dynamodb:BatchGetItem",
"dynamodb:BatchWriteItem"
]
[| no | +| [eventbridge\_allowed\_actions](#input\_eventbridge\_allowed\_actions) | List of allowed IAM actions for datasources type AMAZON\_EVENTBRIDGE | `list(string)` |
"es:ESHttpDelete",
"es:ESHttpHead",
"es:ESHttpGet",
"es:ESHttpPost",
"es:ESHttpPut"
]
[| no | | [functions](#input\_functions) | Map of functions to create | `any` | `{}` | no | | [graphql\_api\_tags](#input\_graphql\_api\_tags) | Map of tags to add to GraphQL API | `map(string)` | `{}` | no | | [iam\_permissions\_boundary](#input\_iam\_permissions\_boundary) | ARN for iam permissions boundary | `string` | `null` | no | diff --git a/examples/complete/main.tf b/examples/complete/main.tf index 48c703e..06c486b 100644 --- a/examples/complete/main.tf +++ b/examples/complete/main.tf @@ -222,6 +222,12 @@ module "appsync" { endpoint = "https://search-my-domain-2.eu-west-1.es.amazonaws.com" region = "eu-west-1" } + + eventbridge1 = { + type = "AMAZON_EVENTBRIDGE" + + event_bus_arn = "aws:arn:events:us-west-1:135367859850:event-bus/eventbridge1" + } } resolvers = { diff --git a/iam.tf b/iam.tf index 4758570..57b1dd4 100644 --- a/iam.tf +++ b/iam.tf @@ -1,7 +1,7 @@ data "aws_partition" "this" {} locals { - service_roles_with_policies = var.create_graphql_api ? { for k, v in var.datasources : k => v if contains(["AWS_LAMBDA", "AMAZON_DYNAMODB", "AMAZON_ELASTICSEARCH", "AMAZON_OPENSEARCH_SERVICE"], v.type) && tobool(lookup(v, "create_service_role", true)) } : {} + service_roles_with_policies = var.create_graphql_api ? { for k, v in var.datasources : k => v if contains(["AWS_LAMBDA", "AMAZON_DYNAMODB", "AMAZON_ELASTICSEARCH", "AMAZON_OPENSEARCH_SERVICE", "AMAZON_EVENTBRIDGE"], v.type) && tobool(lookup(v, "create_service_role", true)) } : {} service_roles_with_policies_lambda = { for k, v in local.service_roles_with_policies : k => merge(v, { @@ -51,11 +51,24 @@ locals { } ) if v.type == "AMAZON_OPENSEARCH_SERVICE" } + service_roles_with_policies_eventbridge = { for k, v in local.service_roles_with_policies : k => merge(v, + { + policy_statements = { + eventbridge = { + effect = "Allow" + actions = lookup(v, "policy_actions", null) == null ? var.eventbridge_allowed_actions : v.policy_actions + resources = [v.event_bus_arn] + } + } + } + ) if v.type == "AMAZON_EVENTBRIDGE" } + service_roles_with_specific_policies = merge( local.service_roles_with_policies_lambda, local.service_roles_with_policies_dynamodb, local.service_roles_with_policies_elasticsearch, local.service_roles_with_policies_opensearchservice, + local.service_roles_with_policies_eventbridge, ) } diff --git a/main.tf b/main.tf index 9142596..b837012 100644 --- a/main.tf +++ b/main.tf @@ -144,7 +144,7 @@ resource "aws_appsync_datasource" "this" { name = each.key type = each.value.type description = lookup(each.value, "description", null) - service_role_arn = lookup(each.value, "service_role_arn", tobool(lookup(each.value, "create_service_role", contains(["AWS_LAMBDA", "AMAZON_DYNAMODB", "AMAZON_ELASTICSEARCH", "AMAZON_OPENSEARCH_SERVICE"], each.value.type))) ? aws_iam_role.service_role[each.key].arn : null) + service_role_arn = lookup(each.value, "service_role_arn", tobool(lookup(each.value, "create_service_role", contains(["AWS_LAMBDA", "AMAZON_DYNAMODB", "AMAZON_ELASTICSEARCH", "AMAZON_OPENSEARCH_SERVICE", "AMAZON_EVENTBRIDGE"], each.value.type))) ? aws_iam_role.service_role[each.key].arn : null) dynamic "http_config" { for_each = each.value.type == "HTTP" ? [true] : [] @@ -189,6 +189,14 @@ resource "aws_appsync_datasource" "this" { region = lookup(each.value, "region", null) } } + + dynamic "event_bridge_config" { + for_each = each.value.type == "AMAZON_EVENTBRIDGE" ? [true] : [] + + content { + event_bus_arn = each.value.event_bus_arn + } + } } # Resolvers diff --git a/variables.tf b/variables.tf index 9ee386c..bc65c94 100644 --- a/variables.tf +++ b/variables.tf @@ -236,6 +236,12 @@ variable "opensearchservice_allowed_actions" { default = ["es:ESHttpDelete", "es:ESHttpHead", "es:ESHttpGet", "es:ESHttpPost", "es:ESHttpPut"] } +variable "eventbridge_allowed_actions" { + description = "List of allowed IAM actions for datasources type AMAZON_EVENTBRIDGE" + type = list(string) + default = ["events:PutEvents"] +} + variable "iam_permissions_boundary" { description = "ARN for iam permissions boundary" type = string diff --git a/wrappers/main.tf b/wrappers/main.tf index 219c423..2208e41 100644 --- a/wrappers/main.tf +++ b/wrappers/main.tf @@ -37,6 +37,7 @@ module "wrapper" { dynamodb_allowed_actions = try(each.value.dynamodb_allowed_actions, var.defaults.dynamodb_allowed_actions, ["dynamodb:GetItem", "dynamodb:PutItem", "dynamodb:DeleteItem", "dynamodb:UpdateItem", "dynamodb:Query", "dynamodb:Scan", "dynamodb:BatchGetItem", "dynamodb:BatchWriteItem"]) elasticsearch_allowed_actions = try(each.value.elasticsearch_allowed_actions, var.defaults.elasticsearch_allowed_actions, ["es:ESHttpDelete", "es:ESHttpHead", "es:ESHttpGet", "es:ESHttpPost", "es:ESHttpPut"]) opensearchservice_allowed_actions = try(each.value.opensearchservice_allowed_actions, var.defaults.opensearchservice_allowed_actions, ["es:ESHttpDelete", "es:ESHttpHead", "es:ESHttpGet", "es:ESHttpPost", "es:ESHttpPut"]) + eventbridge_allowed_actions = try(each.value.eventbridge_allowed_actions, var.defaults.eventbridge_allowed_actions, ["events:PutEvents"]) iam_permissions_boundary = try(each.value.iam_permissions_boundary, var.defaults.iam_permissions_boundary, null) direct_lambda_request_template = try(each.value.direct_lambda_request_template, var.defaults.direct_lambda_request_template, <<-EOF {
"events:PutEvents"
]