Skip to content

Commit

Permalink
upgrade to module
Browse files Browse the repository at this point in the history
  • Loading branch information
johnricords committed Jul 1, 2024
1 parent a4c42ff commit fc728e8
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 114 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 1.0.0
current_version = 2.0.0
commit = True
message = Bumps version to {new_version}
tag = False
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/).

### [2.0.0](https://github.com/plus3it/terraform-aws-tardigrade-cloudwatch-events/releases/tag/2.0.0)

**Released**: 2024.07.01

**Summary**:

* Tweaked optionality to match terraform registry
* revised variable to `event_target` to create singular object

### [1.0.0](https://github.com/plus3it/terraform-aws-tardigrade-cloudwatch-events/releases/tag/1.0.0)

**Released**:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ No requirements.

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_cloudwatch_rule"></a> [cloudwatch\_rule](#input\_cloudwatch\_rule) | Object of input configs for cloudwatch event rules | <pre>list(object({<br> event_rule = object({<br> name = string<br> description = string<br> event_pattern = string<br> })<br> event_target = object({<br> event_name = string<br> event_target_id = optional(string)<br> event_target_arn = string<br> role_arn = string<br> input_transformer = object({<br> input_paths = map(string)<br> })<br> input_template = string<br> })<br> }))</pre> | n/a | yes |
| <a name="input_event_rule"></a> [event\_rule](#input\_event\_rule) | Object of input configs for the CloudWatch Event Rule | <pre>object({<br> name = string<br> description = optional(string)<br> event_pattern = optional(string)<br><br> event_targets = optional(list(object({<br> name = string<br> arn = string<br><br> event_bus_name = optional(string)<br> role_arn = optional(string)<br> target_id = optional(string)<br><br> dead_letter_config = optional(object({<br> arn = string<br> }))<br><br> input_transformer = optional(object({<br> input_paths = optional(map(string))<br> input_template = string<br> }))<br> })), [])<br> })</pre> | n/a | yes |

## Outputs

Expand Down
30 changes: 15 additions & 15 deletions main.tf
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
resource "aws_cloudwatch_event_rule" "this" {
for_each = { for item in var.cloudwatch_rule : item.event_rule.name => item }

name = each.value.event_rule.name
description = each.value.event_rule.description
event_pattern = each.value.event_rule.event_pattern
name = var.event_rule.name
description = var.event_rule.description
event_pattern = var.event_rule.event_pattern
}


resource "aws_cloudwatch_event_target" "this" {
for_each = { for item in var.cloudwatch_rule : item.event_target.event_name => item }

arn = each.value.event_target.event_target_arn
rule = each.value.event_target.event_name
target_id = each.value.event_target.event_target_id
role_arn = each.value.event_target.role_arn
for_each = { for target in var.event_rule.event_targets : target.name => target }

input_transformer {
input_paths = each.value.event_target.input_transformer.input_paths
arn = each.value.arn
rule = aws_cloudwatch_event_rule.this.id
target_id = each.value.target_id
role_arn = each.value.role_arn

input_template = each.value.event_target.input_template
dynamic "input_transformer" {
for_each = each.value.input_transformer != null ? [each.value.input_transformer] : []
content {
input_paths = input_transformer.value.input_paths
input_template = input_transformer.value.input_template
}
}
depends_on = [aws_cloudwatch_event_rule.this]
}
}
55 changes: 55 additions & 0 deletions tests/create_all_any/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
resource "random_string" "this" {
length = 8
upper = false
special = false
numeric = false
}

module "cloudwatch" {
source = "../../"

event_rule = {

name = "event1"
description = random_string.this.result
event_pattern = jsonencode({
source = ["aws.codecommit"],
detail-type = ["${random_string.this.result}"],
account = [data.aws_caller_identity.current.account_id],
region = [data.aws_region.current.name],
resources = ["arn:${data.aws_partition.current.partition}:codecommit:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:${random_string.this.result}"],
detail = {
destinationReference = ["${random_string.this.result}"],
isMerged = ["${random_string.this.result}"],
pullRequestStatus = ["${random_string.this.result}"],
}
})
event_targets = [
{
name = "target1"
target_id = "Id0d05d630-096c-4f51-af8c-f5c07daab1ee"
arn = "arn:${data.aws_partition.current.partition}:codebuild:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:project/${random_string.this.result}"
role_arn = "arn:${data.aws_partition.current.partition}:iam::${data.aws_caller_identity.current.account_id}:role/service-role/Amazon_EventBridge_Invoke_CodeBuild_1840626416"
input_transformer = {
input_paths = {
destination-version = "$.detail.destinationReference"
}
input_template = "{\"destinationVersion\": <destination-version>}"
}
},
{
name = "target2"
target_id = "Id0d05d630-096c-4f51-af8c-f5c07daab1ee"
arn = "arn:${data.aws_partition.current.partition}:codebuild:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:project/${random_string.this.result}"
role_arn = "arn:${data.aws_partition.current.partition}:iam::${data.aws_caller_identity.current.account_id}:role/service-role/Amazon_EventBridge_Invoke_CodeBuild_1840626416"
dead_letter_config = {
arn = "arn:${data.aws_partition.current.partition}:sqs:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:${random_string.this.result}"
}
}
]
}
}

data "aws_caller_identity" "current" {}
data "aws_region" "current" {}
data "aws_partition" "current" {}
77 changes: 0 additions & 77 deletions tests/main.tf

This file was deleted.

46 changes: 26 additions & 20 deletions variables.tf
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
variable "cloudwatch_rule" {
description = "Object of input configs for cloudwatch event rules"
type = list(object({
event_rule = object({
name = string
description = string
event_pattern = string
})
event_target = object({
event_name = string
event_target_id = optional(string)
event_target_arn = string
role_arn = string
input_transformer = object({
input_paths = map(string)
})
input_template = string
})
}))
}
variable "event_rule" {
description = "Object of input configs for the CloudWatch Event Rule"
type = object({
name = string
description = optional(string)
event_pattern = optional(string)

event_targets = optional(list(object({
name = string
arn = string

event_bus_name = optional(string)
role_arn = optional(string)
target_id = optional(string)

dead_letter_config = optional(object({
arn = string
}))

input_transformer = optional(object({
input_paths = optional(map(string))
input_template = string
}))
})), [])
})
}

0 comments on commit fc728e8

Please sign in to comment.