Skip to content

Commit

Permalink
azurerm_management_group - fix issue with child subscription dissoc…
Browse files Browse the repository at this point in the history
…iation (#28228)

* fix mg deletion

* add test
  • Loading branch information
teowa authored Dec 11, 2024
1 parent 4153c30 commit a5e4f2f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -321,16 +321,15 @@ func resourceManagementGroupDelete(d *pluginsdk.ResourceData, meta interface{})
continue
}

subscriptionId, err := managementgroups.ParseSubscriptionID(*v.Id)
subscriptionId, err := commonids.ParseSubscriptionID(*v.Id)
if err != nil {
return fmt.Errorf("unable to parse child Subscription ID %+v", err)
}
if subscriptionId == nil {
continue
}
managementGroupSubscriptionId := managementgroups.NewSubscriptionID(id.GroupId, subscriptionId.SubscriptionId)

log.Printf("[DEBUG] De-associating Subscription %q from Management Group %q..", subscriptionId, id.GroupId)
// NOTE: whilst this says `Delete` it's actually `Deassociate` - which is /really/ helpful
deleteResp, err := client.SubscriptionsDelete(ctx, *subscriptionId, managementgroups.SubscriptionsDeleteOperationOptions{
deleteResp, err := client.SubscriptionsDelete(ctx, managementGroupSubscriptionId, managementgroups.SubscriptionsDeleteOperationOptions{
CacheControl: &managementGroupCacheControl,
})
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,13 @@ func TestAccManagementGroup_withSubscriptions(t *testing.T) {
check.That(data.ResourceName).Key("subscription_ids.#").HasValue("0"),
),
},
{
Config: r.withSubscriptions(subscriptionID),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("subscription_ids.#").HasValue("1"),
),
},
})
}

Expand Down

0 comments on commit a5e4f2f

Please sign in to comment.