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.54k stars 4.61k forks source link

azurerm_function_app_function not destroying #18293

Open mgw6 opened 2 years ago

mgw6 commented 2 years ago

Is there an existing issue for this?

Community Note

Terraform Version

1.2.8

AzureRM Provider Version

3.21.1

Affected Resource(s)/Data Source(s)

azurerm_function_app_function

Terraform Configuration Files

terraform {
  required_providers {
    azurerm = {
      source  = "hashicorp/azurerm"
      version = "3.21.1"
    }
  }
  required_version = ">= 0.15"
}

provider "azurerm" {
  features {}
}

# Creates a resouce group
resource "azurerm_resource_group" "main" {
  name     = "mgw-rg-eastus"
  location = "eastus"
}

# Requirements for storage
resource "azurerm_storage_account" "main" {
  name                     = "mgw6az6storage"
  resource_group_name      = azurerm_resource_group.main.name
  location                 = azurerm_resource_group.main.location
  account_tier             = "Standard"
  account_replication_type = "LRS"
  # How the data is copied (zones, regions etc. In this case it is Locally Redundant Storage)
}

# Requirements for Azure Function App
# Prioritize getting storage > event grid first
resource "azurerm_application_insights" "main" {
  name                = "mgw-application-insights"
  location            = azurerm_resource_group.main.location
  resource_group_name = azurerm_resource_group.main.name
  application_type    = "other"
}

resource "azurerm_service_plan" "main" {
  name                = "mgw-app-service-plan"
  resource_group_name = azurerm_resource_group.main.name
  location            = azurerm_resource_group.main.location
  os_type             = "Linux"
  sku_name            = "Y1"
}

resource "azurerm_linux_function_app" "main" {
  name                = "mgw-linux-function-app"
  resource_group_name = azurerm_resource_group.main.name
  location            = azurerm_resource_group.main.location

  storage_account_name       = azurerm_storage_account.main.name
  storage_account_access_key = azurerm_storage_account.main.primary_access_key
  service_plan_id            = azurerm_service_plan.main.id

  site_config {}
}

resource "azurerm_function_app_function" "main" {
  name            = "mgw-function-app-function"
  function_app_id = azurerm_linux_function_app.main.id
  language        = "Python"

  test_data = jsonencode({
    "name" = "Azure"
  })

  file {
    name    = "hello.py"
    content = file("hello.py")
  }

  config_json = jsonencode({
    "bindings" = [
      {
        "authLevel" = "function"
        "direction" = "in"
        "name"      = "req"
        "type"      = "httpTrigger"
        "methods" = [
          "get",
          "post",
        ]
      },
      {
        "direction" = "out"
        "name"      = "$return"
        "type"      = "http"
      },
    ]
  })
}

Debug Output/Panic Output

deleting Function App Function: (Function Name "mgw-function-app-function" / Site Name "mgw-linux-function-app" / Resource    
│ Group "mgw-rg-eastus"): web.AppsClient#DeleteFunction: Failure responding to request: StatusCode=404 -- Original Error:       
│ autorest/azure: Service returned an error. Status=404 Code="NotFound" Message="Error deleting function."

Expected Behaviour

The Function App Function should have been destroyed.

Actual Behaviour

An error is thrown sayin that the function app cannot be found. This doesn't make sense to me as plan runs without a hitch.

Steps to Reproduce

terraform apply terraform destroy

Important Factoids

No response

References

No response

xiaxyi commented 2 years ago

Thanks @mgw6 for raising this issue, can you share the detailed steps with me? Are you suggesting that the function mgw-function-app-function was deleted already before you run the tf apply, so the function should be created again?

mgw6 commented 2 years ago

Hi @xiaxyi, the detailed steps are that I run terraform apply and terraform destroy. The function app is created on the apply. When I run terraform destroy, the mgw-function-app-function is found in the plan, which is expected. However after planning when Terraform goes to delete mgw-function-app-function, I receive that error message and the mgw-function-app-function remains. At this point it should be deleted. I can go into the console, and find mgw-function-app-function remains.

This also becomes an issue anytime another apply is run that would require the function_app_function to be replaced, since the original one cannot be destroyed.

stuikomma commented 2 years ago

Hi, I have been experiencing the same issue over the past couple of days.

A change to my azurerm_function_app_function made TF try to recreate the function . However, deleting the function failed with the same error that @mgw6 got. I then tried to work around this issue by manually deleting the function via the Azure Portal UI. There, I also got an error along the same lines: "Not found". After this error, the function was deleted anyways.

I think this might indicate a bug in Azure instead of this TF provider.

@mgw6 Can you delete the function manually?

Terraform Version

1.2.8

AzureRM Provider Version

3.23.0

mgw6 commented 2 years ago

Hi @stuikomma

Yes I am able to delete the function app manually. It works as a short term fix but long term defeats the purpose of Terraform.

Re: Azure bug vs TF bug, it appears that tf finds everything during the plan just fine, its the when the apply is authorized that the issue arises. I'm not sure how TF works under the hood, but based on our workaround I wonder what would happen if TF didn't try destroying the function app function, and just went right to destroying the function app? Although that would cause issues if there were multiple functions running on one app.

xiaxyi commented 2 years ago

Thanks @mgw6 , it seems a service bug to me, have you tried rest api to delete the functions?

mgw6 commented 2 years ago

Hey @xiaxyi

No, I have not. If you can provide me with more information I can try it.

When you say service bug, do you mean Azure service?

xiaxyi commented 2 years ago

yes, Terraform calls the deletion via GO SDK which based on rest api.

Can you let me know if there is any change to the file?

file {
    name    = "hello.py"
    content = file("hello.py")
  }

as for the api part, you can this docs to delete the function from rest api

xiaxyi commented 2 years ago

@mgw6 I tried the issue from my side and I find the deletion issue may relates to it's parent function app settings.

I noticed the site_config remains empty in your TF config, can you try specifying a detailed stack such as below and see if you are able to delete the function?


  site_config {
    application_stack {
      python_version = 3.7
    }
  }
mgw6 commented 2 years ago

Hi @xiaxyi,

The first thing I did was try the API. Thank you for sending that link. It was super helpful and I was able to use the "try it" button. I did that and got this:

HTTP:

cache-control: no-cache
content-length: 66
content-type: application/json
date: Fri, 23 Sep 2022 21:17:53 GMT
expires: -1
pragma: no-cache
server: Microsoft-IIS/10.0
strict-transport-security: max-age=31536000; includeSubDomains
x-aspnet-version: 4.0.30319
x-ms-correlation-request-id: fdba14a1-669f-4dc2-8f10-c6ba4d452bb3
x-ms-ratelimit-remaining-subscription-deletes: 14999
x-ms-request-id: 4f5678c5-33bd-4f28-88cf-05736aa0727a
x-ms-routing-request-id: SOUTHCENTRALUS:20220923T211753Z:fdba14a1-669f-4dc2-8f10-c6ba4d452bb3
x-powered-by: ASP.NET

JSON:

{"error":{"code":"NotFound","message":"Error deleting function."}}

I'm not sure what you mean by the file changing. The file is the same on my local machine. If I try to view the file on the Azure Portal, then it says I can't view it because it was edited externally.

Lastly, I added the site_config block as shown below. I noticed that the documentation for the [azurerm_function_app] (https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/windows_function_app#application_stack) doesn't mention a python_version argument. The Terraform apply ran fine, however when I ran the terraform destroy I got the same result.

resource "azurerm_linux_function_app" "main" {
  name                = "mgw-linux-function-app"
  resource_group_name = var.rg_grp_name
  location            = var.rg_grp_loc

  storage_account_name       = azurerm_storage_account.function_storage.name
  storage_account_access_key = azurerm_storage_account.function_storage.primary_access_key
  service_plan_id            = azurerm_service_plan.main.id

  app_settings = {
    FUNCTIONS_WORKER_RUNTIME       = "python"
    APPINSIGHTS_INSTRUMENTATIONKEY = azurerm_application_insights.main.instrumentation_key
  }
  #Check the error log to solve this one

  site_config {
    application_stack {
      python_version = 3.7
    }
  }
}
xiaxyi commented 2 years ago

Thanks @mgw6 for the information.

The function app function cannot be deleted via API neither, at least we can confirm the issue is happening from the function side. my suggestions would be checking the function app configurations, there may be some misconfigurations that are blocking the function from being deleting, maybe we can get some useful information from the activity log.

As for the python_version, it's not supposed to be set via app_setting, instead via site_config -> application_stack as your code suggested.

azurerm_function_app is being deprecating and will totally be removed from 4.0 provider. We strongly recommend users to use azurerm_windows_function_app and linux_function_app instead.

mgw6 commented 2 years ago

Hi @xiaxyi

Thank for you for the tip about the configurations. I am finding that after running apply, if I go into the function app configuration and change the Daily Usage Quota setting via the portal, then the function will delete via terraform command line. However if I try to set this feature through Terraform via daily_memory_time_quota then it still fails to delete with Terraform. I am including my updated code below. When I hit the save butting after changing the configurations, are there some other features that are being modified?

resource "azurerm_linux_function_app" "main" {
  name                = "mgw-linux-function-app"
  resource_group_name = var.rg_grp_name
  location            = var.rg_grp_loc

  storage_account_name       = azurerm_storage_account.function_storage.name
  storage_account_access_key = azurerm_storage_account.function_storage.primary_access_key
  service_plan_id            = azurerm_service_plan.main.id

  daily_memory_time_quota = 1

  app_settings = {
    FUNCTIONS_WORKER_RUNTIME       = "python"
    APPINSIGHTS_INSTRUMENTATIONKEY = azurerm_application_insights.main.instrumentation_key
  }
  #Check the error log to solve this one

  site_config {
    application_stack {
      python_version = 3.7
    }
  }
}

After deploying the function_app, the activity log looks like this: (I would copy/paste into CSV and read in Excel.

Correlation id,Operation name,Status,Event category,Level,Time,Subscription,Resource type,Resource group,Resource
97d07185-058a-448d-b497-eec466172978,'auditIfNotExists' Policy action.,Succeeded,Policy,Informational,2022-10-03T02:15:54.826Z,5581d03e-5621-4415-bff1-e87a68da5dae,Microsoft.Web/sites,mgw-rg-eastus,/subscriptions/5581d03e-5621-4415-bff1-e87a68da5dae/resourceGroups/mgw-rg-eastus/providers/Microsoft.Web/sites/mgw-linux-function-app
97d07185-058a-448d-b497-eec466172978,'audit' Policy action.,Succeeded,Policy,Warning,2022-10-03T02:15:54.826Z,5581d03e-5621-4415-bff1-e87a68da5dae,Microsoft.Web/sites,mgw-rg-eastus,/subscriptions/5581d03e-5621-4415-bff1-e87a68da5dae/resourceGroups/mgw-rg-eastus/providers/Microsoft.Web/sites/mgw-linux-function-app
97d07185-058a-448d-b497-eec466172978,'audit' Policy action.,Succeeded,Policy,Warning,2022-10-03T02:15:54.826Z,5581d03e-5621-4415-bff1-e87a68da5dae,Microsoft.Web/sites,mgw-rg-eastus,/subscriptions/5581d03e-5621-4415-bff1-e87a68da5dae/resourceGroups/mgw-rg-eastus/providers/Microsoft.Web/sites/mgw-linux-function-app
97d07185-058a-448d-b497-eec466172978,'audit' Policy action.,Succeeded,Policy,Warning,2022-10-03T02:15:54.826Z,5581d03e-5621-4415-bff1-e87a68da5dae,Microsoft.Web/sites,mgw-rg-eastus,/subscriptions/5581d03e-5621-4415-bff1-e87a68da5dae/resourceGroups/mgw-rg-eastus/providers/Microsoft.Web/sites/mgw-linux-function-app
97d07185-058a-448d-b497-eec466172978,'audit' Policy action.,Succeeded,Policy,Warning,2022-10-03T02:15:54.826Z,5581d03e-5621-4415-bff1-e87a68da5dae,Microsoft.Web/sites,mgw-rg-eastus,/subscriptions/5581d03e-5621-4415-bff1-e87a68da5dae/resourceGroups/mgw-rg-eastus/providers/Microsoft.Web/sites/mgw-linux-function-app
97d07185-058a-448d-b497-eec466172978,'auditIfNotExists' Policy action.,Succeeded,Policy,Informational,2022-10-03T02:15:54.826Z,5581d03e-5621-4415-bff1-e87a68da5dae,Microsoft.Web/sites,mgw-rg-eastus,/subscriptions/5581d03e-5621-4415-bff1-e87a68da5dae/resourceGroups/mgw-rg-eastus/providers/Microsoft.Web/sites/mgw-linux-function-app
97d07185-058a-448d-b497-eec466172978,'audit' Policy action.,Succeeded,Policy,Warning,2022-10-03T02:15:54.826Z,5581d03e-5621-4415-bff1-e87a68da5dae,Microsoft.Web/sites,mgw-rg-eastus,/subscriptions/5581d03e-5621-4415-bff1-e87a68da5dae/resourceGroups/mgw-rg-eastus/providers/Microsoft.Web/sites/mgw-linux-function-app
97d07185-058a-448d-b497-eec466172978,'auditIfNotExists' Policy action.,Succeeded,Policy,Informational,2022-10-03T02:15:54.826Z,5581d03e-5621-4415-bff1-e87a68da5dae,Microsoft.Web/sites,mgw-rg-eastus,/subscriptions/5581d03e-5621-4415-bff1-e87a68da5dae/resourceGroups/mgw-rg-eastus/providers/Microsoft.Web/sites/mgw-linux-function-app
97d07185-058a-448d-b497-eec466172978,'audit' Policy action.,Succeeded,Policy,Warning,2022-10-03T02:15:54.826Z,5581d03e-5621-4415-bff1-e87a68da5dae,Microsoft.Web/sites,mgw-rg-eastus,/subscriptions/5581d03e-5621-4415-bff1-e87a68da5dae/resourceGroups/mgw-rg-eastus/providers/Microsoft.Web/sites/mgw-linux-function-app
97d07185-058a-448d-b497-eec466172978,'auditIfNotExists' Policy action.,Succeeded,Policy,Informational,2022-10-03T02:15:54.826Z,5581d03e-5621-4415-bff1-e87a68da5dae,Microsoft.Web/sites,mgw-rg-eastus,/subscriptions/5581d03e-5621-4415-bff1-e87a68da5dae/resourceGroups/mgw-rg-eastus/providers/Microsoft.Web/sites/mgw-linux-function-app
97d07185-058a-448d-b497-eec466172978,'audit' Policy action.,Succeeded,Policy,Warning,2022-10-03T02:15:54.826Z,5581d03e-5621-4415-bff1-e87a68da5dae,Microsoft.Web/sites,mgw-rg-eastus,/subscriptions/5581d03e-5621-4415-bff1-e87a68da5dae/resourceGroups/mgw-rg-eastus/providers/Microsoft.Web/sites/mgw-linux-function-app
97d07185-058a-448d-b497-eec466172978,'auditIfNotExists' Policy action.,Succeeded,Policy,Informational,2022-10-03T02:15:54.826Z,5581d03e-5621-4415-bff1-e87a68da5dae,Microsoft.Web/sites,mgw-rg-eastus,/subscriptions/5581d03e-5621-4415-bff1-e87a68da5dae/resourceGroups/mgw-rg-eastus/providers/Microsoft.Web/sites/mgw-linux-function-app
97d07185-058a-448d-b497-eec466172978,'auditIfNotExists' Policy action.,Succeeded,Policy,Informational,2022-10-03T02:15:54.826Z,5581d03e-5621-4415-bff1-e87a68da5dae,Microsoft.Web/sites,mgw-rg-eastus,/subscriptions/5581d03e-5621-4415-bff1-e87a68da5dae/resourceGroups/mgw-rg-eastus/providers/Microsoft.Web/sites/mgw-linux-function-app
97d07185-058a-448d-b497-eec466172978,'auditIfNotExists' Policy action.,Succeeded,Policy,Informational,2022-10-03T02:15:54.826Z,5581d03e-5621-4415-bff1-e87a68da5dae,Microsoft.Web/sites,mgw-rg-eastus,/subscriptions/5581d03e-5621-4415-bff1-e87a68da5dae/resourceGroups/mgw-rg-eastus/providers/Microsoft.Web/sites/mgw-linux-function-app
22492b57-732c-bfbd-c6b8-ec3074b76ae1,Delete website,Succeeded,Administrative,Informational,2022-10-03T02:08:05.479Z,5581d03e-5621-4415-bff1-e87a68da5dae,Microsoft.Web/sites,mgw-rg-eastus,/subscriptions/5581d03e-5621-4415-bff1-e87a68da5dae/resourcegroups/mgw-rg-eastus/providers/Microsoft.Web/sites/mgw-linux-function-app
22492b57-732c-bfbd-c6b8-ec3074b76ae1,Delete website,Started,Administrative,Informational,2022-10-03T02:07:27.156Z,5581d03e-5621-4415-bff1-e87a68da5dae,Microsoft.Web/sites,mgw-rg-eastus,/subscriptions/5581d03e-5621-4415-bff1-e87a68da5dae/resourceGroups/mgw-rg-eastus/providers/Microsoft.Web/sites/mgw-linux-function-app
22492b57-732c-bfbd-c6b8-ec3074b76ae1,Delete website,Succeeded,Administrative,Informational,2022-10-03T02:07:33.154Z,5581d03e-5621-4415-bff1-e87a68da5dae,Microsoft.Web/sites,mgw-rg-eastus,/subscriptions/5581d03e-5621-4415-bff1-e87a68da5dae/resourceGroups/mgw-rg-eastus/providers/Microsoft.Web/sites/mgw-linux-function-app
ffc2c030-e4c6-44f6-86f7-95d5dd3febf7,DeleteWebSite,Succeeded,Administrative,Informational,2022-10-03T02:07:31.000Z,5581d03e-5621-4415-bff1-e87a68da5dae,MICROSOFT.WEB/sites,MGW-RG-EASTUS,/SUBSCRIPTIONS/5581D03E-5621-4415-BFF1-E87A68DA5DAE/RESOURCEGROUPS/MGW-RG-EASTUS/PROVIDERS/MICROSOFT.WEB/SITES/MGW-LINUX-FUNCTION-APP
ffc2c030-e4c6-44f6-86f7-95d5dd3febf7,DeleteWebSite,Started,Administrative,Informational,2022-10-03T02:07:27.000Z,5581d03e-5621-4415-bff1-e87a68da5dae,MICROSOFT.WEB/sites,MGW-RG-EASTUS,/SUBSCRIPTIONS/5581D03E-5621-4415-BFF1-E87A68DA5DAE/RESOURCEGROUPS/MGW-RG-EASTUS/PROVIDERS/MICROSOFT.WEB/SITES/MGW-LINUX-FUNCTION-APP
a6dab985-da56-4ee5-a668-7bbe78da3d84,Sync Web Apps Function Triggers,Succeeded,Administrative,Informational,2022-10-03T02:05:53.036Z,5581d03e-5621-4415-bff1-e87a68da5dae,Microsoft.Web/sites/host,mgw-rg-eastus,/subscriptions/5581d03e-5621-4415-bff1-e87a68da5dae/resourceGroups/mgw-rg-eastus/providers/Microsoft.Web/sites/mgw-linux-function-app/host/default
a6dab985-da56-4ee5-a668-7bbe78da3d84,Sync Web Apps Function Triggers,Started,Administrative,Informational,2022-10-03T02:05:51.786Z,5581d03e-5621-4415-bff1-e87a68da5dae,Microsoft.Web/sites/host,mgw-rg-eastus,/subscriptions/5581d03e-5621-4415-bff1-e87a68da5dae/resourceGroups/mgw-rg-eastus/providers/Microsoft.Web/sites/mgw-linux-function-app/host/default
82e605ad-532d-4c30-9e7a-f474459e1c50,UpdateWebSite,Succeeded,Administrative,Informational,2022-10-03T02:05:50.000Z,5581d03e-5621-4415-bff1-e87a68da5dae,MICROSOFT.WEB/sites,MGW-RG-EASTUS,/SUBSCRIPTIONS/5581D03E-5621-4415-BFF1-E87A68DA5DAE/RESOURCEGROUPS/MGW-RG-EASTUS/PROVIDERS/MICROSOFT.WEB/SITES/MGW-LINUX-FUNCTION-APP
82e605ad-532d-4c30-9e7a-f474459e1c50,UpdateWebSite,Started,Administrative,Informational,2022-10-03T02:05:48.000Z,5581d03e-5621-4415-bff1-e87a68da5dae,MICROSOFT.WEB/sites,MGW-RG-EASTUS,/SUBSCRIPTIONS/5581D03E-5621-4415-BFF1-E87A68DA5DAE/RESOURCEGROUPS/MGW-RG-EASTUS/PROVIDERS/MICROSOFT.WEB/SITES/MGW-LINUX-FUNCTION-APP
5e082f93-e12d-49ac-8233-9654059837b4,Sync Web Apps Function Triggers,Succeeded,Administrative,Informational,2022-10-03T02:05:39.880Z,5581d03e-5621-4415-bff1-e87a68da5dae,Microsoft.Web/sites/host,mgw-rg-eastus,/subscriptions/5581d03e-5621-4415-bff1-e87a68da5dae/resourceGroups/mgw-rg-eastus/providers/Microsoft.Web/sites/mgw-linux-function-app/host/default
5e082f93-e12d-49ac-8233-9654059837b4,Sync Web Apps Function Triggers,Started,Administrative,Informational,2022-10-03T02:05:39.364Z,5581d03e-5621-4415-bff1-e87a68da5dae,Microsoft.Web/sites/host,mgw-rg-eastus,/subscriptions/5581d03e-5621-4415-bff1-e87a68da5dae/resourceGroups/mgw-rg-eastus/providers/Microsoft.Web/sites/mgw-linux-function-app/host/default
b40d16a0-815a-5f06-e296-f150af230b49,Delete Web Apps Functions,Failed,Administrative,Error,2022-10-03T02:04:48.309Z,5581d03e-5621-4415-bff1-e87a68da5dae,Microsoft.Web/sites/functions,mgw-rg-eastus,/subscriptions/5581d03e-5621-4415-bff1-e87a68da5dae/resourceGroups/mgw-rg-eastus/providers/Microsoft.Web/sites/mgw-linux-function-app/functions/mgw-function-app-function
b40d16a0-815a-5f06-e296-f150af230b49,Delete Web Apps Functions,Started,Administrative,Informational,2022-10-03T02:04:47.637Z,5581d03e-5621-4415-bff1-e87a68da5dae,Microsoft.Web/sites/functions,mgw-rg-eastus,/subscriptions/5581d03e-5621-4415-bff1-e87a68da5dae/resourceGroups/mgw-rg-eastus/providers/Microsoft.Web/sites/mgw-linux-function-app/functions/mgw-function-app-function
679d7afd-7fd3-4e84-a924-88a4091ee69f,List Web Apps Functions Host Keys,Succeeded,Administrative,Informational,2022-10-03T02:01:44.594Z,5581d03e-5621-4415-bff1-e87a68da5dae,Microsoft.Web/sites/host,mgw-rg-eastus,/subscriptions/5581d03e-5621-4415-bff1-e87a68da5dae/resourceGroups/mgw-rg-eastus/providers/Microsoft.Web/sites/mgw-linux-function-app/host/default
679d7afd-7fd3-4e84-a924-88a4091ee69f,List Web Apps Functions Host Keys,Started,Administrative,Informational,2022-10-03T02:01:44.297Z,5581d03e-5621-4415-bff1-e87a68da5dae,Microsoft.Web/sites/host,mgw-rg-eastus,/subscriptions/5581d03e-5621-4415-bff1-e87a68da5dae/resourceGroups/mgw-rg-eastus/providers/Microsoft.Web/sites/mgw-linux-function-app/host/default
beef8b84-a2b0-8785-3624-1578a38d7862,Update Web Apps Functions,Succeeded,Administrative,Informational,2022-10-03T02:01:38.720Z,5581d03e-5621-4415-bff1-e87a68da5dae,Microsoft.Web/sites/functions,mgw-rg-eastus,/subscriptions/5581d03e-5621-4415-bff1-e87a68da5dae/resourceGroups/mgw-rg-eastus/providers/Microsoft.Web/sites/mgw-linux-function-app/functions/mgw-function-app-function
beef8b84-a2b0-8785-3624-1578a38d7862,Update website,Started,Administrative,Informational,2022-10-03T02:00:34.215Z,5581d03e-5621-4415-bff1-e87a68da5dae,Microsoft.Web/sites,mgw-rg-eastus,/subscriptions/5581d03e-5621-4415-bff1-e87a68da5dae/resourceGroups/mgw-rg-eastus/providers/Microsoft.Web/sites/mgw-linux-function-app
beef8b84-a2b0-8785-3624-1578a38d7862,'audit' Policy action.,Succeeded,Policy,Warning,2022-10-03T02:00:34.434Z,5581d03e-5621-4415-bff1-e87a68da5dae,Microsoft.Web/sites,mgw-rg-eastus,/subscriptions/5581d03e-5621-4415-bff1-e87a68da5dae/resourceGroups/mgw-rg-eastus/providers/Microsoft.Web/sites/mgw-linux-function-app
beef8b84-a2b0-8785-3624-1578a38d7862,'auditIfNotExists' Policy action.,Started,Policy,Informational,2022-10-03T02:00:52.501Z,5581d03e-5621-4415-bff1-e87a68da5dae,Microsoft.Web/sites,mgw-rg-eastus,/subscriptions/5581d03e-5621-4415-bff1-e87a68da5dae/resourceGroups/mgw-rg-eastus/providers/Microsoft.Web/sites/mgw-linux-function-app
beef8b84-a2b0-8785-3624-1578a38d7862,Update website,Succeeded,Administrative,Informational,2022-10-03T02:00:52.517Z,5581d03e-5621-4415-bff1-e87a68da5dae,Microsoft.Web/sites,mgw-rg-eastus,/subscriptions/5581d03e-5621-4415-bff1-e87a68da5dae/resourceGroups/mgw-rg-eastus/providers/Microsoft.Web/sites/mgw-linux-function-app
beef8b84-a2b0-8785-3624-1578a38d7862,Update website,Started,Administrative,Informational,2022-10-03T02:00:52.610Z,5581d03e-5621-4415-bff1-e87a68da5dae,Microsoft.Web/sites,mgw-rg-eastus,/subscriptions/5581d03e-5621-4415-bff1-e87a68da5dae/resourceGroups/mgw-rg-eastus/providers/Microsoft.Web/sites/mgw-linux-function-app
beef8b84-a2b0-8785-3624-1578a38d7862,'audit' Policy action.,Succeeded,Policy,Warning,2022-10-03T02:00:52.626Z,5581d03e-5621-4415-bff1-e87a68da5dae,Microsoft.Web/sites,mgw-rg-eastus,/subscriptions/5581d03e-5621-4415-bff1-e87a68da5dae/resourceGroups/mgw-rg-eastus/providers/Microsoft.Web/sites/mgw-linux-function-app
beef8b84-a2b0-8785-3624-1578a38d7862,'auditIfNotExists' Policy action.,Started,Policy,Informational,2022-10-03T02:00:55.002Z,5581d03e-5621-4415-bff1-e87a68da5dae,Microsoft.Web/sites,mgw-rg-eastus,/subscriptions/5581d03e-5621-4415-bff1-e87a68da5dae/resourceGroups/mgw-rg-eastus/providers/Microsoft.Web/sites/mgw-linux-function-app
beef8b84-a2b0-8785-3624-1578a38d7862,Update website,Succeeded,Administrative,Informational,2022-10-03T02:00:56.004Z,5581d03e-5621-4415-bff1-e87a68da5dae,Microsoft.Web/sites,mgw-rg-eastus,/subscriptions/5581d03e-5621-4415-bff1-e87a68da5dae/resourceGroups/mgw-rg-eastus/providers/Microsoft.Web/sites/mgw-linux-function-app
beef8b84-a2b0-8785-3624-1578a38d7862,Update Web Apps Functions,Started,Administrative,Informational,2022-10-03T02:01:37.907Z,5581d03e-5621-4415-bff1-e87a68da5dae,Microsoft.Web/sites/functions,mgw-rg-eastus,/subscriptions/5581d03e-5621-4415-bff1-e87a68da5dae/resourceGroups/mgw-rg-eastus/providers/Microsoft.Web/sites/mgw-linux-function-app/functions/mgw-function-app-function
e3c12ecf-f7a3-45d8-9ab3-4a8b59ec24e9,UpdateWebSite,Succeeded,Administrative,Informational,2022-10-03T02:00:54.000Z,5581d03e-5621-4415-bff1-e87a68da5dae,MICROSOFT.WEB/sites,MGW-RG-EASTUS,/SUBSCRIPTIONS/5581D03E-5621-4415-BFF1-E87A68DA5DAE/RESOURCEGROUPS/MGW-RG-EASTUS/PROVIDERS/MICROSOFT.WEB/SITES/MGW-LINUX-FUNCTION-APP
e3c12ecf-f7a3-45d8-9ab3-4a8b59ec24e9,UpdateWebSite,Started,Administrative,Informational,2022-10-03T02:00:53.000Z,5581d03e-5621-4415-bff1-e87a68da5dae,MICROSOFT.WEB/sites,MGW-RG-EASTUS,/SUBSCRIPTIONS/5581D03E-5621-4415-BFF1-E87A68DA5DAE/RESOURCEGROUPS/MGW-RG-EASTUS/PROVIDERS/MICROSOFT.WEB/SITES/MGW-LINUX-FUNCTION-APP
f0c5aa78-8fcc-4407-8c8c-a500df2f265c,CreateWebSite,Succeeded,Administrative,Informational,2022-10-03T02:00:52.000Z,5581d03e-5621-4415-bff1-e87a68da5dae,MICROSOFT.WEB/sites,MGW-RG-EASTUS,/SUBSCRIPTIONS/5581D03E-5621-4415-BFF1-E87A68DA5DAE/RESOURCEGROUPS/MGW-RG-EASTUS/PROVIDERS/MICROSOFT.WEB/SITES/MGW-LINUX-FUNCTION-APP
f0c5aa78-8fcc-4407-8c8c-a500df2f265c,CreateWebSite,Started,Administrative,Informational,2022-10-03T02:00:35.000Z,5581d03e-5621-4415-bff1-e87a68da5dae,MICROSOFT.WEB/sites,MGW-RG-EASTUS,/SUBSCRIPTIONS/5581D03E-5621-4415-BFF1-E87A68DA5DAE/RESOURCEGROUPS/MGW-RG-EASTUS/PROVIDERS/MICROSOFT.WEB/SITES/MGW-LINUX-FUNCTION-APP

After the failure to delete the function, I go in and change the Daily Usage Quota, which appears in the log and "Sync Web App Functions" and "Update Website". I am thinking the issue is somewhere in here.

I am using the azurerm_linux_function_app, I referenced the wrong documentation above.

chaoqi commented 1 year ago

I also have this problems since two weeks ago, it looks like Terraform can not destroy the azurerm_linux_function_app.... it has already been deleted in the portal, but somehow terraform are waiting for the 200 response but could not get it and in the end, terraform outputs error.... can someone take a look at this issue? Thank you very much.

The error what i get is:

web.AppsClient#Delete: Failure sending request: StatusCode=504 -- Original Error: context deadline exceeded

chaoqi commented 1 year ago

Does anyone have a workaround for this problem? terraform can destroy windows_function_app without any problems but somehow can still not destroy the linux_function_app... any ideas on solving this would be highly appreciated.

xiaxyi commented 1 year ago

Hey Guys, after deleting the functions, have you tried to restart the function app?

mgw6 commented 1 year ago

No, I have not. If I do that what should I do/look for?

On Mon, Oct 24, 2022 at 1:26 AM Xiaxin @.***> wrote:

Hey Guys, after deleting the functions, have you tried to restart the function app?

— Reply to this email directly, view it on GitHub https://github.com/hashicorp/terraform-provider-azurerm/issues/18293#issuecomment-1288438384, or unsubscribe https://github.com/notifications/unsubscribe-auth/AUJ7YSC5BRCTPEENEFIARNTWEYMZHANCNFSM6AAAAAAQHFMLDI . You are receiving this because you were mentioned.Message ID: @.***>

-- MacGregor G. Winegard | http://linkedin.com/in/mwinegard

*(518) 641 - 9780 || @. @.>*

xiaxyi commented 1 year ago

I was able to see this issue intermittently, the detailed behavior is the function still exists in Azure portal, even after I used the DELETE api (please note its api, not terraform which is calling the SDK instead).

Then I tried to restart the function app, the issue disappeared: image

Can you try the same?

chaoqi commented 1 year ago

@xiaxyi we can destroy the linux function app via terraform since a few days now... Thank you very much...

xiaxyi commented 1 year ago

@chaoqi Thanks for the update! Did you take any actions such as restarting the function?

chaoqi commented 1 year ago

@xiaxyi Not at all.... it just works which it does not work before.... can not explain why....

mgw6 commented 1 year ago

Hi @xiaxyi

I am still receiving the error. The most recent activity that caused it was that I chanced the name of the azurerm_function_app_function. This forces the old function to be deleted and a new one to be created. As before the init and plan all ran fine, but it gets caught on the apply. The error I received is below: (I redacted the names of the function app and app function.)

╷
│ Error: deleting Function App Function: (Function Name "[function name redacted]" / Site Name "[function app name redacted]" / Resource Group "***"): web.AppsClient#DeleteFunction: Failure responding to request: StatusCode=404 -- Original Error: autorest/azure: Service returned an error. Status=404 Code="NotFound" Message="Error deleting function."
│ 
│ deleting Function App Function: (Function Name "[function name redacted]" /
│ Site Name "[function app name redacted]" / Resource Group
│ "***"): web.AppsClient#DeleteFunction: Failure
│ responding to request: StatusCode=404 -- Original Error: autorest/azure:
│ Service returned an error. Status=404 Code="NotFound" Message="Error
│ deleting function."
╵
##[error]Error: The process '/opt/hostedtoolcache/terraform/1.3.3/x64/terraform' failed with exit code 1

I have been comparing the JSON file for this function to other functions' JSON files and cannot see an obvious difference between the two.

mgw6 commented 1 year ago

Hi @xiaxyi

Latest update on this issue from my end. I continue having this error every time I modify the function in a way that causes it to be deleted and recreated. To get around the error, I go in and delete the function in the Azure portal before running the tf apply. However when I delete the function I first get this error: image

When I go back and refresh the list of functions, the function will disappear, but I never get a notification saying that it was actually deleted.

Annotation 2022-11-15 095111

Here is the events from the activity log: image

I agree with you that this is an issue on Azure's end. What would we need to do to elevate it to that level?

mgw6 commented 1 year ago

Hi @xiaxyi As it stands now Azure just doesn't let you delete functions. When trying to delete manually deployed ones through both the Azure Portal and VS Code, it says deleting but then they're still there after the delete is "Complete". Who should this be forwarded to next?

Lanre-B commented 2 weeks ago

Does anyone know if this has been resolved? I have the same problem and can't figure out what to do.