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

azurerm_logic_app_standard - add default values to worker runtime #18178

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 49 additions & 1 deletion internal/services/logic/logic_app_standard_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,8 @@ func resourceLogicAppStandardCreate(d *pluginsdk.ResourceData, meta interface{})
appSettings := expandAppSettings(d)
appSettings = append(appSettings, basicAppSettings...)

appSettings = addDefaultWorkerRuntime(d, appSettings)

siteConfig.AppSettings = &appSettings

siteEnvelope := web.Site{
Expand Down Expand Up @@ -1247,7 +1249,7 @@ func expandLogicAppStandardSettings(d *pluginsdk.ResourceData, endpointSuffix st
if err != nil {
return nil, err
}
for _, p := range append(basicAppSettings, appSettings...) {
for _, p := range addDefaultWorkerRuntime(d, append(basicAppSettings, appSettings...)) {
output[*p.Name] = p.Value
}

Expand Down Expand Up @@ -1412,3 +1414,49 @@ func expandHeaders(input interface{}) map[string][]string {

return output
}

func addDefaultWorkerRuntime(d *pluginsdk.ResourceData, appSettings []web.NameValuePair) []web.NameValuePair {
functionVersion := d.Get("version").(string)
functionWorkerRuntimeName := "FUNCTIONS_WORKER_RUNTIME"
nodeDefaultVersionName := "WEBSITE_NODE_DEFAULT_VERSION"
functionWorkerRuntime, nodeDefaultVersion := expandWorkerRuntime(functionVersion)

appSettings = appendIfNotExist(appSettings, web.NameValuePair{Name: &functionWorkerRuntimeName, Value: &functionWorkerRuntime})
appSettings = appendIfNotExist(appSettings, web.NameValuePair{Name: &nodeDefaultVersionName, Value: &nodeDefaultVersion})

return appSettings
}

func appendIfNotExist(appSettings []web.NameValuePair, toAddSettings web.NameValuePair) []web.NameValuePair {
exist := false
for _, pair := range appSettings {
if pair != nil && *pair.Name == *toAddSettings.Name {
exist = true
}
}
if !exist {
appSettings = append(appSettings, toAddSettings)
}
return appSettings
}

func expandWorkerRuntime(version string) (worker string, nodeVersion string) {
switch version {
case "~1":
{
worker = "node"
nodeVersion = "~6"
}
case "~2":
{
worker = "node"
nodeVersion = "~8"
}
case "~3":
{
worker = "node"
nodeVersion = "~14"
}
}
return
}
17 changes: 17 additions & 0 deletions internal/services/logic/logic_app_standard_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,23 @@ func TestAccLogicAppStandard_appSettingsVnetRouteAllEnabled(t *testing.T) {
})
}

func TestAccLogicAppStandard_appSettingsWorkerRuntime(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_logic_app_standard", "test")
r := LogicAppStandardResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.basic(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("app_settings.FUNCTIONS_WORKER_RUNTIME").HasValue("node"),
check.That(data.ResourceName).Key("app_settings.WEBSITE_NODE_DEFAULT_VERSION").HasValue("~14"),
),
},
data.ImportStep(),
})
}

func TestAccLogicAppStandard_requiresImport(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_logic_app_standard", "test")
r := LogicAppStandardResource{}
Expand Down
4 changes: 3 additions & 1 deletion website/docs/r/logic_app_standard.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,9 @@ The following arguments are supported:

* `app_settings` - (Optional) A map of key-value pairs for [App Settings](https://docs.microsoft.com/azure/azure-functions/functions-app-settings) and custom values.

~> **NOTE:** There are a number of application settings that will be managed for you by this resource type and *shouldn't* be configured separately as part of the app_settings you specify. `AzureWebJobsStorage` is filled based on `storage_account_name` and `storage_account_access_key`. `WEBSITE_CONTENTSHARE` is detailed below. `FUNCTIONS_EXTENSION_VERSION` is filled based on `version`. `APP_KIND` is set to workflowApp and `AzureFunctionsJobHost__extensionBundle__id` and `AzureFunctionsJobHost__extensionBundle__version` are set as detailed below.
~> **NOTE:** There are a number of application settings that will be managed for you by this resource type and *shouldn't* be configured separately as part of the app_settings you specify. `AzureWebJobsStorage` is filled based on `storage_account_name` and `storage_account_access_key`. `WEBSITE_CONTENTSHARE` is detailed below. `FUNCTIONS_EXTENSION_VERSION` is filled based on `version`. `APP_KIND` is set to workflowApp and `AzureFunctionsJobHost__extensionBundle__id` and `AzureFunctionsJobHost__extensionBundle__version` are set as detailed below..

~> **NOTE:** There are a number of application settings wil be set to default value if not specified. `FUNCTIONS_WORKER_RUNTIME` is set to `node`, `WEBSITE_NODE_DEFAULT_VERSION` application settings will be set to default value based on `version` if not specified.

* `use_extension_bundle` - (Optional) Should the logic app use the bundled extension package? If true, then application settings for `AzureFunctionsJobHost__extensionBundle__id` and `AzureFunctionsJobHost__extensionBundle__version` will be created. Default true

Expand Down