Member-only story
Test Azure Terraform code with Terratest

As a experienced terraform developer with Azure I always wanted to fully automated my Azure infrastructure with terraform, including terraform test. Terragrunt provides a way to write test cases the terraform infrastructure which they calls Terratest , Terratest is the testing framework written in golang programming language…the Terratest document has some basic example to test IaC written using different tools such as terraform, Kubernetes, docker etc. so the documentation which they have on their website is very generic and someone like me who is not expert into terragrunt or golang always finds difficulties to write test case for my azure terraform Infrastructure as Code (IaC), at least this was the case with me 😇.
In the last couple of days I tried learning basics of golang and thought of writing my own way to implement the test cases for my azure terraform code, finally I have learned how to write Terratest with azure terraform code and at some extend I have manage simplified the test case with terraform in azure.
In this blog I would like share the best test writing approach I understand with Terratest.
If you prefer the video rather then blog the same implementation you can find here on my YouTube channel
Rule-1 👍: always write your terraform code into small-small module and test the individual modules with terratest.
Step-01 👉: First of all we need to setup our terraform code or I should say terraform module code which we would like to test, for this blog explanation we are going to use azure virtual network resource module in our repository
in the main.tf file I have added terraform code to create virtual network in azure which you can find here on terraform azure provider documentation its very easy.
Here is the code which we have used in our module