How to test your Terraform code
24.JUN.2022
Senior DevOps Engineer
Rafael Natali
rafael.natali@marionete.co.uk
https://github.com/rafaelmnatali
https://marionete.co.uk
2
© 2022 Marionete Limited
Why do you need to test your infrastructure?
Why “Terraform Plan” is not enough?
Introduction to “Terraform Test”
Testing your infrastructure - DEMO
“Terraform Test” limitations
1
2
3
4
5
© 2022 Marionete Limited
Test-driven infrastructure
Why do you need to test your infrastructure?
4
© 2022 Marionete Limited
Plan output
Why “Terraform Plan” is not enough?
TERMINAL
+ resource "google_storage_bucket" "bucket" {
+ force_destroy = true
+ id = (known after apply)
+ location = "EU"
+ name = (known after apply)
...
5
© 2022 Marionete Limited
“Terraform Test”
Introduction to “Terraform Test”
6
© 2022 Marionete Limited
DEMO – GCP Buckets
Testing your infrastructure
7
© 2022 Marionete Limited
Experimental feature
“Terraform Test” limitations
There are a few limitations on how it works. The two main limitations I’d like to highlight are:
Please, refer to the Hashicorp documentation for a complete list.
8
© 2022 Marionete Limited