Skip to content

Commit 0f19df1

Browse files
authored
Merge pull request #8 from tomarv2/develop
Pulling refs/heads/develop into main
2 parents 1bb6b03 + 2d7ac77 commit 0f19df1

File tree

11 files changed

+65
-139
lines changed

11 files changed

+65
-139
lines changed

.github/workflows/pr-lint.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: PR lint
2+
3+
on:
4+
pull_request:
5+
types: ['opened', 'edited', 'reopened', 'synchronize']
6+
7+
jobs:
8+
pr-lint:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: seferov/pr-lint-action@master
12+
with:
13+
title-regex: '^((Pulling|Update from) refs\/heads\/|(\[tf (plan|apply|destroy|status)\]|\[non tf\])\s(feat|fix|build|chore|ci|docs|style|refactor|perf|test)(\!?): (.{3,250})[^\s*]$)'
14+
github-token: ${{ secrets.GITHUB_TOKEN }}
15+
auto-close-message: 'Closing this pull request since the title does not match %pattern% pattern. Please fix the title and re-open the pull request.'

.github/workflows/state-actions.yml

Lines changed: 0 additions & 32 deletions
This file was deleted.

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ repos:
1919
- '--args=--only=terraform_workspace_remote'
2020

2121
- repo: https://github.com/pre-commit/pre-commit-hooks
22-
rev: v4.1.0
22+
rev: v4.3.0
2323
hooks:
2424
- id: trailing-whitespace
2525
- id: end-of-file-fixer
@@ -31,7 +31,7 @@ repos:
3131
- id: requirements-txt-fixer
3232

3333
- repo: https://github.com/bridgecrewio/checkov.git
34-
rev: '2.0.914'
34+
rev: '2.1.226'
3535
hooks:
3636
- id: checkov
3737
verbose: true

README.md

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
### Versions
1919

2020
- Module tested for Terraform 1.0.1.
21-
- AWS provider version [3.74](https://registry.terraform.io/providers/hashicorp/aws/latest)
21+
- AWS provider version [4.35](https://registry.terraform.io/providers/hashicorp/aws/latest)
2222
- `main` branch: Provider versions not pinned to keep up with Terraform releases.
2323
- `tags` releases: Tags are pinned with versions (use <a href="https://github.com/tomarv2/terraform-aws-cloudwatch-events/tags" alt="GitHub tag">
2424
<img src="https://img.shields.io/github/v/tag/tomarv2/terraform-aws-cloudwatch-events" /></a>).
@@ -38,7 +38,7 @@ terraform destroy -var='teamid=tryme' -var='prjid=project1'
3838

3939
#### Option 2:
4040

41-
##### Recommended method (stores remote state in S3 using `prjid` and `teamid` to create directory structure):
41+
##### Recommended method (stores remote state in remote backend(S3, Azure storage, or Google bucket) using `prjid` and `teamid` to create directory structure):
4242

4343
- Create python 3.8+ virtual environment
4444
```
@@ -92,13 +92,13 @@ tf -c=aws destroy -var='teamid=foo' -var='prjid=bar'
9292
| Name | Version |
9393
|------|---------|
9494
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0.1 |
95-
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | ~> 3.74 |
95+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | ~> 4.35 |
9696

9797
## Providers
9898

9999
| Name | Version |
100100
|------|---------|
101-
| <a name="provider_aws"></a> [aws](#provider\_aws) | ~> 3.74 |
101+
| <a name="provider_aws"></a> [aws](#provider\_aws) | ~> 4.35 |
102102

103103
## Modules
104104

@@ -115,24 +115,15 @@ No modules.
115115

116116
| Name | Description | Type | Default | Required |
117117
|------|-------------|------|---------|:--------:|
118-
| <a name="input_branch"></a> [branch](#input\_branch) | branch to use for cicd | `string` | `"main"` | no |
119-
| <a name="input_custom_input"></a> [custom\_input](#input\_custom\_input) | custom input to be included in generated events | `map(any)` | `null` | no |
120-
| <a name="input_deploy_event_rule"></a> [deploy\_event\_rule](#input\_deploy\_event\_rule) | Feature flag, true or false | `bool` | `true` | no |
121-
| <a name="input_deploy_event_target"></a> [deploy\_event\_target](#input\_deploy\_event\_target) | Feature flag, true or false | `bool` | `true` | no |
122-
| <a name="input_description"></a> [description](#input\_description) | description for the cloudwatch event | `string` | `null` | no |
123-
| <a name="input_name"></a> [name](#input\_name) | Cloudwatch event rule name | `string` | `null` | no |
118+
| <a name="input_cloudwatch_event_config"></a> [cloudwatch\_event\_config](#input\_cloudwatch\_event\_config) | Cloudwatch event configuration | `map(any)` | `{}` | no |
119+
| <a name="input_extra_tags"></a> [extra\_tags](#input\_extra\_tags) | Additional tags to associate | `map(string)` | `{}` | no |
124120
| <a name="input_prjid"></a> [prjid](#input\_prjid) | Name of the project/stack e.g: mystack, nifieks, demoaci. Should not be changed after running 'tf apply' | `string` | n/a | yes |
125-
| <a name="input_schedule"></a> [schedule](#input\_schedule) | schedule for the cloudwatch event | `string` | `"rate(1 day)"` | no |
126-
| <a name="input_service_role"></a> [service\_role](#input\_service\_role) | service role to be used by cicd | `string` | `null` | no |
127-
| <a name="input_suffix"></a> [suffix](#input\_suffix) | suffix to be added to cloudwatch rule name | `string` | `"rule"` | no |
128-
| <a name="input_target_arn"></a> [target\_arn](#input\_target\_arn) | target arn | `string` | n/a | yes |
129121
| <a name="input_teamid"></a> [teamid](#input\_teamid) | Name of the team/group e.g. devops, dataengineering. Should not be changed after running 'tf apply' | `string` | n/a | yes |
130-
| <a name="input_timeout"></a> [timeout](#input\_timeout) | timeout for cloudwatch event | `number` | `60` | no |
131122

132123
## Outputs
133124

134125
| Name | Description |
135126
|------|-------------|
136-
| <a name="output_cloudwatch_event_rule_arn"></a> [cloudwatch\_event\_rule\_arn](#output\_cloudwatch\_event\_rule\_arn) | The cloudwatch event rule ARN |
137-
| <a name="output_cloudwatch_event_target_arn"></a> [cloudwatch\_event\_target\_arn](#output\_cloudwatch\_event\_target\_arn) | The cloudwatch event target ARN |
127+
| <a name="output_event_rule_arn"></a> [event\_rule\_arn](#output\_event\_rule\_arn) | The cloudwatch event rule ARN |
128+
| <a name="output_event_target_arn"></a> [event\_target\_arn](#output\_event\_target\_arn) | The cloudwatch event target ARN |
138129
<!-- END_TF_DOCS -->

examples/main.tf

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ terraform {
22
required_version = ">= 1.0.1"
33
required_providers {
44
aws = {
5-
version = "~> 3.74"
5+
version = "~> 4.35"
66
}
77
}
88
}
@@ -13,9 +13,12 @@ provider "aws" {
1313

1414
module "cloudwatch_event" {
1515
source = "../"
16-
17-
service_role = "<>"
18-
target_arn = "<>"
16+
cloudwatch_event_config = {
17+
demo_rule = {
18+
service_role = "arn:aws:iam::123456789012:role/demo-role"
19+
target_arn = "<lambda_role>"
20+
}
21+
}
1922
#-----------------------------------------------
2023
# Note: Do not change teamid and prjid once set.
2124
teamid = var.prjid

examples/outputs.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
output "cloudwatch_event_rule_arn" {
22
description = "The cloudwatch event rule arn."
3-
value = module.cloudwatch_event.cloudwatch_event_rule_arn
3+
value = module.cloudwatch_event.event_rule_arn
44
}
55

66
output "cloudwatch_event_target_arn" {
77
description = "The cloudwatch event target arn."
8-
value = module.cloudwatch_event.cloudwatch_event_target_arn
8+
value = module.cloudwatch_event.event_target_arn
99
}

examples/variables.tf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,23 @@
11
variable "teamid" {
22
description = "Name of the team/group e.g. devops, dataengineering. Should not be changed after running 'tf apply'"
33
type = string
4+
default = "hello"
45
}
56

67
variable "prjid" {
78
description = "Name of the project/stack e.g: mystack, nifieks, demoaci. Should not be changed after running 'tf apply'"
89
type = string
10+
default = "world"
911
}
1012

1113
variable "region" {
1214
description = "AWS region to create resources"
1315
default = "us-west-2"
1416
type = string
1517
}
18+
19+
variable "cloudwatch_event_config" {
20+
description = "Cloudwatch event configuration"
21+
type = map(any)
22+
default = {}
23+
}

main.tf

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,19 @@
1-
locals {
2-
default_input = { "sourceVersion" = var.branch, "timeoutInMinutesOverride" = var.timeout }
3-
event_input = var.custom_input == null ? local.default_input : var.custom_input
4-
}
5-
61
resource "aws_cloudwatch_event_rule" "event_rule" {
7-
count = var.deploy_event_rule ? 1 : 0
2+
for_each = var.cloudwatch_event_config != null ? var.cloudwatch_event_config : {}
83

9-
name = var.name != null ? "${var.name}-${var.suffix}" : "${var.teamid}-${var.prjid}-${var.suffix}"
10-
description = var.description == null ? "Terraform managed: ${var.teamid}-${var.prjid}" : var.description
11-
schedule_expression = var.schedule
12-
role_arn = var.service_role
4+
name = each.key
5+
description = try(each.value.description, "Terraform managed: ${var.teamid}-${var.prjid}")
6+
schedule_expression = try(each.value.schedule, "rate(1 day)")
7+
role_arn = each.value.service_role
138

14-
tags = merge(local.shared_tags)
9+
tags = merge(local.shared_tags, var.extra_tags)
1510
}
1611

1712
resource "aws_cloudwatch_event_target" "event_target_input_type" {
18-
count = var.deploy_event_target ? 1 : 0
13+
for_each = var.cloudwatch_event_config != null ? var.cloudwatch_event_config : {}
1914

20-
target_id = var.name != null ? var.name : "${var.teamid}-${var.prjid}"
21-
rule = aws_cloudwatch_event_rule.event_rule.*.id[count.index]
22-
arn = var.target_arn
23-
role_arn = var.service_role
24-
input = jsonencode(local.event_input)
15+
target_id = each.key
16+
rule = join("", [for rule in aws_cloudwatch_event_rule.event_rule : rule.id])
17+
arn = each.value.target_arn
18+
input = jsonencode(try(each.value.event_input, { "sourceVersion" = try(each.value.branch, "main"), "timeoutInMinutesOverride" = try(each.value.timeout, 60) }))
2519
}

outputs.tf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
output "cloudwatch_event_rule_arn" {
1+
output "event_rule_arn" {
22
description = "The cloudwatch event rule ARN"
3-
value = join("", aws_cloudwatch_event_rule.event_rule.*.arn)
3+
value = [for event in aws_cloudwatch_event_rule.event_rule : event.arn]
44
}
55

6-
output "cloudwatch_event_target_arn" {
6+
output "event_target_arn" {
77
description = "The cloudwatch event target ARN"
8-
value = join("", aws_cloudwatch_event_target.event_target_input_type.*.arn)
8+
value = [for target in aws_cloudwatch_event_rule.event_rule : target.arn]
99
}

providers.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ terraform {
22
required_version = ">= 1.0.1"
33
required_providers {
44
aws = {
5-
version = "~> 3.74"
5+
version = "~> 4.35"
66
}
77
}
88
}

0 commit comments

Comments
 (0)