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
Related
I am new to terraform and as I extracted one of the resources into a module I got this:
Error: Inconsistent dependency lock file
│
│ The following dependency selections recorded in the lock file are inconsistent with the current
│ configuration:
│ - provider registry.terraform.io/hashicorp/heroku: required by this configuration but no version is selected
│
│ To update the locked dependency selections to match a changed configuration, run:
│ terraform init -upgrade
How I did?
First I had this:
provider "heroku" {}
resource "heroku_app" "example" {
name = "learn-terraform-heroku-ob"
region = "us"
}
resource "heroku_addon" "redis" {
app = heroku_app.example.id
plan = "rediscloud:30"
}
after that terraform init was runing without error also terraform plan was successfull.
Then I extracted the redis resource declaration into a module:
provider "heroku" {}
resource "heroku_app" "example" {
name = "learn-terraform-heroku-ob"
region = "us"
}
module "key-value-store" {
source = "./modules/key-value-store"
app = heroku_app.example.id
plan = "30"
}
And the content of modules/key-value-store/main.tf is this:
terraform {
required_providers {
mycloud = {
source = "heroku/heroku"
version = "~> 4.6"
}
}
}
resource "heroku_addon" "redis" {
app = var.app
plan = "rediscloud:${var.plan}"
}
terraform get went well. but terraform plan showed me the above error!
For this code to work, you have to have the required_providers blocks in both the root and child modules. So, the following needs to happen:
Add the required_providers block to the root module (this is what you have already)
Add the required_providers block to the child module and name it properly (currently you have set it to mycloud, and provider "heroku" {} block is missing)
The code that needs to be added in the root module is:
terraform {
required_providers {
heroku = {
source = "heroku/heroku"
version = "~> 4.6"
}
}
}
provider "heroku" {}
resource "heroku_app" "example" {
name = "learn-terraform-heroku-ob"
region = "us"
}
module "key-value-store" {
source = "./modules/key-value-store"
app = heroku_app.example.id
plan = "30"
}
In the child module (i.e., ./modules/key-value-store) the following needs to be present:
terraform {
required_providers {
heroku = { ### not mycloud
source = "heroku/heroku"
version = "~> 4.6"
}
}
}
provider "heroku" {} ### this was missing as well
resource "heroku_addon" "redis" {
app = var.app
plan = "rediscloud:${var.plan}"
}
This stopped working when the second resource was moved to the module as Heroku is not an official Terraform provider hence the provider settings are not propagated to the modules. For the unofficial providers (e.g., marked with verified), corresponding blocks of required_providers and provider <name> {} have to be defined. Also, make sure to remove the .terraform directory and re-run terraform init.
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"
}
}
}
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
}
}
I am following this guide https://github.com/hashicorp/terraform/blob/v0.13/website/docs/configuration/modules.html.md#passing-providers-explicitly
This is a brand new Terraform project ie no resources and an empty state file! The version of terraform is Terraform v0.14.5.
In the calling module I have my providers set up as follows
terraform {
backend "azurerm" {
}
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = ">= 2.68.0"
}
}
}
provider "azurerm" {
alias = "lz"
subscription_id = "xxx-xxx-xxx-xxx"
features {}
}
provider "azurerm" {
alias = "prd"
subscription_id = "xxx-xxx-xxx-xxx"
features {}
}
And I am calling modules passing multiple providers like this
module "prod" {
source = "../../../Terraform/modules/LandingZone"
providers = {
azurerm.lz = azurerm.lz
azurerm.prd = azurerm.prd
}
}
In the called module I have this in the providers.tf
terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = ">= 2.68.0"
}
}
backend "azurerm" {
}
}
provider "azurerm" {
alias = "lz"
features{}
}
provider "azurerm" {
alias = "prd"
features{}
}
Up to this point init and plan works fine. However when I try to create resources like this
resource "azurerm_resource_group" "this" {
provider= azurerm.lz
for_each = var.rg_names
name = each.value
location = "Australia Southeast"
}
I get this error message
Error: Provider configuration not present
To work with module.trn.module.rg.azurerm_resource_group.this its original
provider configuration at
module.trn.module.rg.provider["registry.terraform.io/hashicorp/azurerm"].lz is
required, but it has been removed. This occurs when a provider configuration
is removed while objects created by that provider still exist in the state.
Re-add the provider configuration to destroy
module.trn.module.rg.azurerm_resource_group.this, after which you can remove
the provider configuration again.
From the guide you have linked,
A proxy configuration block is one that contains only the alias argument.
Your provider blocks in your module have more than just the alias argument, so they are probably not being set up as proxy provider configurations. Try removing the features{} part from the provider blocks inside your module.
Referring to this guide you should declare configuration_aliases inside terraform block for required providers. You can try this also.
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 {}
}