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 Error deleting App Service Plan StatusCode=409 Server farm [asp] cannot be deleted because it has web app(s) [azure-function] assigned to it #8241

Closed
stianbearingpoint opened this issue Aug 25, 2020 · 5 comments

Comments

@stianbearingpoint
Copy link

stianbearingpoint commented Aug 25, 2020

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 v0.12.26
Azurerm 2.24.0

Affected Resource(s)

  • azurerm_app_service_plan
  • azurerm_function_app

Terraform Configuration Files

# Copy-paste your Terraform configurations here - for large Terraform configs,
# please use a service like Dropbox and share a link to the ZIP file. For
# security, you can also encrypt the files using our GPG public key: https://keybase.io/hashicorp
Provider:
# Configure the Microsoft Azure
provider "azurerm" {
  version = "~> 2.24.0"

  use_msi = true

  features {}
  client_id       = var.client_id
  client_secret   = var.client_secret
  tenant_id       = var.tenant_id
  subscription_id = var.subscription_id
}

provider "azuread" {
  version         = "~> 0.3"
  subscription_id = var.subscription_id
  client_id       = var.client_id
  client_secret   = var.client_secret
  tenant_id       = var.tenant_id
}

Debug Output

https://gist.github.com/stianbearingpoint/19b4daff45b28d45a7ba9946a0c5f46f

Panic Output

Expected Behavior

Apply build should have completed ok
It does work fine if I manually delete the function and its service plan using the Azure Portal

Actual Behavior

It fails, here is a summary of the relevant part of the DEBUG log:

2020-08-25T06:31:23.256Z [DEBUG] plugin.terraform-provider-azurerm_v2.24.0_x5: {"Code":"Conflict","Message":"Server farm 'asp-staging' cannot be deleted because it has web app(s) function-staging assigned to it.","Target":null,"Details":[{"Message":"Server farm 'asp-staging' cannot be deleted because it has web app(s) function-staging assigned to it."},{"Code":"Conflict"},{"ErrorEntity":{"ExtendedCode":"11003","MessageTemplate":"Server farm '{0}' cannot be deleted because it has web app(s) {1} assigned to it.","Parameters":["asp-staging","function-staging"],"Code":"Conflict","Message":"Server farm 'asp-staging' cannot be deleted because it has web app(s) function-staging assigned to it."}}],"Innererror":null}
...
Error: Error deleting App Service Plan "asp-staging" (Resource Group "my-resource-group"): web.AppServicePlansClient#Delete: Failure sending request: StatusCode=409 -- Original Error: autorest/azure: Service returned an error. Status=<nil> <nil>

Steps to Reproduce

  1. Create the following resources
resource "azurerm_app_service_plan" "asp" {
    name = "asp-${var.environment}"
    resource_group_name      = var.rg_name
    location                 = var.location
    kind = "FunctionApp"
    reserved            = true
    sku {
        tier = "ElasticPremium"
        size = "EP1"
    }
}

resource "azurerm_function_app" "function" {
    name = "function-${var.environment}"
    resource_group_name= var.rg_name
    location= var.location
    app_service_plan_id= azurerm_app_service_plan.asp.id
    storage_connection_string=azurerm_storage_account.storage.primary_connection_string
    os_type = "linux"


    site_config {
      linux_fx_version = "DOCKER|${data.azurerm_container_registry.acr.login_server}/${var.image_name}:latest"
    }

    identity {
      type = "SystemAssigned"
    }

    depends_on = [azurerm_app_service_plan.asp]


    app_settings              = {
    #Lots of variables, but irrelevant for this issue I assume?
    }
    version = "~2"

}
  1. Do any change and try to reapply using Terraform

Important Factoids

References

I have an open Stackoverflow post, it was there they suggested to open bug report here:
https://stackoverflow.com/questions/63573535/terraform-error-deleting-app-service-plan-statuscode-409-server-farm-asp-canno?noredirect=1#comment112418835_63573535

  • #0000
@tombuildsstuff
Copy link
Member

hi @stianbearingpoint

Thanks for opening this issue.

This forum is intended to be used for feature enhancements and bugs in the Azure Provider - so that we can keep this forum focused on that we instead ask that broader questions are raised using one of the Community Resources. As such I'm going to close this issue for the moment, but I believe you should be able to get an answer for this using one of the Community Resources.

Thanks!

@stianbearingpoint
Copy link
Author

Thanks Tom,
I am a bit confused. Are you saying this is not a bug in the provider? Or that I should post it somewhere else?

@tombuildsstuff
Copy link
Member

@stianbearingpoint there's a missing dependency between these two resources which is why this is happening, unfortunately we're unable to assist with every configuration issue which is why we ask users open these on the forum (or another community location) instead - however adding a dependency between the two should resolve this :)

@stianbearingpoint
Copy link
Author

stianbearingpoint commented Aug 25, 2020

Thanks again for your help Tom!
I assumed the depency was implied. Should dependency be mentioned here https://www.terraform.io/docs/providers/azurerm/d/app_service_plan.html
or here https://www.terraform.io/docs/providers/azurerm/r/function_app.html then? 😄
I now added the following in the function definition:

depends_on = [azurerm_app_service_plan.asp]

I still get the same error, I even tried with a null_resource with a sleep of 30 sec between them. Have I missunderstood what you meant by adding dependency?

@ghost
Copy link

ghost commented Sep 24, 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 👉 hashibot-feedback@hashicorp.com. Thanks!

@ghost ghost locked and limited conversation to collaborators Sep 24, 2020
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

2 participants