Allan Xu
Allan Xu

Reputation: 9368

Terraform Azure Testing: What is the value that terratest adds?

I am going through the following video that shows how to test Terraform "azurerm" provider.

P3 - How to test infrastructure as code - Terraform/TerraTest/Golang/Azure REST API - Hands-on Demos

I am having hard time underestanding what exact value Terratest adds in the approach shown in the video.

To my simplistic view, I can easily write a relatively simple script (Bash, Python, PowerShell Core Linux , etc.) to cal Azure REST API (Azure CLI is a much simpler option) and test verift my deployed infrastructure.

Why do it need to go throough all that golang and Terratest effort that is explained in the video?

Upvotes: 1

Views: 455

Answers (2)

Christian Pearce
Christian Pearce

Reputation: 1026

There are a couple things happening here and it is best not to conflate them.

  1. What you are seeing is a range on integration testing. As the presenter indicated in the first part of the test, they validate the input matches the output from terraform. Therefore executing the REST APIs as developed by the terraform azurerm community. The presenter also indicated this is a very simply test. Which is true. They simply wanted to test it further. Or it could be there is some part of the resouce not available via output they simply wanted to validate. Which is a choice they made to satisfy their requirements.
  2. You don't need to use terratest. I used it before because it worked and I was comfortable with it. In my current role we use powershell, psake, and pester. In otherwords don't get hung up on the language or the REST call, focus on what you need to test.

For me a lot of this is, I am going to take the time to test it by hand, I might as well be organized and do it with code. It helps me quickly validate I am doing what I think I am trying to do through code. When it comes to IaC this is harder to do with mocks and unit tests. Easier to do in cloud through integration testing.

Upvotes: 1

Charles Xu
Charles Xu

Reputation: 31454

In my opinion, it depends on the different requirements. When you just need to use the REST API quickly and no other requirement, then the simplest way is best. But when you want to execute the REST API in code, here is the golang. Then this video is the example you need.

In fact, I think it's a good thing to learn the process that how does the REST API executes in the code. It makes you clearly know each step it will do. If there is something wrong, then you will know which step causes the error.

Upvotes: 0

Related Questions