Error: Unsupported Terraform Core version - azure

I have a simple terraform configuration as follows.
# Terraform settings Block
terraform {
required_version = "~> 1.0.0"
required_providers {
azurerm = {
source = "hashicorp/azurerm" # https://registry.terraform.io/providers/hashicorp/azurerm/latest
version = "~> 3.0"
}
}
}
provider "azurerm" {
features { }
}
resource "azurerm_resource_group" "rg" {
name = var.resource_group_name
location = var.resource_group_location
}
When I run
terraform init
I get the following error.
╷
│ Error: Unsupported Terraform Core version
│
│ on main.tf line 3, in terraform:
│ 3: required_version = "~> 1.0.0"
│
│ This configuration does not support Terraform version 1.2.2. To proceed, either choose another supported Terraform version or update this version
│ constraint. Version constraints are normally set for good reason, so updating the constraint may lead to other errors or unexpected behavior.
╵
If the required version is set the following way, it works fine(Changed ~> to >=).
required_version = ">= 1.0.0"
Looked at this doc, but not clear what to do. Should I revert back to required_version = ">= 1.0.0"
Just wanted to ensure that lastest minor is in place. Also read somewhere that for production, the one with tilde(~) is recommended. Bit confused now.

You have already installed TF version 1.2.2, which obviously is far newer then 1.0.0. If you want to use such an old version of TF, you have download older version of terraform, and use that to run your scripts.

I had the same issue after upgrading both the terraform and the azurerm terraform provider to the latest versions (up to the date of writing this answer):
terraform {
backend "azurerm" { }
required_version = "1.2.5"
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "3.14.0"
}
}
}
I managed to fix the issue locally by using an older version of terraform (1.2.3 instead of 1.2.5), so I'm guessing the issue you experienced is similar to mine.
terraform {
backend "azurerm" { }
required_version = "1.2.3"
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "3.14.0"
}
}
}
However, when running terraform in a ubuntu 20.04 agent in Azure DevOps pipelines the exact same provider configuration, I was still getting the same error (for some weird reason - a bug maybe? - the pipeline would try to use terraform 1.2.4, when I locked it to 1.2.3) ... I was able to fix it by using the same versions with >= :
terraform {
backend "azurerm" { }
required_version = ">=1.2.3"
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = ">=3.14.0"
}
}
}

Related

Terraform init failed. Error: Failed to query available provider packages

Installed terraform & init is failing.
- Finding hashicorp/aws versions matching "~> 4.16"...
╷
│ Error: Failed to query available provider packages
│
│ Could not retrieve the list of available versions for provider hashicorp/aws: could not connect to registry.terraform.io: Failed to request discovery document: Get
│ "https://registry.terraform.io/.well-known/terraform.json": x509: “cf-registry.tf-registry-prod-use1.terraform.io” certificate is not standards compliant
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 4.16"
}
}
required_version = ">= 1.2.0"
}
provider "aws" {
region = "us-west-2"
}
resource "aws_instance" "app_server" {
ami = "ami-830c94e3"
instance_type = "t2.micro"
tags = {
Name = "ExampleAppServerInstance"
}
}
I have uninstalled and reinstalled it but still not working.
Terraform version: Terraform v1.3.7 on darwin_amd64
I was facing the same issue, even with a module that was working well previously. After discarding network issues ( curl https://registry.terraform.io/.well-known/terraform.json ), trying with different files and directories, etc. It turned out that a reboot did the trick for me.

Terraform: Failed to query available provider packages (Azapi)

I try to use the Azure/Azapi Provider within my Terraform project but after I add the provider and run terraform init, I get the following error:
Error: Failed to query available provider packages
Could not retrieve the list of available versions for provider hashicorp/azapi: provider registry registry.terraform.io does not have a provider named registry.terraform.io/hashicorp/azapi
This is how my providers.tf looks like:
terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "=3.16.0"
}
azapi = {
source = "azure/azapi"
version = "=0.4.0"
}
}
required_version = "=1.2.6"
}
provider "azurerm" {
features {}
}
provider "azapi" {
}
When I run terraform providers, I can see that the provider has a wrong registry URL within my module:
├── module.az-aca-env
│ └── provider[registry.terraform.io/hashicorp/azapi]
I would expect something like registry.terraform.io/azure/azapi.
Any ideas?
Okay, I found a workaround. I have to add a providers.tf inside my module directory (/modules/az-aca-env) with the following content:
terraform {
required_providers {
azapi = {
source = "Azure/azapi"
version = "=0.4.0"
}
}
}
After adding it, the terraform init works ✅.
You have a typo in the provider name, it is Azure/azapi as per documentation [1]:
terraform {
required_providers {
azapi = {
source = "Azure/azapi"
version = "0.4.0"
}
}
}
provider "azapi" {
# Configuration options
}
You can always see how to use the provider if you click on the big purple button in the top right-hand corner saying USE PROVIDER.
[1] https://registry.terraform.io/providers/azure/azapi/latest/docs

Using multiple provider version in terraform

Im trying to use two provider version with in terraform, though Im getting the below error
Error: Failed to query available provider packages
Could not retrieve the list of available versions for provider hashicorp/aws:
no available releases match the given constraints >= 3.71.0, 3.71.0, 4.6.0
Here is what Im trying to do. I have a terraform file, which uses multiple module. And in one module alone, I need to use aws provider version 4.6.0. On other modules, I need to stick to currently applied provider version, which is 3.71.0
Terraform version: 0.13.6
Im defining a constraint in terraform file, so "hashicorp/aws" can be anything above 3.71.0. Below is what is defined:
"aws": {
"version": ">= 3.71.0",
"assume_role": {
"role_arn": "....",
"session_name": "..."
},
terraform file calls more than 10 module, and module 0 to 9 provider config is
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "= 3.71.0"
}
}
}
and 10th module provider config is
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "= 4.6.0"
}
}
}
Anything Im missing?
Note : I have already referred this post - Multiple provider versions with Terraform, though not sure, if its technically not possible, and something Im doing it wrong
We use a separate provider block for each and every region, this is how we handle it:
provider "aws" {
region = "us-west-2"
}
provider "aws" {
alias = "east-2-provider"
region = "us-east-2"
version = "~> 4.0"
}
provider "aws" {
alias = "east-1-provider"
region = "us-east-1"
version = "~> 3.74"
}
When we are using a module we use it as below:
module "example-1" {
source = "./example"
providers = {
aws = east-1-provider
}
}
module "example-2" {
source = "./example"
providers = {
aws = east-2-provider
}
}

Failed to query available provider packages

I'm using the Powershell in the Azure Portal.
Terraform version = v1.0.3
Powershell version = 7.1.3
this is my code
provider "azurerm" {
features {}
}
resource "azure_storage_account" "lab" {
name = "newbloddystoragegroup"
resource_group_name = "TFResourcegroup"
location = "eastus"
account_tier = "Standard"
account_replication_type = "LRS"
}
resource "azure_storage_container" "lab" {
name = "blobcontainer4dev"
storage_account_name = azure.storage.account.lab.name
container_access_type = "private"
}
resource "azure_storage_blob" "lab" {
name = "TerraformdevBlob"
storage_account_name = azure_storage_account.lab.name
storage_container_name = azure_storage_container.lab.name
account_replication_type = "Block"
}
resource "azure_storage_share" "lab"{
name = "terraformdevshare"
storage_account_name = azure_storage_account.lab.name
quota = 50
}
but when I run terraform init..I get the following error
Initializing provider plugins...
- Finding latest version of hashicorp/azurerm...
- Finding latest version of hashicorp/azure...
- Installing hashicorp/azurerm v2.74.0...
- Installed hashicorp/azurerm v2.74.0 (signed by HashiCorp)
╷
│ Error: Failed to query available provider packages
│
│ Could not retrieve the list of available versions for provider hashicorp/azure: provider registry registry.terraform.io does not have a provider named registry.terraform.io/hashicorp/azure
│
│ Did you intend to use terraform-providers/azure? If so, you must specify that source address in each module which requires that provider. To see which modules are currently depending on hashicorp/azure, run the following command:
│ terraform providers
I've run this..
terraform providers
Providers required by configuration:
.
├── provider[registry.terraform.io/hashicorp/azure]
└── provider[registry.terraform.io/hashicorp/azurerm]
but I don't know what I have to change
What I've tried ...
I've put
provider "azurerm" {
features {}
}
into its own provider.tf file...but I'm still getting the error
I've tried to put
provider "registry.terraform.io/hashicorp/azurerm" {
features {}
}
...but it turns out that that is unacceptable syntax
I've tried replacing
provider "azurerm" {
features {}
}
with
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "2.74.0"
}
..but that didn't work either
..any help is gratefully received....just guide me ..you don't necessarily need to tell me the answer
I believe you have gotten this error because you used azure_* resources
If you open Azure Provider documentation you will figure out that all resources names start with azurerm_* prefix.

Terraform Opsgenie string value required

I am simplying trying to terrafomr init a provider for opsgenie.
My version of terraform is:
Terraform v0.12.6
Your version of Terraform is out of date! The latest version
is 0.14.10. You can update by downloading from www.terraform.io/downloads.html
and my provider is:
terraform {
# https://www.terraform.io/docs/configuration/terraform.html#specifying-a-required-terraform-version
required_version = "~> 0.12"
# https://www.terraform.io/docs/configuration/provider-requirements.html
required_providers {
opsgenie = {
source = "opsgenie/opsgenie",
version = "~> 0"
}
}
The error I get is:
There are some problems with the configuration, described 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 provider.tf line 16, in terraform:
16: opsgenie = {
17: source = "opsgenie/opsgenie"
18: version = "0.6.3"
19: }
A string value is required for opsgenie.
Your TF is too old, and your syntax is new. From docs:
The name = { source, version } syntax for required_providers was added in Terraform v0.13. Previous versions of Terraform used a version constraint string instead of an object (like mycloud = "~> 1.0"), and had no way to specify provider source addresses. If you want to write a module that works with both Terraform v0.12 and v0.13, see v0.12-Compatible Provider Requirements below.
You can try old syntax (or upgrade your TF):
terraform {
# https://www.terraform.io/docs/configuration/terraform.html#specifying-a-required-terraform-version
required_version = "~> 0.12"
# https://www.terraform.io/docs/configuration/provider-requirements.html
required_providers {
opsgenie = "~> 0"
}

Resources