microsoft / azure-pipelines-terraform

Azure Pipelines tasks for installing Terraform and running Terraform commands in a build or release pipeline.
MIT License
106 stars 66 forks source link

"Provider configuration not present" with azurerm when using a provider alias #96

Open marco-svitol opened 2 years ago

marco-svitol commented 2 years ago

With TerraformTaskVx@x if I use an alias provider such as:

provider "azurerm" {
  subscription_id = var.subscriptionId
  tenant_id = var.tenantId
  features {}
}

provider "azurerm" {
  alias = "sharedsubscription"
  subscription_id = var.sharedSubscriptionId
  tenant_id = var.sharedTenantId
  features {}
}

resource "azurerm_virtual_network_peering" "spoke2nonprod_peering" {
  provider = azurerm.sharedsubscription
  name                      = "spoke2nonprod_peering"
  resource_group_name       = data.azurerm_virtual_network.spoke_vnet.resource_group_name
  virtual_network_name      = data.azurerm_virtual_network.spoke_vnet.name
  remote_virtual_network_id = azurerm_virtual_network.nonprod_vnet.id
}

I always get the error message when running the pipeline in AzureDevOps:

│ Error: Provider configuration not present │ │ To work with azurerm_virtual_network_peering.spoke2nonprod_peering (orphan) │ its original provider configuration at │ provider["registry.terraform.io/hashicorp/azurerm"].sharedsubscription 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 │ azurerm_virtual_network_peering.spoke2nonprod_peering (orphan), after which │ you can remove the provider configuration again. ╵

[error]Error: TerraformPlanFailed 1

The same terraform plan works fine if executed locally:

image

AminTi commented 2 years ago

Thanks for reporting, we'll dig into this.

mericstam commented 1 year ago

Is your SPN configured to have access to both subscriptions?

marco-svitol commented 1 year ago

Yes, just for testing I am using the alias provider that points to the same subscription as the default provider.