hashicorp / terraform-provider-azurerm

Terraform provider for Azure Resource Manager
https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs
Mozilla Public License 2.0
4.52k stars 4.6k forks source link

Bad Request - Invalid URL during the terraform apply #21790

Open dauphinpasdroit opened 1 year ago

dauphinpasdroit commented 1 year ago

Is there an existing issue for this?

Community Note

Terraform Version

v1.4.6

AzureRM Provider Version

3.54.0

Affected Resource(s)/Data Source(s)

Azure rm

Terraform Configuration Files

terraform {
  backend "azurerm" {
  }
  required_providers {
    azurerm = {
      source = "hashicorp/azurerm"
      version = "3.54.0"
    }
}

Debug Output/Panic Output

Error: Unable to list provider registration status, it is possible that this is due to invalid credentials or the service principal does not have permission to use the Resource Manager API, Azure error: resources.ProvidersClient#List: Failure responding to request: StatusCode=400 -- Original Error: autorest/azure: error response cannot be parsed: {"\r\n\r\n\r\n
Bad Request - Invalid URL
\r\n
HTTP Error 400. The request URL is invalid.

\r\n\r\n" '\x00' '\x00'} error: invalid character '<' looking for beginning of value
│ 
│   with provider["registry.terraform.io/hashicorp/azurerm"],
│   on main.tf line 1, in provider "azurerm":
│    1: provider "azurerm" {
│

Expected Behaviour

To be working and to "connect' to the subscription.

Actual Behaviour

Plan fail with the error previsouly mentionned.

Steps to Reproduce

Just a terraform apply

Important Factoids

Works on all the subscription that I work with, except this one.

References

No response

rcskosir commented 1 year ago

@alphaxr6 Thank you for submitting this! Is the code snippet above the entire configuration file? If so, I believe you are missing a closing}. In addition, your configuration file will need the below code snippet, even if you don't have any configuration options to set:

provider "azurerm" {
  # Configuration options
}

This can be seen on the docs page when you click USE PROVIDER, in the How to use this provider code snippet. https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs

dauphinpasdroit commented 1 year ago

Hey @rcskosir

No, it's not the entire configuration file. I wanted to add the part of the provider version.

provider "azurerm" {
  # Configuration options
}

Is set as well.

Like I said in the first post. The exact same code is running perfectly when I use another subscription. My issue is with only one, and I couldn't figure out why...

dauphinpasdroit commented 1 year ago

Here are more information and code snippet:

version.tf

##################################################################################
# VERSIONS
##################################################################################

terraform {
  backend "azurerm" {
  }
  required_providers {
    azurerm = {
      source = "hashicorp/azurerm"
      version = "3.54.0"
    }
    /*
    netbox = {
      source  = "e-breuninger/netbox"
      version = "1.5.1"
    }*/
    awx = {
      source  = "nolte/awx"
      version = "0.2.2"
    }

    }
}

main.tf

provider "azurerm" {
  features {}
}

provider "azurerm" {
  skip_provider_registration = "true"
  features {}

  alias           = "common-services"
  subscription_id = var.common_services_id
}

resource "random_password" "admin_pwd" {
  length           = 16
  special          = true
  override_special = "!#$%&*()-_=+[]{}<>:?"
}

data "azurerm_resource_group" "" {
  name = var.resource_group
}

## Import Key vault informations ##
data "azurerm_key_vault" "compute_lab" {
  provider            = azurerm.common-services
  name                = var.key_vault_name
  resource_group_name = var.resource_group_keyvault
}

and the entire error message:

▼ ▼ ▼ ▼ ▼ ▼ ▼ ▼ ▼ ▼ Terraform Apply ▼ ▼ ▼ ▼ ▼ ▼ ▼ ▼ ▼ ▼
Acquiring state lock. This may take a few moments...
data.azurerm_key_vault.compute_lab: Reading...
data.azurerm_resource_group.image: Reading...
data.azurerm_shared_image.image: Reading...
data.azurerm_resource_group.image: Read complete after 0s [id=/subscriptions/((redacted))/resourceGroups/Packer]
data.azurerm_shared_image.image: Read complete after 1s [id=/subscriptions/((redacted))/resourceGroups/Packer/providers/Microsoft.Compute/galleries/cycloid/images/Windows-server-2019]
data.azurerm_key_vault.compute_lab: Read complete after 1s [id=/subscriptions/((redacted))/resourceGroups/COMPUTE-LAB-COM/providers/Microsoft.KeyVault/vaults/COMPUTE-LAB]
╷
│ Warning: Invalid index:The given key does not identify an element in this collection value.
│ 
│ 
╵
╷
│ Error: Unable to list provider registration status, it is possible that this is due to invalid credentials or the service principal does not have permission to use the Resource Manager API, Azure error: resources.ProvidersClient#List: Failure responding to request: StatusCode=400 -- Original Error: autorest/azure: error response cannot be parsed: {"\r\n\r\n\r\n
Bad Request - Invalid URL
\r\n
HTTP Error 400. The request URL is invalid.

\r\n\r\n" '\x00' '\x00'} error: invalid character '<' looking for beginning of value
│ 
│   with provider["registry.terraform.io/hashicorp/azurerm"],
│   on main.tf line 1, in provider "azurerm":
│    1: provider "azurerm" {
│ 
╵
Releasing state lock. This may take a few moments...
▲ ▲ ▲ ▲ ▲ ▲ ▲ ▲ ▲ ▲ Terraform Apply ▲ ▲ ▲ ▲ ▲ ▲ ▲ ▲ ▲ ▲
Failed To Run Terraform Apply!
2023/05/31 08:28:43 Apply Error: Failed to run Terraform command: exit status 1