Terraform Warning: “Version constraints inside provider configuration blocks are deprecated” fix

A quick blog post on how to resolve the Terraform warning Warning: Version constraints inside provider configuration blocks are deprecated within your Terraform configuration. The fix below is in relation to azurerm provider, but similar fix can be used for other providers.

Using Terraform version > 0.13, you will see this warning with similar output below

│   on providers.tf line 2, in provider "azurerm":
│    2:   version = "3.44.1"
│ 
│ Terraform 0.13 and earlier allowed provider version constraints inside the provider configuration block, but that is now deprecated and will be removed in a future version of Terraform. To silence this
│ warning, move the provider version constraint into the required_providers block.

Current provider version is referenced below

provider "azurerm" {
  version = "3.44.1"
  features {}
}

The fix

Moving the required provider version to a required_providers block

terraform {
  backend "local" {
  }

  required_providers {
    azurerm = {
      source  = "hashicorp/azurerm"
      version = "3.44.1"
    }
  }

}

Please note, you will still need the provider reference as below

provider "azurerm" {
  features {}
}

If you don’t include the provider reference above, your Terraform will error with:

│ Error: Insufficient features blocks
│ 
│   on <empty> line 0:
│   (source code not available)
│ 
│ At least 1 "features" blocks are required.

Full example of updated providers.tf

terraform {
  backend "local" {
  }

  required_providers {
    azurerm = {
      source  = "hashicorp/azurerm"
      version = "3.44.1"
    }
  }

}

provider "azurerm" {
  features {}
}

Thank you for reading & hopefully this blog post has assisted you with the above warning.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s