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.52k stars 4.6k forks source link

Support for 'IgnoreResourceCheck' when cancelling a subscription #12264

Open cktwo opened 3 years ago

cktwo commented 3 years ago

Community Note

Description

When deploying a subscription with resources for testing purposes and trying to cancel said subscription after deleting all resources, from time to time Azure seems to still find some resources (that aren't there anymore). In the Azure Portal exists a 'force'/'Ignore resource' option which will cancel the subscription immediately.

Right now the cancellation times out after 30 minutes if those 'ghost' resources are still found. A couple hours or sometimes even a day later the subscription can be cancelled.

New or Affected Resource(s)

Potential Terraform Configuration

A new flag 'ignore_resource_check = true|false' would be introduced, propably defaulting to 'false'. If the flag 'ignore_resource_check' is set to true the Api call would use the 'IgnoreResourceCheck', otherwise it would not.

data "azurerm_billing_enrollment_account_scope" "example" {
  billing_account_name    = "1234567890"
  enrollment_account_name = "0123456"
}

resource "azurerm_subscription" "example" {
  subscription_name     = "My Example EA Subscription"
  billing_scope_id      = data.azurerm_billing_enrollment_account_scope.example.id
  ignore_resource_check = true|false
}

References

The flag is not documented but it exists: https://github.com/Azure/azure-rest-api-specs/issues/9042

The Azure Portal performs this exact call when cancelling a subscription with existing resources, except it uses the old '2019-03-01-preview" Api. I tested the call with the current Api which works just fine: https://management.azure.com/subscriptions//providers/Microsoft.Subscription/cancel?IgnoreResourceCheck=true&api-version=2020-09-01

chris@cktwo:~$ az rest --method POST --url "https://management.azure.com/subscriptions/<SUBSCRIPTION_ID>/providers/Microsoft.Subscription/cancel?IgnoreResourceCheck=true&api-version=2020-09-01"
{
  "subscriptionId": "<SUBSCRIPTION_ID>"
}
KungWaz commented 1 week ago

@tombuildsstuff How do I use this workaround you linked here? I can only find the prevent_cancellation_on_destroy feature flag for the subscription.