terraform test locking in providers for your test

 Maintaining a repository of terraform modules can be challenging at times and we cannot expect all our team to migrate over to azurerm 4.2 for example. 

In order to ensure that our test would continue to work (terraform test will use the latest version of the azurerm by default), we can use the following approach to lock down azurerm providers for your tests. This is applicable to other providers too.


We have the following folder setup. There's a setup folder under tests folders. Then in the terraform test file called default.tftest.hcl, we have the following code to references our provider. 


Referencing our azurerm providers 3.0 from test file. 

# setup specific test
run "setup_tests" {
  module {
    source = "./tests/setup"
  }
}


And finally in our /test/setup/main.tf we have the following contents

terraform {
  required_providers {
    azurerm = {
      source  = "hashicorp/azurerm"
      version = "~> 3.0"
    }
  }
}


Comments

Popular posts from this blog

The specified initialization vector (IV) does not match the block size for this algorithm