Terraform Opsgenie string value required - terraform

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"
}

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

Error: Unsupported Terraform Core version

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"
}
}
}

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
}
}

Unable to create azurerm_cosmosdb_sql_container with indexing_policy block

According to the documentation on Terraform.io for azurerm_cosmosdb_sql_container, it says I can include an indexing_policy block. However, when I run terraform plan I get errors:
Error: Unsupported block type
on main.tf line 912, in resource "azurerm_cosmosdb_sql_container"
"AccountActivity": 912: indexing_policy {
Blocks of type "indexing_policy" are not expected here.
main.tf
resource "azurerm_cosmosdb_sql_container" "AccountActivity" {
name = "AccountActivity"
resource_group_name = azurerm_resource_group.backendResourceGroup.name
account_name = azurerm_cosmosdb_account.AzureCosmosAccount.name
database_name = azurerm_cosmosdb_sql_database.AzureCosmosDbCache.name
default_ttl = 2592000
throughput = 2500
indexing_policy {
indexing_mode = "Consistent"
included_path {
path = "/*"
}
excluded_path {
path = "/\"_etag\"/?"
}
}
}
Here is my terraform version output:
terraform version
Terraform v0.13.4
+ provider registry.terraform.io/-/azurerm v2.30.0
+ provider registry.terraform.io/hashicorp/azurerm v2.20.0
+ provider registry.terraform.io/hashicorp/random v2.3.0
After searching GitHub, I finally found that support for the indexing_policy block was added in this commit 26 days ago. The documentation doesn't mention this, nor does the release notes for azurerm v2.31.1. After updating my main.tf file with the latest version for azurerm and running terraform init the terraform plan command worked without issue.
provider "azurerm" {
version = "~>2.31.1"
features {}
}

Resources