Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 52 additions & 2 deletions examples/with-archive/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ provider "aws" {
skip_credentials_validation = true
}

data "aws_caller_identity" "current" {}
data "aws_region" "current" {}


module "eventbridge" {
source = "../../"

Expand Down Expand Up @@ -48,8 +52,9 @@ module "eventbridge" {
module "eventbridge_archive_only" {
source = "../../"

create_bus = false
create_archives = true
create_bus = false
create_archives = true
kms_key_identifier = module.kms.key_id

archives = {
"launch-archive-existing-bus" = {
Expand Down Expand Up @@ -79,3 +84,48 @@ resource "random_pet" "this" {
resource "aws_cloudwatch_event_bus" "existing_bus" {
name = "${random_pet.this.id}-existing-bus"
}

module "kms" {
source = "terraform-aws-modules/kms/aws"
version = "~> 2.0"
description = "KMS key for cross region automated backups replication"

# Aliases
aliases = ["test"]
aliases_use_name_prefix = true
key_statements = [
{
sid = "Allow eventbridge"
principals = [
{
type = "Service"
identifiers = ["events.amazonaws.com"]
}
]
actions = [
"kms:DescribeKey",
"kms:GenerateDataKey",
"kms:Decrypt"
]
resources = ["*"]
conditions = [
{
test = "StringEquals"
variable = "kms:EncryptionContext:aws:events:event-bus:arn"
values = [
"arn:aws:events:${data.aws_region.current.region}:${data.aws_caller_identity.current.account_id}:event-bus/example",
]
},
{
test = "StringEquals"
variable = "aws:SourceArn"
values = [
"arn:aws:events:${data.aws_region.current.id}:${data.aws_caller_identity.current.account_id}:event-bus/example",
]
}
]
}
]

key_owners = [data.aws_caller_identity.current.arn]
}
10 changes: 6 additions & 4 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,9 @@ resource "aws_cloudwatch_event_archive" "this" {

region = var.region

name = lookup(each.value, "name", each.key)
event_source_arn = try(each.value["event_source_arn"], aws_cloudwatch_event_bus.this[0].arn)
name = lookup(each.value, "name", each.key)
event_source_arn = try(each.value["event_source_arn"], aws_cloudwatch_event_bus.this[0].arn)
kms_key_identifier = var.kms_key_identifier

description = lookup(each.value, "description", null)
event_pattern = lookup(each.value, "event_pattern", null)
Expand Down Expand Up @@ -667,8 +668,9 @@ resource "aws_pipes_pipe" "this" {
source = each.value.source
target = each.value.target

description = lookup(each.value, "description", null)
desired_state = lookup(each.value, "desired_state", null)
kms_key_identifier = var.kms_key_identifier
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't it be using lookup and fetch from each like the rest of arguments? I think it should in all places.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the kms key is specified in the module variables, not per pipe. I think it depends a bit how you would want that to be implemented. The current approach would mean, that pipes, archives and eventbus use the same key specified on the module variables. If you wanted to use different keys, you can set up individual modules for archive, pipes and eventbus, though. That's what I do currently, as well.

Does that work for you? Or do I miss something?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

User may want to use different keys for different resources, so using lookup for each is a common pattern. Please update it, and example if necessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, please review.

description = lookup(each.value, "description", null)
desired_state = lookup(each.value, "desired_state", null)

dynamic "source_parameters" {
for_each = try([each.value.source_parameters], [])
Expand Down
2 changes: 1 addition & 1 deletion versions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 6.0"
version = ">= 6.2"
}
}
}