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

Error when deploying a Flex Consumption Function App #26672

Open oWretch opened 1 month ago

oWretch commented 1 month ago

Is there an existing issue for this?

Community Note

Terraform Version

1.9.1

AzureRM Provider Version

3.112.0

Affected Resource(s)/Data Source(s)

azurerm_linux_function_app

Terraform Configuration Files

resource "azurerm_linux_function_app" "this" {
  name                = "test-function-app-234asf"
  resource_group_name = azurerm_resource_group.test.name
  location            = azurerm_resource_group.test.location
  service_plan_id     = azurerm_service_plan.test.id

  storage_account_name       = azurerm_storage_account.test.name
  storage_account_access_key = azurerm_storage_account.test.primary_access_key

  site_config {
    application_stack {
      python_version = "3.11"
    }
  }
}

resource "azurerm_service_plan" "test" {
  name                = "test-service-plan"
  location            = azurerm_resource_group.test.location
  resource_group_name = azurerm_resource_group.test.name

  sku_name = "FC1"
  os_type  = "Linux"
}

resource "azurerm_storage_account" "test" {
  name                     = "testsa234asf"
  resource_group_name      = azurerm_resource_group.test.name
  location                 = azurerm_resource_group.test.location
  account_tier             = "Standard"
  account_replication_type = "LRS"
}

resource "azurerm_resource_group" "test" {
  name     = "terraform-test-rg"
  location = "East US"
}

Debug Output/Panic Output

Error: creating Linux App Service (Subscription: "00000000-0000-0000-0000-000000000000"
│ Resource Group Name: "terraform-test-rg"
│ Site Name: "test-function-app-234asf"): performing CreateOrUpdate: unexpected status 400 (400 Bad Request) with response: {"Code":"BadRequest","Message":"Site.FunctionAppConfig is invalid.  The FunctionAppConfig section was not specified in the request, which is required for Flex Consumption sites. To proceed, please add the FunctionAppConfig section in your request.","Target":null,"Details":[{"Message":"Site.FunctionAppConfig is invalid.  The FunctionAppConfig section was not specified in the request, which is required for Flex Consumption sites. To proceed, please add the FunctionAppConfig section in your request."},{"Code":"BadRequest"},{"ErrorEntity":{"ExtendedCode":"51021","MessageTemplate":"{0} is invalid.  {1}","Parameters":["Site.FunctionAppConfig","The FunctionAppConfig section was not specified in the request, which is required for Flex Consumption sites. To proceed, please add the FunctionAppConfig section in your request."],"Code":"BadRequest","Message":"Site.FunctionAppConfig is invalid.  The FunctionAppConfig section was not specified in the request, which is required for Flex Consumption sites. To proceed, please add the FunctionAppConfig section in your request."}}],"Innererror":null}
│ 
│   with azurerm_linux_function_app.this,
│   on azurerm.tf line 1, in resource "azurerm_linux_function_app" "this":
│    1: resource "azurerm_linux_function_app" "this" {

After adding support for the FC1 SKU to the azurerm_service_plan in #26351 as part of #26043 I attempted to also create a flex consumption function app. This failed with the above error.

Resolution of this is dependant upon hashicorp/go-azure-sdk#1017 ,which may be dependant upon an upstream fix - I haven't investigated that far.

I'm mostly raising this issue as a placeholder for a known issue.

As an aside, it seems that Microsoft are making some significant changes to the way the Function App is provisioned - many of the old settings are deprecated and replaced with new settings inside the functionAppConfig structure. Reference: https://learn.microsoft.com/en-us/azure/azure-functions/flex-consumption-plan.

Also, from further testing, the functionAppConfig structure is only supported on the flex consumption function apps.

xiaxyi commented 1 month ago

Thanks @oWretch for raising this issue, just curious about whether you are able to create the function app via Azure portal? Seems I'm having issue creating the flex consumption function app via any methods.

oWretch commented 1 month ago

Hi @xiaxyi. Yes, I have been able to create Flex Consumption Function Apps both via the portal and code. I've written a blog post on how to do it with the AzAPI provider: https://solideogloria.tech/azure/deploy-a-flex-consumption-function-app-with-terraform/

JameySteinmann commented 1 month ago

Also worth noting that this sample code from the Azure-Samples works with the AzAPI provider as well. I have tested this code and confirm it works. https://github.com/Azure-Samples/azure-functions-flex-consumption-samples/blob/main/IaC/terraform/main.tf

Now we just need the AzureRM provider to be current with this feature.

rcomar-cit commented 2 weeks ago

Hi guys! I also need to deploy a function app in consumption plan, are there plans for these adjustments to be included in AzureRM provider in a near future ?