I'm trying to find the best way to test my Terraform and infrastructure deployments. I know that using `terraform plan` helps to catch major issues before rolling out changes. Typically, I deploy changes from dev to staging and then to production. However, I encounter occasional breakages in the dev environment due to infrastructure changes, and debugging can be a hassle. Ideally, I'd love to have a process where I can run a series of targeted deployments that include tests right after the deployment to ensure everything works as expected. Any advice on how to set this up?
2 Answers
I test my Terraform modules in a separate environment. When I use Terratest, I apply the infra and validate the functionality before destroying it. Once the test passes, I publish the module to a private repository, which makes it easy to use as I move through dev to staging to production.
Terratest is a great tool from GruntWork specifically designed for testing Terraform. You can apply your infrastructure, run your assertions, and then destroy it afterward. If everything passes, you can publish the module for use in your deployments.
This is exactly what I do! It really streamlines the process.