microsoft / azure-pipelines-terraform

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

Error when planning Terraform configuration with Management Group scope #232

Open JoelCanteroGCO opened 1 month ago

JoelCanteroGCO commented 1 month ago

I'm encountering an issue when running a Terraform pipeline in Azure DevOps with a service connection that has a Management Group scope. The error message indicates that Terraform is unable to determine the subscription ID, which seems to be an issue when using Management Group scope.

Terraform Configuration:

provider "azurerm" {
  alias = "azurerm"
  features {
    resource_group {
      prevent_deletion_if_contains_resources = false
    }
  }
}

Error Message:

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

╷
│ Error: building account: unable to configure ResourceManagerAccount: subscription ID could not be determined and was not specified
│
│   with provider["registry.terraform.io/hashicorp/azurerm"].azurerm,
│   on providers.tf line 25, in provider "azurerm":
│   25: provider "azurerm" {
│
╵

Details:

Terraform Version: 1.9.14

Expected Behavior:

Terraform should be able to generate the plan successfully without errors related to subscription ID, given that the scope is set at the Management Group level.

Additional Context:

Possible Solution:

paulmccrady commented 3 weeks ago

I'm getting the same issue now. Is there chance of an update ?

mericstam commented 3 weeks ago

Hi, the task does not currently support Service Connection configured with Management Group scope as that type does not populate subscription ID. To solve this we would need to an option to supply the subscription id manually.

paulmcclbg commented 3 weeks ago

OK, well for myself, this was working fine up to 14/08/2024 then started failing 15/08/2024. Was there a change that can be attributed to the failure since 15/08/2024? Also, what alternatives are there? TIA.

paulmcclbg commented 3 weeks ago

So I managed to fix this with the help of a colleague by adding a subscription_id = xxx to the azurerm provider block.

mericstam commented 3 weeks ago

That's great! thanks for updating the issue.