Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issues with azurerm_windows_function_app on Java version and cors #17173

Closed
1 task done
jb68 opened this issue Jun 8, 2022 · 19 comments · Fixed by #20987
Closed
1 task done

issues with azurerm_windows_function_app on Java version and cors #17173

jb68 opened this issue Jun 8, 2022 · 19 comments · Fixed by #20987
Labels
Milestone

Comments

@jb68
Copy link

jb68 commented Jun 8, 2022

Is there an existing issue for this?

  • I have searched the existing issues

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Terraform Version

1.2.1

AzureRM Provider Version

3.8

Affected Resource(s)/Data Source(s)

azurerm_windows_function_app

Terraform Configuration Files

resource "azurerm_windows_function_app" "example" {
  name                = "example-windows-function-app"
  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 {
    always_on = true
    http2_enabled = true
    ftps_state = "AllAllowed"
    application_insights_key = azurerm_application_insights.appinsights[count.index].instrumentation_key
    application_stack {
        java_version = "11"
    }


    ip_restriction {
      ip_address = "${azurerm_api_management.example.public_ip_addresses[0]}/32"
      name       = "api_management_public_IP"
    }
    scm_ip_restriction {
      ip_address = "${azurerm_api_management.maasapi.public_ip_addresses[0]}/32"
      name       = "api_management_public_IP"
    }

    cors {
      allowed_origins = var.function_apps[count.index] == "external" ? [] : var.function_app_allowed_origins
    }
  }
}


### Debug Output/Panic Output

```shell
~ site_config {
            # (31 unchanged attributes hidden)

          + application_stack {
              + java_version                = "11"
              + use_dotnet_isolated_runtime = false
            }

          + cors {
              + support_credentials = false
            }
        }

Expected Behaviour

terraform apply should set these

Actual Behaviour

Apply works but doesn't actually sets them. On Azure GUY Java version is empty.

Steps to Reproduce

  1. terraform apply
  2. terraform plan
  3. terraform apply
  4. terraform plan

Important Factoids

No response

References

No response

@jb68 jb68 added the bug label Jun 8, 2022
@github-actions github-actions bot removed the bug label Jun 8, 2022
@xiaxyi
Copy link
Contributor

xiaxyi commented Jul 1, 2022

@jb68 Thanks for raising the issue, I'll work on the fix

@jb68
Copy link
Author

jb68 commented Jul 7, 2022

Thanks,
It looks like It was fixed on 3.12 or at least since 3.8. I'll do more testing

@xiaxyi
Copy link
Contributor

xiaxyi commented Aug 27, 2022

@jb68 hi, good day. can you confirm if this is working as expected from your end? I made a pr for the fix and you can refer to #18076

@arroyc
Copy link

arroyc commented Sep 13, 2022

@xiaxyi .. I'm still facing the issue .. using 3.22 version. application_stack inside site_config doesn't work
app_settings = {
FUNCTIONS_WORKER_RUNTIME = "java"
WEBSITE_RUN_FROM_PACKAGE = data.azurerm_key_vault_secret.uri_secret.value
}

site_config {
always_on = var.always_on != null ? var.always_on : null
application_stack {
java_version = "11"
}

This is what I'm seeing in portal after successful "terraform apply"
image

@xiaxyi
Copy link
Contributor

xiaxyi commented Sep 26, 2022

@arroyc are you using windows function app or linux?

@SoulKa
Copy link

SoulKa commented Nov 24, 2022

@xiaxyi I'm using the windows function app and get the same result

@Suraj-Project
Copy link

I am experiencing the same behavior. Cannot set java version using application stack for windows function app. Is there any workaround to set the version using terraform rather than setting it from portal ?

tried javaVersion in app settings but no luck

@Fafrancisco
Copy link

Also waiting for a fix on this

@julieerle
Copy link
Contributor

I was able to deploy the azurerm_linux_web_app (code below).

resource "azurerm_linux_web_app" "example" {
  name                = "example"
  resource_group_name = azurerm_resource_group.example.name
  location            = azurerm_service_plan.example.location
  service_plan_id     = azurerm_service_plan.example.id

  site_config {
    application_stack {
        java_version = "11.0.13"
    }
  }
}
  • Output: Apply complete! Resources: 1 added, 0 changed, 0 destroyed.

  • Unexpectedly, my state file shows "java_version": "",

  • Unexpectedly, Azure Portal shows "javaVersion": null,

@jb68
Copy link
Author

jb68 commented Jan 23, 2023

I was able to deploy the azurerm_linux_web_app (code below).

  site_config {
    application_stack {
        java_version = "11.0.13"

@julieerle Try java_version = "11"

@jb68
Copy link
Author

jb68 commented Jan 24, 2023

@xiaxyi , I did some tests and after the app is updated through the web here is the diff between terraform and guy based on
az functionapp config show
The first one is terraform, second is gui, rest are identical.

73,75c73,75
<   "javaContainer": null,
<   "javaContainerVersion": null,
<   "javaVersion": null,
---
>   "javaContainer": "",
>   "javaContainerVersion": "",
>   "javaVersion": "11",

If I am doing
az functionapp config set --name <name> -g <rg> --java-version 17 will fix it and will also change those 2 other records from null to empty string.

@jb68
Copy link
Author

jb68 commented Jan 24, 2023

I did more tests:

resource "azurerm_linux_web_app" "jb_fapp" {
  name                = "jbfaap01"
  resource_group_name        = data.azurerm_resource_group.backend.name
  location                   = data.azurerm_resource_group.backend.location
  service_plan_id            = azurerm_service_plan.asplan.id
  https_only                 = true
  app_settings = {
  }
  site_config {
    application_stack {
        java_version = "11"
    }
    cors {
      allowed_origins     = [ "https://portal.azure.com",  ]
      support_credentials = false
    }
  }

will create an app service with no stack. If we change azurerm_linux_web_app to azurerm_windows_function_app and adding storage will produce a Custom function runtime, a java stack with no Java Version

@xiaxyi
Copy link
Contributor

xiaxyi commented Jan 31, 2023

@jb68 Have you tried to also include JavaServer and JavaServerVersion together with the existed java_version in your TF config and try again? Example:

site_config {
    application_stack {
      java_version        = "11"
      java_server         = "JAVA"
      java_server_version = "11"
    }
  }

@UteHaus
Copy link

UteHaus commented Jan 31, 2023

I try it for a test, but it not works as recommended.

│ Error: Unsupported argument
│ 
│   on [functionapp-client-api.tf](http://functionapp-client-api.tf/) line 241, in resource "azurerm_windows_function_app" "functionapp-clientapi":
│  241:       java_server         = "JAVA"
│ 
│ An argument named "java_server" is not expected here.
╵
╷
│ Error: Unsupported argument
│ 
│   on [functionapp-client-api.tf](http://functionapp-client-api.tf/) line 242, in resource "azurerm_windows_function_app" "functionapp-clientapi":
│  242:       java_server_version = "11"
│ 
│ An argument named "java_server_version" is not expected here.
╵

@xiaxyi
Copy link
Contributor

xiaxyi commented Feb 1, 2023

@UteHaus may I know the provider version you used? Those properties were just introduced, so you may need to try the latest provider.

@UteHaus
Copy link

UteHaus commented Feb 2, 2023

Currently I use the following versions:

  • hashicorp/azurerm v3.41.0
  • hashicorp/azuread v2.33.0

@jb68
Copy link
Author

jb68 commented Feb 3, 2023

@xiaxyi I will give it a try,
I also came with a workaround, is not perfect because requires az and jq to work in the env you run terraform and it will set the version on every read ( aka plan ) but hey, it works. LOL

data "external" "fapp_set_java_version" {
  # workaround against https://github.com/hashicorp/terraform-provider-azurerm/issues/17173
  # please note that this block is executed as a read so even on "plan" will still be executed
  count = length(var.function_apps)
  depends_on = [
     azurerm_windows_function_app.function_app
  ]
  program = [
    # output of "program" needs to be a json that contains only keys -> string values  Ex: { "a" = "b", "c" = "d" }; jq will output a minimal json
    "/bin/bash", "-c", "az functionapp config set -g ${data.azurerm_resource_group.backend.name} -n fappname-${var.function_apps[count.index]} --java-version 11 | jq -r '{\"javaVersion\" : .javaVersion}'"
  ]
}

@github-actions
Copy link

This functionality has been released in v3.49.0 of the Terraform Provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you!

@github-actions
Copy link

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.