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

Subnet used by destroyed azurerm_api_management cannot be deleted #1520

Closed
torresdal opened this issue Jul 9, 2018 · 5 comments
Closed

Subnet used by destroyed azurerm_api_management cannot be deleted #1520

torresdal opened this issue Jul 9, 2018 · 5 comments

Comments

@torresdal
Copy link
Contributor

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 Version

Terraform v0.11.7

Affected Resource(s)

Terraform Configuration Files

resource "azurerm_resource_group" "west" {
  name     = "api-rg-premium-west"
  location = "West Europe"
}

resource "azurerm_virtual_network" "west" {
  name                = "vn-west"
  address_space       = ["10.254.0.0/17"]
  location            = "${azurerm_resource_group.west.location}"
  resource_group_name = "${azurerm_resource_group.west.name}"
}

resource "azurerm_subnet" "west" {
  name                 = "api-subnet-west"
  resource_group_name  = "${azurerm_resource_group.west.name}"
  virtual_network_name = "${azurerm_virtual_network.west.name}"
  address_prefix       = "10.254.1.0/24"
}

resource "azurerm_api_management" "test" {
  name                          = "api-mngmnt"
  publisher_name                = "My Company"
  publisher_email               = "[email protected]"
  vnet_subnet_id                = "${azurerm_subnet.west.id}"
  vnet_type                     = "External"

  sku {
    name = "Developer"
  }

  location            = "${azurerm_resource_group.west.location}"
  resource_group_name = "${azurerm_resource_group.west.name}"

Debug Output

https://gist.github.com/torresdal/df34f85a8288d39fcc205c45c3d2914a

Panic Output

Expected Behavior

The resource azurerm_subnet should have been successfully destroyed and not being used by azurerm_api_management anymore, since azurerm_api_management have been destroyed.

Actual Behavior

* azurerm_subnet.west: Error deleting Subnet "testsubnet1" (VN "acctest-vn1-1" / Resource Group "amtestRG1-1"): network.SubnetsClient#Delete: Failure sending request: StatusCode=0 -- Original Error: autorest/azure: Service returned an error. Status=400 Code="InUseSubnetCannotBeDeleted" Message="Subnet testsubnet1 is in use by /subscriptions/0967fd64-a807-47e1-bf05-0e55e24a68d5/providers/Microsoft.ApiManagement/service?vnetResourceGuid=4b40d13c-b439-4ea8-b898-844b4413c252&subnet=testsubnet1&api-version=2016-07-07 and cannot be deleted." Details=[]

Note: Taking into account that it takes from 30-50 minutes to create a api_management resource in Azure and only seconds to delete it, it would be safe to assume that the actual underlying Azure resources are still being deleted behind the scenes, after the Delete call to the Azure API has succeeded. It would also be natural to assume that these resources are the ones preventing azurerm_subnet to be deleted.

Steps to Reproduce

  1. terraform apply
  2. terraform destroy

References

@tombuildsstuff
Copy link
Contributor

hey @torresdal

Thanks for opening this issue / for PR #1516

Given this issue is in reference to a PR which hasn't been merged/shipped yet - I'm going to close it for the moment so that we can discuss this in #1516. The error being returned in this case is coming from the Azure API - where as you've identified the API Management instance still exists for a period of time once it's deleted; given this is a bug in the Azure SDK for Go - would you mind opening an issue on that repository where that can be fixed?

Thanks!

@torresdal
Copy link
Contributor Author

Will do!

@tharris29
Copy link

@torresdal @tombuildsstuff, this was closed but I think it should be reopened now to allow support for the vnet_type and vnet_subnet_id. Or do we have another issue raised to add this support?

@torresdal
Copy link
Contributor Author

@tharris29 Azure/azure-sdk-for-go#2199 and Azure/azure-rest-api-specs#4409

No activity or progress as far as I can see.

@ghost
Copy link

ghost commented Mar 5, 2019

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 Mar 5, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants