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.6k stars 4.64k forks source link

Error Code="SubscriptionNotFound" after version 3.43 (3.44 and above) when using in Gov Cloud #27223

Open hboneta opened 2 months ago

hboneta commented 2 months ago

Is there an existing issue for this?

Community Note

Terraform Version

1.9.5

AzureRM Provider Version

3.44.0

Affected Resource(s)/Data Source(s)

provider

Terraform Configuration Files

terraform {
  backend "local" {}

  required_providers {
    azurerm = {
      source  = "hashicorp/azurerm"
      version = "3.44"
    }
  }
}

Debug Output/Panic Output

Planning failed. Terraform encountered an error while generating this plan.

╷
│ 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=404 -- Original Error: autorest/azure: Service returned an error. Status=404 Code="SubscriptionNotFound" Message="The subscription 'xxx' could not be found."
│
│   with provider["registry.terraform.io/hashicorp/azurerm"],
│   on provider.tf line 1, in provider "azurerm":
│    1: provider "azurerm" {

Expected Behaviour

As when in 3.43 the provider allows for processing of terraform files.

Actual Behaviour

Planning failed. Terraform encountered an error while generating this plan.

╷ │ 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=404 -- Original Error: autorest/azure: Service returned an error. Status=404 Code="SubscriptionNotFound" Message="The subscription '85f3552d-bc5e-4875-b592-4ba31f66b8ec' could not be found." │ │ with provider["registry.terraform.io/hashicorp/azurerm"], │ on provider.tf line 1, in provider "azurerm": │ 1: provider "azurerm" {

Steps to Reproduce

terraform plan or terraform apply

Important Factoids

None

References

None

neil-yechenwei commented 2 months ago

Thanks for raising this issue. Seems the error returned by service API indicates that the service principal you are using lost permission. May I ask if it still works in v3.43? Could you please try again?

gsharma-jiggzy commented 1 month ago

@hboneta I was able to use the latest by export the ARM variables export ARM_ENVIRONMENT=usgovernment eport ARM_SUBSCRIPTION_ID=......

hboneta commented 1 month ago

Thanks for raising this issue. Seems the error returned by service API indicates that the service principal you are using lost permission. May I ask if it still works in v3.43? Could you please try again?

Yes it works on 3.43. I'm still using it for my project.

hboneta commented 1 month ago

@hboneta I was able to use the latest by export the ARM variables export ARM_ENVIRONMENT=usgovernment eport ARM_SUBSCRIPTION_ID=......

Yes! thank you! This does work as a workaround. The question remains how did it regress between 3.43 and 3.44 or if by design the intent is to explicitly set up the environment to avoid other problems that would be found later in the process.