New Provider config when Upgrading Terraform from 0.12 to 0.13/0.14

IT et al.
2 min readApr 12, 2021

HashiCorp is working hard in advancing terraform and so far I don’t have a thing to complain about it. Recently I had to upgrade my terraform tasks to 0.14 as I was using a mix of 0.12 and 0.13.

I wont go into the weeds of my migration path but so that we are clear, you have to upgrade one version at the time. Most of the upgrade concerns and the neat features will be well described in the following URL: https://www.terraform.io/upgrade-guides/index.html

Previously my main.tf was set like this:

terraform {
backend "azurerm" {}
}
provider "azurerm" {
version = "=2.39.0"
features {}
subscription_id = var.subscription
client_id = var.client-id
client_secret = var.client-secret
tenant_id = var.tenant
}
resource "azurerm_resource_group" "k8s" {
...
}

Still, I wasn’t so sure on how to correctly change the provider setup due to the Explicit Provider Source Locations change in 0.13. I have a backend block set underneath my Terraform block and I didn't know how that would play in the new configuration.

It is important to highlight that the previous configuration should work still for tf 0.13 and 0.14 however, it was deprecated (and you will be get warnings such as “version constraints inside provider configuration blocks are deprecated”) thus would be a good call to configure the provider correctly. My final configuration ended up like this:

terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "=2.54.0"
}
}
backend "azurerm" {}
}
provider "azurerm" {
features {}
subscription_id = var.subscription
client_id = var.client-id
client_secret = var.client-secret
tenant_id = var.tenant
}

1) The provider version was removed from the provider block and added into the 2) newly created block required_providers which is underneath terraform. The backend block stayed in the same place as it was before.

Quite a simple change yet having two blocks with close names kinda confused me at the very beginning as I didn't know how the changes would somehow merge.

Cheers,

Nilson.

--

--

IT et al.

DevOps guy from the tropics currently living in Ohio. Coffee, wine, cigars, photography, traveling & IT.