Terraform init fails on Azure Devops build pipeline

I am trying to build terraform template with Azure devops pipeline. But the step init is failing with an error like below

The Terraform configuration must be valid before initialization so that
Terraform can determine which modules and providers need to be installed.

Error: Invalid version constraint

  on main.tf line 4, in terraform:
   4:     azurerm = {
   5:       source  = "hashicorp/azurerm"
   6:       version = "=2.52.0"
   7:     }

A string value is required for azurerm.

##[error]Error: The process 'C:\hostedtoolcache\windows\terraform\0.12.3\x64\terraform.exe' failed with exit code 1
Finishing: Terraform : Init

Any help would be appreciated. Thanks in advance.

Hello @mahant.desai,

The error you see is caused because you have a very old version of terraform which cannot process the azurerm source block in required_providers. Provider sources were not supported in v0.12, but later releases are able to return an error indicating the incompatibility. If you are unable to upgrade past 0.12 at the moment, you should at least be using v0.12.31.

In order to use this configuration with 0.12, assign the version string directly to azurerm

 terraform {
  required_providers {
    azurerm = "2.52.0"
1 Like