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_windows_web_app, azurerm_windows_web_app_slot - add node 18 support and fix node version not being set issue. #19343

Closed
wants to merge 1 commit 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
2 changes: 2 additions & 0 deletions internal/services/appservice/helpers/web_app_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -949,6 +949,7 @@ func windowsApplicationStackSchema() *pluginsdk.Schema {
"12-LTS",
"14-LTS",
"16-LTS",
"18-LTS",
}, false),
AtLeastOneOf: []string{
"site_config.0.application_stack.0.docker_container_name",
Expand Down Expand Up @@ -1225,6 +1226,7 @@ func linuxApplicationStackSchema() *pluginsdk.Schema {
"12-lts",
"14-lts",
"16-lts",
"18-lts",
}, false),
AtLeastOneOf: []string{
"site_config.0.application_stack.0.docker_image",
Expand Down
7 changes: 7 additions & 0 deletions internal/services/appservice/windows_web_app_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,13 @@ func (d WindowsWebAppDataSource) Read() sdk.ResourceFunc {

var healthCheckCount *int
webApp.AppSettings, healthCheckCount = helpers.FlattenAppSettings(appSettings)

// Remove node version if not set by user explicitly
appSettingRawData := metadata.ResourceData.Get("app_settings").(map[string]interface{})
if appSettingRawData["WEBSITE_NODE_DEFAULT_VERSION"] == nil && webApp.AppSettings["WEBSITE_NODE_DEFAULT_VERSION"] != "" {
delete(webApp.AppSettings, "WEBSITE_NODE_DEFAULT_VERSION")
}

webApp.Kind = utils.NormalizeNilableString(existing.Kind)
webApp.Location = location.NormalizeNilable(existing.Location)
webApp.Tags = tags.ToTypedObject(existing.Tags)
Expand Down
39 changes: 36 additions & 3 deletions internal/services/appservice/windows_web_app_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,21 @@ func (r WindowsWebAppResource) Create() sdk.ResourceFunc {
return err
}

siteConfig.AppSettings = helpers.ExpandAppSettingsForCreate(webApp.AppSettings)
// for node app, we need to add the key WEBSITE_NODE_DEFAULT_VERSION in app_setting for windows web app.
appSetting := make(map[string]string)
if webApp.AppSettings != nil {
appSetting = webApp.AppSettings
}
if currentStack != nil && *currentStack == "node" {
nodeKey := "WEBSITE_NODE_DEFAULT_VERSION"
nodeVersion := ""
if siteConfig.NodeVersion != nil {
nodeVersion = "~" + strings.TrimSuffix(*siteConfig.NodeVersion, "-LTS")
}
appSetting[nodeKey] = nodeVersion
}

siteConfig.AppSettings = helpers.ExpandAppSettingsForCreate(appSetting)

expandedIdentity, err := expandIdentity(metadata.ResourceData.Get("identity").([]interface{}))
if err != nil {
Expand Down Expand Up @@ -355,7 +369,7 @@ func (r WindowsWebAppResource) Create() sdk.ResourceFunc {
}
}

appSettings := helpers.ExpandAppSettingsForUpdate(webApp.AppSettings)
appSettings := helpers.ExpandAppSettingsForUpdate(appSetting)
if appSettings != nil {
if _, err := client.UpdateApplicationSettings(ctx, id.ResourceGroup, id.SiteName, *appSettings); err != nil {
return fmt.Errorf("setting App Settings for Windows %s: %+v", id, err)
Expand Down Expand Up @@ -541,6 +555,12 @@ func (r WindowsWebAppResource) Read() sdk.ResourceFunc {
var healthCheckCount *int
state.AppSettings, healthCheckCount = helpers.FlattenAppSettings(appSettings)

// Remove node version if not set by user explicitly
appSettingRawData := metadata.ResourceData.Get("app_settings").(map[string]interface{})
if appSettingRawData["WEBSITE_NODE_DEFAULT_VERSION"] == nil && state.AppSettings["WEBSITE_NODE_DEFAULT_VERSION"] != "" {
delete(state.AppSettings, "WEBSITE_NODE_DEFAULT_VERSION")
}

if v := props.OutboundIPAddresses; v != nil {
state.OutboundIPAddresses = *v
state.OutboundIPAddressList = strings.Split(*v, ",")
Expand Down Expand Up @@ -705,11 +725,19 @@ func (r WindowsWebAppResource) Update() sdk.ResourceFunc {
currentStack = stateConfig.ApplicationStack[0].CurrentStack
}

addNodeVersion := false
nodeVersion := ""
if metadata.ResourceData.HasChange("site_config") || servicePlanChange {
siteConfig, stack, err := helpers.ExpandSiteConfigWindows(state.SiteConfig, existing.SiteConfig, metadata, servicePlan)
if err != nil {
return fmt.Errorf("expanding Site Config for Windows %s: %+v", id, err)
}
if *stack == "node" {
addNodeVersion = true
if siteConfig.NodeVersion != nil {
nodeVersion = *siteConfig.NodeVersion
}
}
currentStack = *stack
existing.SiteConfig = siteConfig
}
Expand All @@ -729,7 +757,12 @@ func (r WindowsWebAppResource) Update() sdk.ResourceFunc {
}

// (@jackofallops) - App Settings can clobber logs configuration so must be updated before we send any Log updates
if metadata.ResourceData.HasChange("app_settings") {
if metadata.ResourceData.HasChange("app_settings") || addNodeVersion {
if addNodeVersion {
nodeKey := "WEBSITE_NODE_DEFAULT_VERSION"
nodeVersion = "~" + strings.TrimSuffix(nodeVersion, "-LTS")
state.AppSettings[nodeKey] = nodeVersion
}
appSettingsUpdate := helpers.ExpandAppSettingsForUpdate(state.AppSettings)
if _, err := client.UpdateApplicationSettings(ctx, id.ResourceGroup, id.SiteName, *appSettingsUpdate); err != nil {
return fmt.Errorf("updating App Settings for Windows %s: %+v", id, err)
Expand Down
37 changes: 35 additions & 2 deletions internal/services/appservice/windows_web_app_slot_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,21 @@ func (r WindowsWebAppSlotResource) Create() sdk.ResourceFunc {
return err
}

siteConfig.AppSettings = helpers.ExpandAppSettingsForCreate(webAppSlot.AppSettings)
// for node app, we need to add the key WEBSITE_NODE_DEFAULT_VERSION in app_setting for windows web app.
appSetting := make(map[string]string)
if webAppSlot.AppSettings != nil {
appSetting = webAppSlot.AppSettings
}
if currentStack != nil && *currentStack == "node" {
nodeKey := "WEBSITE_NODE_DEFAULT_VERSION"
nodeVersion := ""
if siteConfig.NodeVersion != nil {
nodeVersion = "~" + strings.TrimSuffix(*siteConfig.NodeVersion, "-LTS")
}
appSetting[nodeKey] = nodeVersion
}

siteConfig.AppSettings = helpers.ExpandAppSettingsForCreate(appSetting)

expandedIdentity, err := expandIdentity(metadata.ResourceData.Get("identity").([]interface{}))
if err != nil {
Expand Down Expand Up @@ -312,7 +326,7 @@ func (r WindowsWebAppSlotResource) Create() sdk.ResourceFunc {
}
}

appSettings := helpers.ExpandAppSettingsForUpdate(webAppSlot.AppSettings)
appSettings := helpers.ExpandAppSettingsForUpdate(appSetting)
if appSettings != nil {
if _, err := client.UpdateApplicationSettingsSlot(ctx, id.ResourceGroup, id.SiteName, *appSettings, id.SlotName); err != nil {
return fmt.Errorf("setting App Settings for Windows %s: %+v", id, err)
Expand Down Expand Up @@ -479,6 +493,12 @@ func (r WindowsWebAppSlotResource) Read() sdk.ResourceFunc {
var healthCheckCount *int
state.AppSettings, healthCheckCount = helpers.FlattenAppSettings(appSettings)

// Remove node version if not set by user explicitly
appSettingRawData := metadata.ResourceData.Get("app_settings").(map[string]interface{})
if appSettingRawData["WEBSITE_NODE_DEFAULT_VERSION"] == nil && state.AppSettings["WEBSITE_NODE_DEFAULT_VERSION"] != "" {
delete(state.AppSettings, "WEBSITE_NODE_DEFAULT_VERSION")
}

if v := props.OutboundIPAddresses; v != nil {
state.OutboundIPAddresses = *v
state.OutboundIPAddressList = strings.Split(*v, ",")
Expand Down Expand Up @@ -605,11 +625,19 @@ func (r WindowsWebAppSlotResource) Update() sdk.ResourceFunc {
currentStack = stateConfig.ApplicationStack[0].CurrentStack
}

addNodeVersion := false
nodeVersion := ""
if metadata.ResourceData.HasChange("site_config") {
siteConfig, stack, err := helpers.ExpandSiteConfigWindowsWebAppSlot(state.SiteConfig, existing.SiteConfig, metadata)
if err != nil {
return fmt.Errorf("expanding Site Config for Windows %s: %+v", id, err)
}
if *stack == "node" {
addNodeVersion = true
if siteConfig.NodeVersion != nil {
nodeVersion = *siteConfig.NodeVersion
}
}
currentStack = *stack
existing.SiteConfig = siteConfig
}
Expand Down Expand Up @@ -643,6 +671,11 @@ func (r WindowsWebAppSlotResource) Update() sdk.ResourceFunc {

// (@jackofallops) - App Settings can clobber logs configuration so must be updated before we send any Log updates
if metadata.ResourceData.HasChange("app_settings") {
if addNodeVersion {
nodeKey := "WEBSITE_NODE_DEFAULT_VERSION"
nodeVersion = "~" + strings.TrimSuffix(nodeVersion, "-LTS")
state.AppSettings[nodeKey] = nodeVersion
}
appSettingsUpdate := helpers.ExpandAppSettingsForUpdate(state.AppSettings)
if _, err := client.UpdateApplicationSettingsSlot(ctx, id.ResourceGroup, id.SiteName, *appSettingsUpdate, id.SlotName); err != nil {
return fmt.Errorf("updating App Settings for Windows %s: %+v", id, err)
Expand Down
2 changes: 1 addition & 1 deletion website/docs/r/linux_web_app.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ An `application_stack` block supports the following:

~> **NOTE:** The valid version combinations for `java_version`, `java_server` and `java_server_version` can be checked from the command line via `az webapp list-runtimes --linux`.

* `node_version` - (Optional) The version of Node to run. Possible values include `12-lts`, `14-lts`, and `16-lts`. This property conflicts with `java_version`.
* `node_version` - (Optional) The version of Node to run. Possible values include `12-lts`, `14-lts`, `16-lts` and `18-lts`. This property conflicts with `java_version`.

~> **NOTE:** 10.x versions have been/are being deprecated so may cease to work for new resources in the future and may be removed from the provider.

Expand Down
2 changes: 1 addition & 1 deletion website/docs/r/linux_web_app_slot.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ An `application_stack` block supports the following:

~> **NOTE:** The valid version combinations for `java_version`, `java_server` and `java_server_version` can be checked from the command line via `az webapp list-runtimes --linux`.

* `node_version` - (Optional) The version of Node to run. Possible values include `12-lts`, `14-lts`, and `16-lts`. This property conflicts with `java_version`.
* `node_version` - (Optional) The version of Node to run. Possible values include `12-lts`, `14-lts`, `16-lts` and `18-lts`. This property conflicts with `java_version`.

~> **NOTE:** 10.x versions have been/are being deprecated so may cease to work for new resources in the future and may be removed from the provider.

Expand Down
2 changes: 1 addition & 1 deletion website/docs/r/windows_web_app.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ An `application_stack` block supports the following:

~> **NOTE:** For compatible combinations of `java_version`, `java_container` and `java_container_version` users can use `az webapp list-runtimes` from command line.

* `node_version` - (Optional) The version of node to use when `current_stack` is set to `node`. Possible values include `12-LTS`, `14-LTS`, and `16-LTS`.
* `node_version` - (Optional) The version of node to use when `current_stack` is set to `node`. Possible values include `12-LTS`, `14-LTS`, `16-LTS` and `18-LTS`.

~> **NOTE:** This property conflicts with `java_version`.

Expand Down
2 changes: 1 addition & 1 deletion website/docs/r/windows_web_app_slot.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ A `application_stack` block supports the following:

~> **NOTE:** For compatible combinations of `java_version`, `java_container` and `java_container_version` users can use `az webapp list-runtimes` from command line.

* `node_version` - (Optional) The version of node to use when `current_stack` is set to `node`. Possible values include `12-LTS`, `14-LTS`, and `16-LTS`.
* `node_version` - (Optional) The version of node to use when `current_stack` is set to `node`. Possible values include `12-LTS`, `14-LTS`, `16-LTS` and `18-LTS`.

~> **NOTE:** This property conflicts with `java_version`.

Expand Down