Skip to content

Useful infrastructure testing abstractions over the popular Terratest library

License

Notifications You must be signed in to change notification settings

microsoft/terratest-abstraction

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Terratest Abstraction

This Go package offers abstractions over the popular Terratest library in order to abstract some common testing patterns that have been identified through multiple projects that deploy Infrastructure as Code (IAC) using Terraform. The abstractions offered here can be used along side existing Terratest code and are quite easy to drop into existing projects. Feedback and OSS contributions are welcome!

When to use?

Development teams that rely on automated deployments of any kind demand robust automated validation of those environments in order to have confidence in changes. The results of these automated changes will allow software and operations engineers to sleep well at night, knowing that large classes of defects will be caught by repeatable and automated checks against their runtime systems. These concepts apply equally to software and infrastructure deployments.

terratest-abstraction offers an intuitive interface to testing Terraform deployments that offers a more declarative approach to writing test cases. There is support for testing the Terraform Plan as a pre-deployment unit test and Terraform Output as a post-deployment integration test.

Getting started

Writing unit tests

A full example unit test is included in the samples directory. Check out unit_test.go to see a unit test for the included sample main.tf. The included README.md provides instructions for running this example.

Writing integration tests

A full example integration test is included in the samples directory. Check out integration_test.go to see a unit test for the included sample main.tf. The included README.md provides instructions for running this example.

Automating in CICD pipelines

Tests written with terratest-abstraction can be invoked like any other Golang test. We recommend separating unit and integration tests so that they can be easily targeted at build and deploy time within an automated CICD pipeline. The samples all follow this structure:

$ tree
├── README.md
├── main.tf             # other terraform files live here
└── tests
    ├── commons.go      # common test code lives here
    ├── integration     # integration tests live here
    └── unit            # unit tests live here

If you follow this structure, then it is easy to invoke tests written with terratest-abstraction using the following commands:

Unit Tests

# before executing `terraform plan`
go test -v $(go list ./... | grep unit)

Integration Tests

# after executing `terraform apply`
go test -v $(go list ./... | grep integration)

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.

When you submit a pull request, a CLA bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.

About

Useful infrastructure testing abstractions over the popular Terratest library

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •