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

node_version value is inconsistent between azurerm_linux_function_app & azurerm_linux_windows_app #23424

Open MikaelEdebro opened 1 year ago

MikaelEdebro commented 1 year ago

Is there an existing issue for this?

Community Note

Terraform Version

1.5.7

AzureRM Provider Version

3.75.0

Affected Resource(s)/Data Source(s)

azurerm_linux_function_app, azurerm_linux_windows_app

Terraform Configuration Files

// Linux function app
resource "azurerm_linux_function_app" "default" {
  count               = var.os_type == "Linux" ? 1 : 0
  name                = local.function_app_name
  resource_group_name = var.resource_group_name
  location            = var.location

  storage_account_name        = module.fa_sa.name
  storage_account_access_key  = module.fa_sa.primary_access_key
  service_plan_id             = module.fa_asp.id
  https_only                  = true
  builtin_logging_enabled     = false
  functions_extension_version = "~4"

  site_config {
    application_insights_connection_string = var.application_insights_connection_string
    application_stack {
      node_version = "18"
    }
  }

  identity {
    type         = "SystemAssigned, UserAssigned"
    identity_ids = var.service_principal_ids
  }

  lifecycle {
    ignore_changes = [tags, app_settings, site_config]
  }

  depends_on = [
    module.fa_sa, module.fa_asp
  ]
}

// Windows function app
resource "azurerm_windows_function_app" "default" {
  count               = var.os_type == "Windows" ? 1 : 0
  name                = local.function_app_name
  resource_group_name = var.resource_group_name
  location            = var.location

  storage_account_name        = module.fa_sa.name
  storage_account_access_key  = module.fa_sa.primary_access_key
  service_plan_id             = module.fa_asp.id
  https_only                  = true
  builtin_logging_enabled     = false
  functions_extension_version = "~4"

  site_config {
    application_insights_connection_string = var.application_insights_connection_string
    application_stack {
      // inconsistent with linux, where value should be "18" without the tilde
      node_version = "18"
    }
  }

  identity {
    type         = "SystemAssigned, UserAssigned"
    identity_ids = var.service_principal_ids
  }

  lifecycle {
    ignore_changes = [tags, app_settings, site_config]
  }

  depends_on = [
    module.fa_sa, module.fa_asp
  ]
}

Debug Output/Panic Output

Error: expected site_config.0.application_stack.0.node_version to be one of ["~12" "~14" "~16" "~18"], got 18
│ 
│   with module.fa_functions_win_test[0].azurerm_windows_function_app.default[0],
│   on modules/functionapp/main.tf line 79, in resource "azurerm_windows_function_app" "default":
│   79:       node_version = "18"

Expected Behaviour

Expected values should be equal between Windows and Linux resource. Currently Windows only accepts ~18, and Linux accepts only 18.

Actual Behaviour

Currently azurerm_linux_function_app accepts values without ~, like this:

application_stack {
   node_version = "18"
}

While on azurerm_windows_function_app, the value needs to be ~18:

application_stack {
  node_version = "~18"
}

Preferably both Windows and Linux should accept the same values.

Steps to Reproduce

terraform plan

Important Factoids

I don't think so, this seems like a input validation issue

References

No response

MarcBuch commented 1 year ago

The schema appears to be different:

For windowsFunctionAppStackSchema():

"node_version": {
    Type:     pluginsdk.TypeString,
    Optional: true,
    ValidateFunc: validation.StringInSlice([]string{
        "~12",
        "~14",
        "~16",
        "~18",
    }, false),

For linuxFunctionAppStackSchema():

"node_version": {
    Type:     pluginsdk.TypeString,
    Optional: true,
    ValidateFunc: validation.StringInSlice([]string{
        "12",
        "14",
        "16",
        "18",
    }, false),

But needs check if this is imposed by the Azure API.

EDIT: Was introduced in #15884