Skip to content

Commit e44effa

Browse files
committed
Tests:
- Add tests (Ter1raform & OpenTofu - Add gitignore - Update example module setup and name - Fix MODULE_DIRECTORIES error - Add tflint config - Add README.md tests badge
1 parent e9790ab commit e44effa

File tree

11 files changed

+1883
-91
lines changed

11 files changed

+1883
-91
lines changed

.github/workflows/linter.yml

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

.github/workflows/tests.yml

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
name: "Tests"
2+
defaults:
3+
run:
4+
shell: bash
5+
on:
6+
pull_request:
7+
workflow_dispatch:
8+
9+
jobs:
10+
terraform-linter:
11+
name: Linter
12+
runs-on: ubuntu-24.04
13+
timeout-minutes: 5
14+
strategy:
15+
matrix:
16+
terraform_version: [1.5.6, 1.10.1]
17+
directory: [., ./examples/complete/]
18+
fail-fast: false
19+
steps:
20+
- name: Checkout Code
21+
uses: actions/checkout@v4
22+
with:
23+
submodules: true
24+
25+
- uses: hashicorp/setup-terraform@v3
26+
with:
27+
terraform_version: ${{ matrix.terraform_version }}
28+
29+
- name: Terraform init
30+
working-directory: ${{ matrix.directory }}
31+
run: terraform init
32+
33+
- name: Tflint Report Output
34+
uses: reviewdog/[email protected]
35+
with:
36+
working_directory: ${{ matrix.directory }}
37+
github_token: ${{ secrets.GITHUB_TOKEN }}
38+
tflint_version: "v0.49.0"
39+
reporter: github-pr-review
40+
fail_on_error: "true"
41+
filter_mode: "added"
42+
flags: "--module"
43+
44+
terraform-formatter:
45+
name: Formatter
46+
runs-on: ubuntu-24.04
47+
timeout-minutes: 5
48+
strategy:
49+
matrix:
50+
terraform_version: [1.5.6, 1.10.1]
51+
directory: [., ./examples/complete/]
52+
fail-fast: false
53+
steps:
54+
- name: Checkout Code
55+
uses: actions/checkout@v4
56+
with:
57+
submodules: true
58+
59+
- uses: hashicorp/setup-terraform@v3
60+
with:
61+
terraform_version: ${{ matrix.terraform_version }}
62+
63+
- name: Terraform init
64+
working-directory: ${{ matrix.directory }}
65+
run: terraform init
66+
67+
- name: Terraform Format suggestions
68+
working-directory: ${{ matrix.directory }}
69+
run: terraform fmt
70+
71+
- uses: reviewdog/[email protected]
72+
with:
73+
github_token: ${{ secrets.GITHUB_TOKEN }}
74+
tool_name: "terraform"
75+
fail_on_error: "true"
76+
filter_mode: "added"
77+
78+
terraform-e2e:
79+
name: E2E Tests (Terraform)
80+
strategy:
81+
max-parallel: 1
82+
matrix:
83+
terraform_version: [1.5.6, 1.10.1]
84+
os: [ubuntu-24.04]
85+
runs-on: ${{ matrix.os }}
86+
steps:
87+
- name: Checkout Code
88+
uses: actions/checkout@v4
89+
with:
90+
submodules: true
91+
92+
- uses: hashicorp/setup-terraform@v3
93+
with:
94+
terraform_version: ${{ matrix.terraform_version }}
95+
96+
- name: Install Go
97+
uses: actions/setup-go@v5
98+
with:
99+
go-version: 1.23.x
100+
101+
- name: Run Tests
102+
working-directory: test/
103+
env:
104+
LOCALSTACK_AUTH_TOKEN: ${{ secrets.LOCALSTACK_AUTH_TOKEN }}
105+
run: |
106+
go install github.com/gruntwork-io/terratest/cmd/terratest_log_parser@latest
107+
go mod tidy
108+
go test -v -timeout 60m -coverprofile=coverage-examples-complete.out -race -covermode=atomic | tee test_output.log
109+
terratest_log_parser -testlog test_output.log -outputdir results
110+
111+
- name: Test Summary
112+
uses: test-summary/action@v2
113+
with:
114+
paths: |
115+
test/results/**/*.xml
116+
test/results/*.xml
117+
118+
opentofu-e2e:
119+
name: E2E Tests (OpenTofu)
120+
strategy:
121+
max-parallel: 1
122+
matrix:
123+
opentofu_version: [1.6.0, 1.8.7]
124+
os: [ubuntu-24.04]
125+
runs-on: ${{ matrix.os }}
126+
steps:
127+
- name: Checkout Code
128+
uses: actions/checkout@v4
129+
with:
130+
submodules: true
131+
132+
- uses: opentofu/setup-opentofu@v1
133+
with:
134+
tofu_version: ${{ matrix.opentofu_version }}
135+
136+
- name: Install Go
137+
uses: actions/setup-go@v5
138+
with:
139+
go-version: 1.23.x
140+
141+
- name: Run Tests
142+
working-directory: test/
143+
env:
144+
LOCALSTACK_AUTH_TOKEN: ${{ secrets.LOCALSTACK_AUTH_TOKEN }}
145+
run: |
146+
go install github.com/gruntwork-io/terratest/cmd/terratest_log_parser@latest
147+
go mod tidy
148+
go test -v -timeout 60m -coverprofile=coverage-examples-complete.out -race -covermode=atomic | tee test_output.log
149+
terratest_log_parser -testlog test_output.log -outputdir results
150+
151+
- name: Test Summary
152+
uses: test-summary/action@v2
153+
with:
154+
paths: |
155+
test/results/**/*.xml
156+
test/results/*.xml
157+

.gitignore

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
### Terraform template
2+
# Local .terraform directories
3+
**/.terraform/*
4+
5+
# .tfstate files
6+
*.tfstate
7+
*.tfstate.*
8+
9+
# Crash log files
10+
crash.log
11+
crash.*.log
12+
13+
# Exclude all .tfvars files, which are likely to contain sensitive data, such as
14+
# password, private keys, and other secrets. These should not be part of version
15+
# control as they are data points which are potentially sensitive and subject
16+
# to change depending on the environment.
17+
*.tfvars
18+
*.tfvars.json
19+
20+
# Ignore override files as they are usually used to override resources locally and so
21+
# are not checked in
22+
override.tf
23+
override.tf.json
24+
*_override.tf
25+
*_override.tf.json
26+
27+
# Ignore transient lock info files created by terraform apply
28+
.terraform.tfstate.lock.info
29+
30+
# Include override files you do wish to add to version control using negated pattern
31+
# !example_override.tf
32+
33+
# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan
34+
# example: *tfplan*
35+
36+
# Ignore CLI configuration files
37+
.terraformrc
38+
terraform.rc
39+

.tflint.hcl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Basic tflint configuration
2+
plugin "aws" {
3+
enabled = true
4+
}

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Terraform AWS SSM Parameters Module
2+
[![Tests](https://github.com/automationd/atun/actions/workflows/tests.yml/badge.svg)](https://github.com/AutomationD/atun/actions/workflows/tests.yml)
23

34
The main goal of the module is to provide a consistent way to manage service SSM parameters. Suitable for use with [External Secrets](https://external-secrets.io/latest/).
45

@@ -71,4 +72,4 @@ No modules.
7172
| Name | Description |
7273
|------|-------------|
7374
| <a name="output_ssm_parameter_paths"></a> [ssm\_parameter\_paths](#output\_ssm\_parameter\_paths) | A list of paths to created parameters |
74-
<!-- END_TF_DOCS -->
75+
<!-- END_TF_DOCS -->

examples/complete/.tflint.hcl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Simple Terraform Module Example doesn't have provider configuration
2+
plugin "aws" {
3+
enabled = true
4+
}
5+
6+
# Ignore missing providers warning
7+
rule "missing-provider" {
8+
enabled = false
9+
}

examples/complete/main.tf

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
resource "aws_s3_bucket" "krabby_demo" {
2+
bucket = "dev-krabby-demo"
3+
tags = {
4+
Name = "Demo Krabby bucket"
5+
Environment = "dev"
6+
}
7+
}
8+
9+
module "krabby" {
10+
source = "../../"
11+
env = "dev"
12+
name = "krabby"
13+
14+
parameters = {
15+
API_KEY = "api-XXXXXXXXXXXXXXXXXXXXX"
16+
S3_BUCKET_ARN = aws_s3_bucket.krabby_demo.arn
17+
S3_BUCKET_NAME = aws_s3_bucket.krabby_demo.id
18+
}
19+
}

examples/main.tf

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

0 commit comments

Comments
 (0)