Hello,
Few months ago, Terraform 0.13 became GA (announcement here).
It provides interesting changes I was waiting for, especially on modules with count
, for_each
and depends_on
. Before that, I had to code workarounds I did not like, to get this feature equivalent (mainly cascading the iteration in modules’ resources – I have an example here : search for “count
”).
But it comes with a significant change on the providers management.
After testing, reading and sweating a little bit, here is my proven upgrade path for all my Terraform 0.12 plans that have states. This is a directive approach, do, do, done. It may not fit your needs. If you need more planning, look at the documentation.
Additionally, I only develop/deploy for Azure, Kubernetes, and Helm, so other providers may have different upgrade paths.
1. Upgrade your Terraform EXE to 0.13 (current latest is 0.13.5):
Many ways to do so. In local configuration for Windows, download the x64 EXE from here: https://releases.hashicorp.com/terraform/0.13.5/terraform_0.13.5_windows_amd64.zip
and unzip the binary in one of your %path% folder.
Note:
- If you stop here and run a Terraform command, it will fail:
That is because the binaries were upgraded but the Terraform state tracks the Terraform version:
2. In your main.tf
, or the *.tf
file that has the provider azurerm {}
block, add the additional block:
terraform {
required_providers {
azurerm = {
source = “hashicorp/azurerm”
}
}
required_version = “>= 0.13”
}
3. Execute a “Terraform init”
terraform init
4. Execute a “Terraform state replace-provider”
terraform state replace-provider ‘registry.terraform.io/-/azurerm’ ‘registry.terraform.io/hashicorp/azurerm’
5. Answer yes
Done.
You are good to go with Terraform 0.13.+
Notes:
- If you use other providers:
use the same approach for provider state replacement, like these ones:
terraform state replace-provider ‘registry.terraform.io/-/azurerm’ ‘registry.terraform.io/hashicorp/azurerm’terraform state replace-provider ‘registry.terraform.io/-/azuread’ ‘registry.terraform.io/hashicorp/azuread’terraform state replace-provider ‘registry.terraform.io/-/random’ ‘registry.terraform.io/hashicorp/random’terraform state replace-provider ‘registry.terraform.io/-/kubernetes’ ‘registry.terraform.io/hashicorp/kubernetes’