Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Terraform & OpenTofu End-to-End tests, minor cleanup #6

Merged
merged 1 commit into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 0 additions & 72 deletions .github/workflows/linter.yml

This file was deleted.

157 changes: 157 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
name: "Tests"
defaults:
run:
shell: bash
on:
pull_request:
workflow_dispatch:

jobs:
terraform-linter:
name: Linter
runs-on: ubuntu-24.04
timeout-minutes: 5
strategy:
matrix:
terraform_version: [1.5.6, 1.10.1]
directory: [., ./examples/complete/]
fail-fast: false
steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
submodules: true

- uses: hashicorp/setup-terraform@v3
with:
terraform_version: ${{ matrix.terraform_version }}

- name: Terraform init
working-directory: ${{ matrix.directory }}
run: terraform init

- name: Tflint Report Output
uses: reviewdog/[email protected]
with:
working_directory: ${{ matrix.directory }}
github_token: ${{ secrets.GITHUB_TOKEN }}
tflint_version: "v0.49.0"
reporter: github-pr-review
fail_on_error: "true"
filter_mode: "added"
flags: "--module"

terraform-formatter:
name: Formatter
runs-on: ubuntu-24.04
timeout-minutes: 5
strategy:
matrix:
terraform_version: [1.5.6, 1.10.1]
directory: [., ./examples/complete/]
fail-fast: false
steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
submodules: true

- uses: hashicorp/setup-terraform@v3
with:
terraform_version: ${{ matrix.terraform_version }}

- name: Terraform init
working-directory: ${{ matrix.directory }}
run: terraform init

- name: Terraform Format suggestions
working-directory: ${{ matrix.directory }}
run: terraform fmt

- uses: reviewdog/[email protected]
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
tool_name: "terraform"
fail_on_error: "true"
filter_mode: "added"

terraform-e2e:
name: E2E Tests (Terraform)
strategy:
max-parallel: 1
matrix:
terraform_version: [1.5.6, 1.10.1]
os: [ubuntu-24.04]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
submodules: true

- uses: hashicorp/setup-terraform@v3
with:
terraform_version: ${{ matrix.terraform_version }}

- name: Install Go
uses: actions/setup-go@v5
with:
go-version: 1.23.x

- name: Run Tests
working-directory: test/
env:
LOCALSTACK_AUTH_TOKEN: ${{ secrets.LOCALSTACK_AUTH_TOKEN }}
run: |
go install github.com/gruntwork-io/terratest/cmd/terratest_log_parser@latest
go mod tidy
go test -v -timeout 60m -coverprofile=coverage-examples-complete.out -race -covermode=atomic | tee test_output.log
terratest_log_parser -testlog test_output.log -outputdir results

- name: Test Summary
uses: test-summary/action@v2
with:
paths: |
test/results/**/*.xml
test/results/*.xml

opentofu-e2e:
name: E2E Tests (OpenTofu)
strategy:
max-parallel: 1
matrix:
opentofu_version: [1.6.0, 1.8.7]
os: [ubuntu-24.04]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
submodules: true

- uses: opentofu/setup-opentofu@v1
with:
tofu_version: ${{ matrix.opentofu_version }}

- name: Install Go
uses: actions/setup-go@v5
with:
go-version: 1.23.x

- name: Run Tests
working-directory: test/
env:
LOCALSTACK_AUTH_TOKEN: ${{ secrets.LOCALSTACK_AUTH_TOKEN }}
run: |
go install github.com/gruntwork-io/terratest/cmd/terratest_log_parser@latest
go mod tidy
go test -v -timeout 60m -coverprofile=coverage-examples-complete.out -race -covermode=atomic | tee test_output.log
terratest_log_parser -testlog test_output.log -outputdir results

- name: Test Summary
uses: test-summary/action@v2
with:
paths: |
test/results/**/*.xml
test/results/*.xml

39 changes: 39 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
### Terraform template
# Local .terraform directories
**/.terraform/*

# .tfstate files
*.tfstate
*.tfstate.*

# Crash log files
crash.log
crash.*.log

# Exclude all .tfvars files, which are likely to contain sensitive data, such as
# password, private keys, and other secrets. These should not be part of version
# control as they are data points which are potentially sensitive and subject
# to change depending on the environment.
*.tfvars
*.tfvars.json

# Ignore override files as they are usually used to override resources locally and so
# are not checked in
override.tf
override.tf.json
*_override.tf
*_override.tf.json

# Ignore transient lock info files created by terraform apply
.terraform.tfstate.lock.info

# Include override files you do wish to add to version control using negated pattern
# !example_override.tf

# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan
# example: *tfplan*

# Ignore CLI configuration files
.terraformrc
terraform.rc

4 changes: 4 additions & 0 deletions .tflint.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Basic tflint configuration
plugin "aws" {
enabled = true
}
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Terraform AWS SSM Parameters Module
[![Tests](https://github.com/automationd/atun/actions/workflows/tests.yml/badge.svg)](https://github.com/AutomationD/atun/actions/workflows/tests.yml)

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/).

Expand Down Expand Up @@ -71,4 +72,4 @@ No modules.
| Name | Description |
|------|-------------|
| <a name="output_ssm_parameter_paths"></a> [ssm\_parameter\_paths](#output\_ssm\_parameter\_paths) | A list of paths to created parameters |
<!-- END_TF_DOCS -->
<!-- END_TF_DOCS -->
9 changes: 9 additions & 0 deletions examples/complete/.tflint.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Simple Terraform Module Example doesn't have provider configuration
plugin "aws" {
enabled = true
}

# Ignore missing providers warning
rule "missing-provider" {
enabled = false
}
19 changes: 19 additions & 0 deletions examples/complete/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
resource "aws_s3_bucket" "krabby_demo" {
AutomationD marked this conversation as resolved.
Show resolved Hide resolved
bucket = "dev-krabby-demo"
tags = {
Name = "Demo Krabby bucket"
Environment = "dev"
}
}

module "krabby" {
source = "../../"
env = "dev"
name = "krabby"

parameters = {
API_KEY = "api-XXXXXXXXXXXXXXXXXXXXX"
S3_BUCKET_ARN = aws_s3_bucket.krabby_demo.arn
S3_BUCKET_NAME = aws_s3_bucket.krabby_demo.id
}
}
18 changes: 0 additions & 18 deletions examples/main.tf

This file was deleted.

Loading
Loading