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

azure function os_type linux doesn't work #6931

Closed
imduchy opened this issue May 14, 2020 · 5 comments · Fixed by #7140
Closed

azure function os_type linux doesn't work #6931

imduchy opened this issue May 14, 2020 · 5 comments · Fixed by #7140
Labels
service/functions Function Apps
Milestone

Comments

@imduchy
Copy link
Contributor

imduchy commented May 14, 2020

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 (and AzureRM Provider) Version

Terraform v0.12.25

Affected Resource(s)

  • azurerm_function_app

Terraform Configuration Files

provider "azurerm" {
  version = "2.9.0"
}

...

resource "azurerm_app_service_plan" "asp-myasp" {
  name                = "ASP-myasp-${var.environment}-1"
  location            = var.location
  resource_group_name = var.resource_group_name
  kind                = "FunctionApp"

  sku {
    tier = "Dynamic"
    size = "Y1"
  }

  timeouts {}
}

resource "azurerm_function_app" "fa-myfunction" {
  name                      = var.name
  location                  = var.location
  resource_group_name       = var.resource_group_name
  app_service_plan_id       = azurerm_app_service_plan.asp-myasp.id
  storage_connection_string = azurerm_storage_account.sa-mystorage.primary_connection_string
  version                   = "~2"
  os_type                   = "linux"

  app_settings = {
    WEBSITE_RUN_FROM_PACKAGE       = ""
    FUNCTIONS_WORKER_RUNTIME       = "node"
    APPINSIGHTS_INSTRUMENTATIONKEY = ""
    WEBSITE_NODE_DEFAULT_VERSION   = "10.4.1"
  }
}

Debug Output

https://gist.github.com/Duchynko/13f2c854e3ce374e340628cecaaa6285

Panic Output

Expected Behavior

(1.) Function App should be created as functionapp,linux
2. Function App shouldn't be recreated on every apply run

Actual Behavior

Function App is being created as Windows app and therefore is forced to be recreated every time I run terraform apply

Steps to Reproduce

  1. terraform apply

Important Factoids

References

  • #0000
@imduchy
Copy link
Contributor Author

imduchy commented May 15, 2020

Alright so I managed to create a functionapp,linux by:
setting azurerm_app_service_plan.kind to Linux and reserved to true

but now I have a problem that every time I run apply it's trying to recreate the service plan just as mentioned in #5971

Terraform will perform the following actions:

  # module.factoryone_graphql_function.azurerm_app_service_plan.asp-factoryone must be replaced
-/+ resource "azurerm_app_service_plan" "xxxxxx" {
      ~ id                           = "/subscriptions/xxxxx/resourceGroups/xxxxxx-staging/providers/Microsoft.Web/serverfarms/xxxxxxxx" -> (known after apply)
      - is_xenon                     = false -> null
      ~ kind                         = "functionapp" -> "Linux" # forces replacement
        location                     = "westeurope"
        reserved                     = true
        ....

      ~ sku {
          ~ capacity = 0 -> (known after apply)
            size     = "Y1"
            tier     = "Dynamic"
        }

        timeouts {}
    }

  # module.xxxxxx.azurerm_function_app.xxxxxxx will be updated in-place
  ~ resource "azurerm_function_app" "xxxxx" {
      ~ app_service_plan_id            = "/subscriptions/xxxxxxx/resourceGroups/factory-one-staging/providers/Microsoft.Web/serverfarms/xxxxxx" -> (known after apply)
        app_settings                   = {
            "APPINSIGHTS_INSTRUMENTATIONKEY" = ""
            "FUNCTIONS_WORKER_RUNTIME"       = "node"
            "WEBSITE_NODE_DEFAULT_VERSION"   = "10.4.1"
            "WEBSITE_RUN_FROM_PACKAGE"       = ""
        }
        kind                           = "functionapp,linux"
        location                       = "westeurope"
        os_type                        = "linux"
        version                        = "~2"
        ....
        }
    }

Plan: 1 to add, 1 to change, 1 to destroy.

@mybayern1974 mybayern1974 added the service/functions Function Apps label May 15, 2020
@imduchy
Copy link
Contributor Author

imduchy commented May 15, 2020

Another finding. If I change app_service_plan.kind from Linux to FunctionApp after everything is deployed and I keep reserved = true, everything seems to work fine.

This is however just a workaround and I believe should be fixed and documented.

@katbyte katbyte added this to the v2.13.0 milestone May 30, 2020
katbyte pushed a commit that referenced this issue May 30, 2020
There is a typo in the code where osType is "Linux" instead of "linux". The format does not match with checks and other parts of the code such as in row 354.

Current behaviour causes the function app to be generated as Windows despite the value of os_type. This fixes #6931 for example.
@markusleh
Copy link
Contributor

markusleh commented May 31, 2020

I submitted a pull request which I thought would fix this. However, the real problem still persists.

The issue is that there are checks to verify that reserved is set to true when using kind = "Linux" but not when using kind = "FunctionApp".

Perhaps there should be alternative option to specify something like kind = "FunctionApp,Linux" where reserved = True is automatically set? Another option would be to cross-check that the app service plan has kind = linux and when creating a function.

Here is the full working configuration:

...
resource "azurerm_app_service_plan" "example" {
  name                = "azure-functions-test-service-plan"
  location            = azurerm_resource_group.example.location
  resource_group_name = azurerm_resource_group.example.name
  kind                = "FunctionApp"
  reserved            = true

  sku {
    tier = "Dynamic"
    size = "Y1"
  }
}

resource "azurerm_function_app" "example" {
  name                      = "test-azure-functions"
  location                  = azurerm_resource_group.example.location
  resource_group_name       = azurerm_resource_group.example.name
  app_service_plan_id       = azurerm_app_service_plan.example.id
  storage_connection_string = azurerm_storage_account.example.primary_connection_string
  os_type                   = "linux"
}

I am making another pull request with a working example for the documentation at least.

markusleh added a commit to markusleh/terraform-provider-azurerm that referenced this issue May 31, 2020
I added documentation about specific arguments to use when deploying a linux function app. 
There is currently also checks missing that the azurerm_app_service_plan should also have `reserved=true` specifically when linked to linux function apps. Note added here, but the check should also be added. See hashicorp#6931 for more details.
katbyte pushed a commit that referenced this issue Jun 1, 2020
I added documentation about specific arguments to use when deploying a linux function app. 
There is currently also checks missing that the azurerm_app_service_plan should also have `reserved=true` specifically when linked to linux function apps. Note added here, but the check should also be added. See #6931 for more details.
@ghost
Copy link

ghost commented Jun 4, 2020

This has been released in version 2.13.0 of the provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading. As an example:

provider "azurerm" {
    version = "~> 2.13.0"
}
# ... other configuration ...

@ghost
Copy link

ghost commented Jun 30, 2020

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 feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 [email protected]. Thanks!

@ghost ghost locked and limited conversation to collaborators Jun 30, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
service/functions Function Apps
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants