Skip to content

Commit 7dcb521

Browse files
authored
feat(cicd): add terraform-min-max validation workflow to validate module changes (#1)
1 parent cbd7bbf commit 7dcb521

File tree

7 files changed

+92
-14
lines changed

7 files changed

+92
-14
lines changed

.github/workflows/semantic-releaser.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,29 @@
11
name: Release
2+
23
on:
34
push:
45
branches:
56
- master
67
paths:
78
- '**.tf'
89
- '!examples/**.tf'
10+
911
jobs:
1012
release:
1113
name: Release
12-
runs-on: ubuntu-18.04
14+
runs-on: ubuntu-latest
1315
steps:
1416
- name: Checkout
1517
uses: actions/checkout@v2
1618
with:
1719
fetch-depth: 0
1820
persist-credentials: false
21+
1922
- name: Setup Node.js
2023
uses: actions/setup-node@v1
2124
with:
2225
node-version: 14
26+
2327
- name: Release
2428
env:
2529
GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }}

.github/workflows/static-checks.yml

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: static-checks
2+
3+
on:
4+
pull_request:
5+
6+
jobs:
7+
versionExtract:
8+
name: Get min/max versions
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- name: Checkout
13+
uses: actions/checkout@v2
14+
15+
- name: Terraform min/max versions
16+
id: minMax
17+
uses: clowdhaus/terraform-min-max@main
18+
outputs:
19+
minVersion: ${{ steps.minMax.outputs.minVersion }}
20+
maxVersion: ${{ steps.minMax.outputs.maxVersion }}
21+
22+
versionEvaluate:
23+
name: Evaluate Terraform versions
24+
runs-on: ubuntu-latest
25+
needs: versionExtract
26+
strategy:
27+
fail-fast: false
28+
matrix:
29+
version:
30+
- ${{ needs.versionExtract.outputs.minVersion }}
31+
- ${{ needs.versionExtract.outputs.maxVersion }}
32+
directory: [examples/complete, examples/simple]
33+
34+
steps:
35+
- name: Checkout
36+
uses: actions/checkout@v2
37+
38+
- name: Install Terraform v${{ matrix.version }}
39+
uses: hashicorp/setup-terraform@v1
40+
with:
41+
terraform_version: ${{ matrix.version }}
42+
43+
- name: Init & validate v${{ matrix.version }}
44+
run: |
45+
cd ${{ matrix.directory }}
46+
terraform init
47+
terraform validate
48+
49+
- name: tflint
50+
uses: reviewdog/action-tflint@master
51+
with:
52+
github_token: ${{ secrets.GITHUB_TOKEN }}
53+
working_directory: ${{ matrix.directory }}
54+
fail_on_error: 'true'
55+
filter_mode: 'nofilter'
56+
flags: '--module'
57+
58+
format:
59+
name: Check code format
60+
runs-on: ubuntu-latest
61+
needs: versionExtract
62+
63+
steps:
64+
- name: Checkout
65+
uses: actions/checkout@v2
66+
67+
- name: Install Terraform v${{ needs.versionExtract.outputs.maxVersion }}
68+
uses: hashicorp/setup-terraform@v1
69+
with:
70+
terraform_version: ${{ needs.versionExtract.outputs.maxVersion }}
71+
72+
- name: Check Terraform format changes
73+
run: terraform fmt --recursive -check=true

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ repos:
55
- id: terraform_fmt
66
- id: terraform_docs
77
- repo: git://github.com/pre-commit/pre-commit-hooks
8-
rev: v3.3.0
8+
rev: v3.4.0
99
hooks:
10-
- id: check-merge-conflict
10+
- id: check-merge-conflict

examples/complete/main.tf

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,13 @@ data "aws_iam_policy_document" "datadog_cmk" {
5252
}
5353

5454
resource "aws_kms_alias" "datadog" {
55-
name = "alias/datadog"
55+
name = "alias/datadog/${random_pet.this.id}"
5656
target_key_id = aws_kms_key.datadog.key_id
5757
}
5858

5959
module "vpc" {
6060
source = "terraform-aws-modules/vpc/aws"
61-
version = "v2.57.0"
61+
version = "~> 2.64"
6262

6363
name = local.name
6464
cidr = "10.0.0.0/16"
@@ -84,7 +84,7 @@ module "vpc" {
8484

8585
module "security_group" {
8686
source = "terraform-aws-modules/security-group/aws"
87-
version = "~> v3.16.0"
87+
version = "~> 3.17"
8888

8989
name = local.name
9090
description = "Example security group"
@@ -114,7 +114,7 @@ module "security_group" {
114114

115115
module "log_bucket_1" {
116116
source = "terraform-aws-modules/s3-bucket/aws"
117-
version = "~> 1.15"
117+
version = "~> 1.17"
118118

119119
bucket = "logs-1-${random_pet.this.id}"
120120
acl = "log-delivery-write"
@@ -124,7 +124,7 @@ module "log_bucket_1" {
124124

125125
module "log_bucket_2" {
126126
source = "terraform-aws-modules/s3-bucket/aws"
127-
version = "~> 1.15"
127+
version = "~> 1.17"
128128

129129
bucket = "logs-2-${random_pet.this.id}"
130130
acl = "log-delivery-write"
@@ -252,7 +252,5 @@ module "default" {
252252
traces_vpce_security_group_ids = [module.security_group.this_security_group_id]
253253
traces_vpce_tags = { TracesVpcEndpoint = true }
254254

255-
depends_on = [aws_kms_alias.datadog]
256-
257255
tags = { Environment = "test" }
258256
}

examples/simple/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ Note that this example may create resources which will incur monetary charges on
2727
| Name | Version |
2828
|------|---------|
2929
| aws | >= 3.0 |
30+
| random | n/a |
3031

3132
## Inputs
3233

examples/simple/main.tf

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ data "aws_caller_identity" "current" {}
1818
# Supporting Resources
1919
################################################################################
2020

21+
resource "random_pet" "this" {
22+
length = 2
23+
}
24+
2125
resource "aws_kms_key" "datadog" {
2226
description = "Datadog KMS CMK"
2327
enable_key_rotation = true
@@ -39,7 +43,7 @@ data "aws_iam_policy_document" "datadog_cmk" {
3943
}
4044

4145
resource "aws_kms_alias" "datadog" {
42-
name = "alias/datadog"
46+
name = "alias/datadog/${random_pet.this.id}"
4347
target_key_id = aws_kms_key.datadog.key_id
4448
}
4549

@@ -53,7 +57,5 @@ module "default" {
5357
kms_alias = aws_kms_alias.datadog.name
5458
dd_api_key_secret_arn = data.aws_secretsmanager_secret.datadog_api_key.arn
5559

56-
depends_on = [aws_kms_alias.datadog]
57-
5860
tags = { Environment = "test" }
5961
}

modules/log_forwarder/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ data "aws_region" "current" {}
2525

2626
module "this_s3_bucket" {
2727
source = "terraform-aws-modules/s3-bucket/aws"
28-
version = "v1.15.0"
28+
version = "v1.17.0"
2929

3030
create_bucket = var.create && var.create_bucket
3131
bucket = local.bucket_name

0 commit comments

Comments
 (0)