autero1 / testing-terraform-with-actions

Automate Testing for Terraform with GitHub Actions and Terratest

Home Page:https://medium.com/p/78d74331fdf8

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Testing Infrastructure Code with GitHub Actions and Terratest

This repository is an example of testing IaC libraries written with Terraform using GitHub Actions. For a detailed run-through, see the see accompanying blog post Automate Terraform Testing with GitHub Actions and Terratest.

Prerequisites

To successfully run all the examples, you need the following tools:

Running the tests

Note that to run the tests, you will have to have AWS Credentials available for Terraform.

Unit tests

As the unit tests don't create any resources, they're safe to run as is. Check out the terratest unit test file for details.

To run the unit tests, go to the test directory and run go test -v -tags=unit.

Integration tests

Integration test creates actual resources in AWS, so you will first have to set up your AWS Credentials. Once that's done, you can run go test -v -tags=integration. Check out the terratest integration test file for details.

Prettier test output

Go test output can sometimes be hard to read. A good tool to get human readable output is gotestsum. Instead of the very verbose output, you get something like this:

❯ gotestsum --format short-verbose -- -tags=unit
PASS TestStaticSiteValidity (12.63s)
PASS .
DONE 1 tests in 15.416s

Useful links

Tools used in this repository

Developing Modules and Infrastructure as Code

GitHub Actions for installing Terraform and Terragrunt

Other utilities

About

Automate Testing for Terraform with GitHub Actions and Terratest

https://medium.com/p/78d74331fdf8


Languages

Language:Go 70.9%Language:HCL 29.1%