Skip to content

Commit 1bb6b03

Browse files
authored
Merge pull request #6 from tomarv2/develop
Pulling refs/heads/develop into main
2 parents 7797ad4 + e568627 commit 1bb6b03

File tree

12 files changed

+138
-54
lines changed

12 files changed

+138
-54
lines changed

.github/workflows/pre-commit.yml

Lines changed: 58 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@ on:
44
pull_request:
55
push:
66
branches:
7-
- main
87
- develop
8+
- main
99

1010
jobs:
11-
# Min Terraform version(s)
1211
getDirectories:
1312
name: Get root directories
1413
runs-on: ubuntu-latest
@@ -25,13 +24,13 @@ jobs:
2524
- name: Build matrix
2625
id: matrix
2726
run: |
28-
DIRS=$(python -c "import json; import glob; print(json.dumps([x.replace('/versions.tf', '') for x in glob.glob('./**/versions.tf', recursive=True)]))")
27+
DIRS=$(python -c "import json; import glob; print(json.dumps([x.replace('/providers.tf', '') for x in glob.glob('./**/providers.tf', recursive=True)]))")
2928
echo "::set-output name=directories::$DIRS"
3029
outputs:
3130
directories: ${{ steps.matrix.outputs.directories }}
3231

3332
preCommitMinVersions:
34-
name: Min TF validate
33+
name: Min validate
3534
needs: getDirectories
3635
runs-on: ubuntu-latest
3736
strategy:
@@ -58,11 +57,9 @@ jobs:
5857
with:
5958
terraform_version: ${{ steps.minMax.outputs.minVersion }}
6059

61-
- name: Install pre-commit dependencies
60+
- name: Install pre-commit
6261
run: pip install pre-commit
6362

64-
65-
# Max Terraform version
6663
getBaseVersion:
6764
name: Module max TF version
6865
runs-on: ubuntu-latest
@@ -78,7 +75,7 @@ jobs:
7875
maxVersion: ${{ steps.minMax.outputs.maxVersion }}
7976

8077
preCommitMaxVersion:
81-
name: Max TF pre-commit
78+
name: Max pre-commit
8279
runs-on: ubuntu-latest
8380
needs: getBaseVersion
8481
strategy:
@@ -105,10 +102,59 @@ jobs:
105102
run: |
106103
pip install pre-commit
107104
pip install checkov
108-
curl -L "$(curl -s https://api.github.com/repos/terraform-docs/terraform-docs/releases/latest | grep -o -E "https://.+?-v1.0.1-linux-amd64" | head -n1)" > terraform-docs && chmod +x terraform-docs && sudo mv terraform-docs /usr/bin/
109105
curl -L "$(curl -s https://api.github.com/repos/terraform-linters/tflint/releases/latest | grep -o -E "https://.+?_linux_amd64.zip")" > tflint.zip && unzip tflint.zip && rm tflint.zip && sudo mv tflint /usr/bin/
110106
111107
- name: Execute pre-commit
112-
# Run all pre-commit checks on max version supported
113-
if: ${{ matrix.version == needs.getBaseVersion.outputs.maxVersion }}
114-
run: pre-commit run --color=always --show-diff-on-failure --all-files
108+
continue-on-error: true # To avoid pre-commit failure
109+
run: |
110+
pre-commit run --color=always --show-diff-on-failure --all-files
111+
112+
- name: Get current branch name
113+
id: vars
114+
run: |
115+
echo ::set-output name=branch_name::${GITHUB_REF##*/}
116+
117+
- name: "Get branch name and save to env"
118+
env:
119+
IS_PR: ${{ github.EVENT_NAME == 'pull_request' }}
120+
run: |
121+
if ${IS_PR}; then
122+
BRANCH_NAME="${GITHUB_HEAD_REF}"
123+
else
124+
BRANCH_NAME="${GITHUB_REF##*/}"
125+
fi
126+
echo "BRANCH_NAME=${BRANCH_NAME}" >> $GITHUB_ENV
127+
128+
- uses: actions/checkout@v2
129+
with:
130+
ref: ${{ github.event.pull_request.head.ref }}
131+
132+
- name: Render terraform docs and commit changes
133+
if: ${{ env.BRANCH_NAME }} == 'develop'
134+
uses: terraform-docs/gh-actions@main
135+
with:
136+
working-dir: .
137+
output-file: README.md
138+
output-method: inject
139+
git-push: "true"
140+
141+
- name: Commit pre-commit modified files
142+
if: ${{ env.BRANCH_NAME }} == 'develop'
143+
run: |
144+
git config --local user.email "terraform+github-actions[bot]@users.noreply.github.com"
145+
git config --local user.name "github-actions[bot]"
146+
git diff-index --quiet HEAD || (git add -A && git commit -m'[bot] update files' --allow-empty && git push -f)
147+
148+
- uses: actions/checkout@v2
149+
- name: Create PR
150+
continue-on-error: true
151+
uses: repo-sync/pull-request@v2
152+
if: ${{ env.BRANCH_NAME }} == 'develop'
153+
with:
154+
source_branch: "develop"
155+
destination_branch: "main"
156+
pr_title: "Pulling ${{ github.ref }} into main"
157+
pr_body: ":crown: *Automated PR*"
158+
pr_label: "auto-pr"
159+
pr_allow_empty: false
160+
github_token: ${{ secrets.GITHUB_TOKEN }}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: "Mark or close stale issues and PRs"
2+
on:
3+
schedule:
4+
- cron: "0 0 10 * *"
5+
6+
jobs:
7+
stale:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/stale@v4
11+
with:
12+
repo-token: ${{ secrets.GITHUB_TOKEN }}
13+
# Staling issues and PR's
14+
days-before-stale: 30
15+
stale-issue-label: stale
16+
stale-pr-label: stale
17+
stale-issue-message: |
18+
This issue has been automatically marked as stale because it has been open 30 days
19+
with no activity. Remove stale label or comment or this issue will be closed in 10 days
20+
stale-pr-message: |
21+
This PR has been automatically marked as stale because it has been open 30 days
22+
with no activity. Remove stale label or comment or this PR will be closed in 10 days
23+
# Not stale if have this labels or part of milestone
24+
exempt-issue-labels: bug,wip,on-hold
25+
exempt-pr-labels: bug,wip,on-hold
26+
exempt-all-milestones: true
27+
# Close issue operations
28+
# Label will be automatically removed if the issues are no longer closed nor locked.
29+
days-before-close: 10
30+
delete-branch: false
31+
close-issue-message: This issue was automatically closed because of stale in 10 days
32+
close-pr-message: This PR was automatically closed because of stale in 10 days

.gitignore

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ override.tf.json
2929
# example: *tfplan*
3030

3131
.idea/
32+
.vscode/
3233
.terraform.lock.hcl
3334

3435
# go
@@ -81,15 +82,10 @@ _testmain.go
8182

8283
# Python
8384
# Editors
84-
.vscode/
85-
.idea/
8685

8786
# Vagrant
8887
.vagrant/
8988

90-
# Mac/OSX
91-
.DS_Store
92-
9389
# Windows
9490
Thumbs.db
9591

@@ -99,9 +95,6 @@ __pycache__/
9995
*.py[cod]
10096
*$py.class
10197

102-
# C extensions
103-
*.so
104-
10598
# Distribution / packaging
10699
.Python
107100
build/
@@ -206,9 +199,14 @@ venv.bak/
206199
.dmypy.json
207200
dmypy.json
208201

209-
# ignore test related file(s)
210-
**/test**
211-
**.
212-
213-
# ignore terraform external modules
202+
# Terraform external modules
214203
**/.external_modules
204+
205+
# Test files and directories
206+
**/[Tt]est/*
207+
**/[Tt]ests/*
208+
**/*[Tt]est*/*
209+
**/*[Tt]ests*/*
210+
211+
# remote_backend.tf file
212+
**/remote_backend.tf

.pre-commit-config.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
2-
- repo: git://github.com/antonbabenko/pre-commit-terraform
3-
rev: v1.60.0
2+
- repo: https://github.com/antonbabenko/pre-commit-terraform
3+
rev: v1.64.0
44
hooks:
55
- id: terraform_fmt
66
- id: terraform_tflint
@@ -12,7 +12,7 @@ repos:
1212
- '--args=--only=terraform_documented_outputs'
1313
- '--args=--only=terraform_documented_variables'
1414
- '--args=--only=terraform_typed_variables'
15-
- '--args=--only=terraform_module_pinned_source'
15+
#- '--args=--only=terraform_module_pinned_source'
1616
- '--args=--only=terraform_naming_convention'
1717
- '--args=--only=terraform_required_providers'
1818
- '--args=--only=terraform_standard_module_structure'

README.md

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,20 @@
1313
<img src="https://img.shields.io/twitter/follow/varuntomar2019?style=social&logo=twitter"></a>
1414
</p>
1515

16-
# Terraform module for [AWS CloudWatch Events](https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/WhatIsCloudWatchEvents.html)
16+
## Terraform module for [AWS CloudWatch Events](https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/WhatIsCloudWatchEvents.html)
1717

18-
## Versions
18+
### Versions
1919

2020
- Module tested for Terraform 1.0.1.
21-
- AWS provider version [3.63](https://registry.terraform.io/providers/hashicorp/aws/latest)
21+
- AWS provider version [3.74](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>).
2525

2626

27-
## Usage
27+
### Usage
2828

29-
### Option 1:
29+
#### Option 1:
3030

3131
```
3232
terrafrom init
@@ -36,9 +36,9 @@ terraform destroy -var='teamid=tryme' -var='prjid=project1'
3636
```
3737
**Note:** With this option please take care of remote state storage
3838

39-
### Option 2:
39+
#### 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 S3 using `prjid` and `teamid` to create directory structure):
4242

4343
- Create python 3.8+ virtual environment
4444
```
@@ -84,23 +84,21 @@ tf -c=aws apply -var='teamid=foo' -var='prjid=bar'
8484
tf -c=aws destroy -var='teamid=foo' -var='prjid=bar'
8585
```
8686

87-
**NOTE:**
88-
89-
- Read more on [tfremote](https://github.com/tomarv2/tfremote)
90-
---
87+
**Note:** Read more on [tfremote](https://github.com/tomarv2/tfremote)
9188

89+
<!-- BEGIN_TF_DOCS -->
9290
## Requirements
9391

9492
| Name | Version |
9593
|------|---------|
9694
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0.1 |
97-
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 3.63 |
95+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | ~> 3.74 |
9896

9997
## Providers
10098

10199
| Name | Version |
102100
|------|---------|
103-
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 3.63 |
101+
| <a name="provider_aws"></a> [aws](#provider\_aws) | ~> 3.74 |
104102

105103
## Modules
106104

@@ -117,26 +115,24 @@ No modules.
117115

118116
| Name | Description | Type | Default | Required |
119117
|------|-------------|------|---------|:--------:|
120-
| <a name="input_aws_region"></a> [aws\_region](#input\_aws\_region) | aws region to deploy resources | `string` | `"us-west-2"` | no |
121118
| <a name="input_branch"></a> [branch](#input\_branch) | branch to use for cicd | `string` | `"main"` | no |
122119
| <a name="input_custom_input"></a> [custom\_input](#input\_custom\_input) | custom input to be included in generated events | `map(any)` | `null` | no |
123120
| <a name="input_deploy_event_rule"></a> [deploy\_event\_rule](#input\_deploy\_event\_rule) | Feature flag, true or false | `bool` | `true` | no |
124121
| <a name="input_deploy_event_target"></a> [deploy\_event\_target](#input\_deploy\_event\_target) | Feature flag, true or false | `bool` | `true` | no |
125122
| <a name="input_description"></a> [description](#input\_description) | description for the cloudwatch event | `string` | `null` | no |
126123
| <a name="input_name"></a> [name](#input\_name) | Cloudwatch event rule name | `string` | `null` | no |
127124
| <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 |
128-
| <a name="input_profile"></a> [profile\_to\_use](#input\_profile\_to\_use) | Getting values from ~/.aws/credentials | `string` | `"default"` | no |
129125
| <a name="input_schedule"></a> [schedule](#input\_schedule) | schedule for the cloudwatch event | `string` | `"rate(1 day)"` | no |
130126
| <a name="input_service_role"></a> [service\_role](#input\_service\_role) | service role to be used by cicd | `string` | `null` | no |
131127
| <a name="input_suffix"></a> [suffix](#input\_suffix) | suffix to be added to cloudwatch rule name | `string` | `"rule"` | no |
132128
| <a name="input_target_arn"></a> [target\_arn](#input\_target\_arn) | target arn | `string` | n/a | yes |
133-
| <a name="input_target_name"></a> [target\_name](#input\_target\_name) | Cloudwatch target name | `string` | `null` | no |
134129
| <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 |
135130
| <a name="input_timeout"></a> [timeout](#input\_timeout) | timeout for cloudwatch event | `number` | `60` | no |
136131

137132
## Outputs
138133

139134
| Name | Description |
140135
|------|-------------|
141-
| <a name="output_cloudwatch_event_rule_arn"></a> [cloudwatch\_event\_rule\_arn](#output\_cloudwatch\_event\_rule\_arn) | The cloudwatch event rule arn. |
142-
| <a name="output_cloudwatch_event_target_arn"></a> [cloudwatch\_event\_target\_arn](#output\_cloudwatch\_event\_target\_arn) | The cloudwatch event target arn. |
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 |
138+
<!-- END_TF_DOCS -->

examples/main.tf

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

1010
provider "aws" {
11-
region = "us-west-2"
11+
region = var.region
1212
}
1313

1414
module "cloudwatch_event" {

examples/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,9 @@ variable "prjid" {
77
description = "Name of the project/stack e.g: mystack, nifieks, demoaci. Should not be changed after running 'tf apply'"
88
type = string
99
}
10+
11+
variable "region" {
12+
description = "AWS region to create resources"
13+
default = "us-west-2"
14+
type = string
15+
}

main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ locals {
66
resource "aws_cloudwatch_event_rule" "event_rule" {
77
count = var.deploy_event_rule ? 1 : 0
88

9-
name = var.name != null ? var.name : "${var.teamid}-${var.prjid}"
9+
name = var.name != null ? "${var.name}-${var.suffix}" : "${var.teamid}-${var.prjid}-${var.suffix}"
1010
description = var.description == null ? "Terraform managed: ${var.teamid}-${var.prjid}" : var.description
1111
schedule_expression = var.schedule
1212
role_arn = var.service_role

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" {
2-
description = "The cloudwatch event rule arn."
2+
description = "The cloudwatch event rule ARN"
33
value = join("", aws_cloudwatch_event_rule.event_rule.*.arn)
44
}
55

66
output "cloudwatch_event_target_arn" {
7-
description = "The cloudwatch event target arn."
7+
description = "The cloudwatch event target ARN"
88
value = join("", aws_cloudwatch_event_target.event_target_input_type.*.arn)
99
}

versions.tf renamed to 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.63"
5+
version = "~> 3.74"
66
}
77
}
88
}

0 commit comments

Comments
 (0)