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.61k stars 4.65k forks source link

"Syncing triggers... Error calling sync triggers (BadRequest)" error for azurerm_windows_function_app while doing "functionapp publish" #18242

Open Pinaki-1 opened 2 years ago

Pinaki-1 commented 2 years ago

Is there an existing issue for this?

Community Note

Terraform Version

1.1.6

AzureRM Provider Version

3.14.0

Affected Resource(s)/Data Source(s)

azurerm_windows_function_app

Terraform Configuration Files

terraform {
  required_providers {
    azurerm = { version = "=3.14.0" }
  }
}

provider "azurerm" {
  features {
    resource_group {
      prevent_deletion_if_contains_resources = false
    }
  }
}

locals {
  location         = "East US"
  operating_system = "Windows"
}

resource "azurerm_resource_group" "example" {
  name     = "test-funcapp-rg"
  location = local.location
}

resource "azurerm_storage_account" "example" {
  name                      = "testsa08642"
  resource_group_name       = azurerm_resource_group.example.name
  location                  = local.location
  account_tier              = "Standard"
  account_replication_type  = "LRS"
  account_kind              = "StorageV2"
  access_tier               = "Hot"
  enable_https_traffic_only = true
  min_tls_version           = "TLS1_2"

  identity {
    type = "SystemAssigned"
  }

  network_rules {
    default_action = "Deny"
    bypass         = ["AzureServices", "Logging", "Metrics"]
  }
}

resource "azurerm_service_plan" "example" {
  name                = "test-app-service-plan"
  resource_group_name = azurerm_resource_group.example.name
  location            = local.location
  os_type             = local.operating_system
  sku_name            = "P1v3"
}

resource "azurerm_application_insights" "example" {
  name                = "test-app-insight"
  resource_group_name = azurerm_resource_group.example.name
  location            = azurerm_resource_group.example.location
  application_type    = "other"
}

resource "azurerm_windows_function_app" "example" {
  name                = "example-win-function-app-pinaki"
  resource_group_name = azurerm_resource_group.example.name
  location            = local.location
  https_only          = true

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

  functions_extension_version = "~3"

  site_config {
    minimum_tls_version = "1.2"
    websockets_enabled  = false
    always_on           = false

    application_stack {
      powershell_core_version = "7"
    }
  }

  app_settings = {
    FUNCTIONS_WORKER_RUNTIME     = "powershell"

    APPINSIGHTS_INSTRUMENTATIONKEY        = azurerm_application_insights.example.instrumentation_key
    APPLICATIONINSIGHTS_CONNECTION_STRING = azurerm_application_insights.example.connection_string
  }

  identity {
    type = "SystemAssigned"
  }

  depends_on = [ azurerm_application_insights.example ]
}

Debug Output/Panic Output

azurerm_windows_function_app.example: Still creating... [40s elapsed]
azurerm_windows_function_app.example: Still creating... [50s elapsed]
azurerm_windows_function_app.example: Creation complete after 50s [id=/subscriptions/0d6d2ddd-df28-49de-bd13-868298d5dbae/resourceGroups/test-funcapp-rg/providers/Microsoft.Web/sites/example-win-function-app-pinaki]

Apply complete! Resources: 2 added, 0 changed, 2 destroyed.

Expected Behaviour

PS C:\Users\pinaki.a.kundu\Work\Test\SES\FuncApp\tkt\powershell_app> func azure functionapp publish example-win-function-app-pinaki --powershell Getting site publishing info... Creating archive for current directory... Uploading 1.11 KB [###############################################################################] Upload completed successfully. Deployment completed successfully. Functions in example-win-function-app-pinaki: health - [httpTrigger] Invoke url: https://example-win-function-app-pinaki.azurewebsites.net/api/health

Actual Behaviour

PS C:\Users\pinaki.a.kundu\Work\Test\SES\FuncApp\tkt\powershell_app> func azure functionapp publish example-win-function-app-pinaki --powershell Getting site publishing info... Creating archive for current directory... Uploading 1.11 KB [###############################################################################] Upload completed successfully. Deployment completed successfully. Syncing triggers... Syncing triggers... Syncing triggers... Syncing triggers... Syncing triggers... Syncing triggers... Error calling sync triggers (BadRequest). Request ID = '964e03aa-ea4d-4d49-b7c9-337b66ca9744'.

Steps to Reproduce

  1. Publish an app. For example PFA function app I have used -
    powershell_app.zip

Command - func azure functionapp publish example-win-function-app-pinaki --powershell

Important Factoids

This is working fine with "azurerm_linux_function_app" with same azurerm and terraform version.

References

No response

xiaxyi commented 2 years ago

Thanks @Pinaki-Kundu for raising this issue, can you help me to confirm if the function can be viewed by clicking: image

Pinaki-1 commented 2 years ago

Yes. PFB snapshot post clicking on browse -

image

xiaxyi commented 2 years ago

@Pinaki-Kundu Thanks for the update, can you help me to check the activity log to see if we can get a more detailed error message?

Pinaki-1 commented 1 year ago

Hello @xiaxyi, Apology for the late reply. Activity logs showing 'Failed' status for 'Sync Web Apps Function Triggers' with the following status message-

"statusMessage": "{\"Code\":\"BadRequest\",\"Message\":\"Encountered an error (InternalServerError) from host runtime.\",\"Target\":null,\"Details\":[{\"Message\":\"Encountered an error (InternalServerError) from host runtime.\"},{\"Code\":\"BadRequest\"},{\"ErrorEntity\":{\"Code\":\"BadRequest\",\"Message\":\"Encountered an error (InternalServerError) from host runtime.\"}}],\"Innererror\":null}",