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

dotnet_core_version triggers constant update #24206

Open kpggt opened 9 months ago

kpggt commented 9 months ago

Is there an existing issue for this?

Community Note

Terraform Version

1.5.0

AzureRM Provider Version

3.84.0

Affected Resource(s)/Data Source(s)

azurerm_windows_web_app

Terraform Configuration Files

resource "azurerm_windows_web_app" "webapp" {
  for_each            = { for app in local.servicemap_win : app.app_name => app }
  name                = "${var.resourcegroupname}-${each.value.app_name}-app"
  location            = var.defaults.global.location
  resource_group_name = var.resourcegroupname
  service_plan_id     = azurerm_service_plan.serviceplan["${each.value.appservice_name}"].id

  site_config {
    cors {
      allowed_origins = each.value.cors
    }

    application_stack {
      tomcat_version               = each.value.webapp_appstack_win_tomcat_version
      java_embedded_server_enabled = each.value.webapp_appstack_win_java_embedded_server_enabled
      docker_container_name        = each.value.webapp_appstack_win_docker_container_name
      docker_container_tag         = each.value.webapp_appstack_win_docker_container_tag
      python                       = each.value.webapp_appstack_win_python
      dotnet_version               = each.value.webapp_appstack_win_dotnet_version
      java_version                 = each.value.webapp_appstack_win_java_version
      node_version                 = each.value.webapp_appstack_win_node_version
      php_version                  = each.value.webapp_appstack_win_php_version
    }
  }
}

Debug Output/Panic Output

no debug is required as no errors are thrown im assumed

Expected Behaviour

on subsequent runs i dont want to be told the dotnet_core_version will be set to null Capture _version needs to be changes from what ever value dotnet_version was

Actual Behaviour

on subsequent runs im told the dotnet_core_version will be set to null Capture _version needs to be changes from whatever value dotnet_version was

Steps to Reproduce

No response

Important Factoids

No response

References

No response

xiaxyi commented 9 months ago

Thanks @kpggt for raising this issue, Terraform sets the dotnet application stack (dotnet_core/ dotnet) based on the site's meta.

Can you help me to confirm whether your dotnet app is at dotnet core stack using the api: POST https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Web/sites/{name}/config/metadata/list?api-version=2022-03-01? https://learn.microsoft.com/en-us/rest/api/appservice/web-apps/list-metadata?view=rest-appservice-2022-03-01

kpggt commented 9 months ago

im very sorry for not replying to this sooner, we added an ignore and have pushed this change to production. So im working on finding a suitable lab environment to retest this on, but due to the upcoming holiday, my reply will be after newyear.

Alfaxomo commented 6 months ago

Hi @xiaxyi, I am running into this issue as well, but adding to ignore_changes doesn't work for me. Can you provide further information on how to gather potential metadata for an app service to troubleshoot further? I am getting the following error:

curl -X GET "https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Web/sites/{name}/config/metadata/list?api-version=2022-03-01?"
{"error":{"code":"MissingApiVersionParameter","message":"The api-version query parameter (?api-version=) is required for all requests."}}

Thanks in advance for your assistance.

oWretch commented 2 weeks ago

After doing some local testing on this, the issue occurs if the Web App is configured in the back-end to be a .Net Core app, instead of just a .Net app. I'm assuming this is a legacy hangover from when the platform had a difference between Core and Windows .NET applications.

To solve the problem, add the current_stack property to the application_stack property, and set it to dotnet. This should solve the perpetual change.

resource "azurerm_windows_web_app" "this" {
  name                = "windows-web-app-432as"
  location            = azurerm_resource_group.example.location
  resource_group_name = azurerm_resource_group.example.name
  service_plan_id     = azurerm_service_plan.windows.id

  site_config {
    application_stack {
      current_stack  = "dotnet"
      dotnet_version = "v8.0"
    }
  }
}

I'll have a look at what we might be able to do in the provider - it seems to just be a cosmetic legacy hangover...