Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

terraform destroy fails with azurerm_management_group containing subscriptions #3450

Closed
richeney opened this issue May 15, 2019 · 3 comments · Fixed by #7216
Closed

terraform destroy fails with azurerm_management_group containing subscriptions #3450

richeney opened this issue May 15, 2019 · 3 comments · Fixed by #7216

Comments

@richeney
Copy link
Contributor

Running terraform destroy on a management group containing a subscription will error. The REST call is malformed for disassociating the child subscriptions from the management group being deleted.

Example REST call from TF_LOG=debug stderr output:

DELETE /providers/Microsoft.Management/managementGroups/6f117285-e8e7-4c4c-8286-af5b2280027d/subscriptions/%2Fsubscriptions%2F2d31be49-d959-4415-bb65-8aec2c90ba62?api-version=2018-03-01-preview

It should be:

DELETE /providers/Microsoft.Management/managementGroups/6f117285-e8e7-4c4c-8286-af5b2280027d/subscriptions/2d31be49-d959-4415-bb65-8aec2c90ba62?api-version=2018-03-01-preview 

My Go is poor, but I think that line 234 of azurerm\resource_arm_management_group.go should change from:

subscriptionId := *v.ID

to

subscriptionId := *v.NAME

as it needs to set it to the subscription GUID rather than the full ID.

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Terraform (and AzureRM Provider) Version

terraform -v:

Terraform v0.12.0-beta2
+ provider.azurerm v1.27.1

Affected Resource(s)

  • azurerm_management_group

Terraform Configuration Files

data "azurerm_subscription" "current" {}

resource "azurerm_management_group" "deleteme" {
  display_name    = "DeleteMe"
  subscription_ids = [
    "${data.azurerm_subscription.current.subscription_id}"
  ]
} 

Debug Output

https://gist.github.com/richeney/8be7107dffd90b14f1fc0c650b4f431e

Note that CTRL+C was pressed after 30 seconds or so.

Panic Output

Expected Behavior

Subscription moved to Tenant Root Group.

Actual Behavior

REST call errors, terraform destroy times out.

Steps to Reproduce

  1. terraform apply -auto-approve
  2. TF_LOG=debug terraform destroy -auto-approve 2>debug

Important Factoids

References

  • #0000
@larsmaes
Copy link

larsmaes commented Jun 4, 2020

same problem here. Cannot delete mangement group with subs in it

@ghost
Copy link

ghost commented Jun 11, 2020

This has been released in version 2.14.0 of the provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading. As an example:

provider "azurerm" {
    version = "~> 2.14.0"
}
# ... other configuration ...

@ghost
Copy link

ghost commented Jul 5, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 [email protected]. Thanks!

@ghost ghost locked and limited conversation to collaborators Jul 5, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
3 participants