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

azurerm_windows_function_app and azurerm_linux_function_app does not generate default app host keys #17750

Open neilmca-inc opened 2 years ago

neilmca-inc commented 2 years ago

Is there an existing issue for this?

Community Note

Terraform Version

1.2.5

AzureRM Provider Version

3.15.0

Affected Resource(s)/Data Source(s)

azurerm_windows_function_app, azurerm_linux_function_app

Terraform Configuration Files

terraform {
  required_providers {
    azurerm = {
      source = "hashicorp/azurerm"
      version = "3.15.0"
    }
  }
}

provider "azurerm" {
  features {}
}

resource "random_string" "genrandom" {
  length = 8
  special = false
  min_numeric = 0
  min_upper = 0
  min_lower = 8
}

resource "azurerm_resource_group" "example" {
  name     = "rg-testfa${random_string.genrandom.id}"
  location = "North Europe"
}

resource "azurerm_storage_account" "example" {
  name                     = "satestfa${random_string.genrandom.id}"
  resource_group_name      = azurerm_resource_group.example.name
  location                 = azurerm_resource_group.example.location
  account_tier             = "Standard"
  account_replication_type = "LRS"
}

# App Service Plan
resource "azurerm_service_plan" "example" {
  name                = "asp-windows${random_string.genrandom.id}"
  resource_group_name = azurerm_resource_group.example.name
  location            = azurerm_resource_group.example.location
  os_type             = "Windows"
  sku_name            = "S1"
}

# Functions using new resource type
resource "azurerm_windows_function_app" "example" {
  name                = "fa-newfawindows01${random_string.genrandom.id}"
  resource_group_name = azurerm_resource_group.example.name
  location            = azurerm_resource_group.example.location

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

  site_config {}

}

# Function using old resource type
resource "azurerm_function_app" "example" {
  name                       = "fa-oldwindows01${random_string.genrandom.id}"
  location                   = azurerm_resource_group.example.location
  resource_group_name        = azurerm_resource_group.example.name
  app_service_plan_id        = azurerm_service_plan.example.id
  storage_account_name       = azurerm_storage_account.example.name
  storage_account_access_key = azurerm_storage_account.example.primary_access_key
}

Debug Output/Panic Output

None

Expected Behaviour

Creates "App Keys" named default and _master host keys. This works with the old azurerm_function_app resource.

This is also added by default when you create a Function App in the Azure portal.

image

Actual Behaviour

It doesn't creates "App Keys" named default and _master host keys

Steps to Reproduce

No response

Important Factoids

Please note that my Terraform code is exactly the same code as provided in the example sections of the official Terraform documentation - the only thing I have added is the random_string generation so you can try it on your own systems easily

No response

References

No response

priyankar-dutta commented 2 years ago

+1 - experiencing same issue

StefanSchoof commented 2 years ago

I had cases where the keys took a very long time to show up. (So I run in timeouts in my tf and wait until the show up)

JoshWeepie commented 2 years ago

I'm not sure if this issue is still occurring, the azurerm_windows_function_app resource generates host keys for me, I just have the .NET 6 and v4 runtime issue.

neilmca-inc commented 2 years ago

Too late for me - I returned to using azurerm_function_app as it worked - sometimes you have to go with what works, rather than the new untested ones, which clearly this is

ehsan1503 commented 2 years ago

+1 - experiencing same issue

Quixotical commented 1 year ago

Hey! I was able to resolve this issue by doing one of the two following things

  1. do a local-exec provision after the function is deployed when WEBSITE_RUN_FROM_PACKAGE = 1 and after the deployment of a HTTP trigger function is completed, it will have the keys,
  2. You can set WEBSITE_RUN_FROM_PACKAGE = 0 and then it will generate the keys, but if you wanted it to be 1 then you have to manually change it back, which kinda sucks
siqueirarenan commented 1 year ago

Any update on that issue?