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_slot - FIX node version reset to "0.12.1" during update #25489

Merged
merged 6 commits into from Apr 18, 2024
3 changes: 2 additions & 1 deletion internal/services/appservice/helpers/web_app_slot_schema.go
Expand Up @@ -1153,7 +1153,8 @@ func (s *SiteConfigWindowsWebAppSlot) ExpandForUpdate(metadata sdk.ResourceMetaD

if len(s.ApplicationStack) == 1 {
winAppStack := s.ApplicationStack[0]
if metadata.ResourceData.HasChange("site_config.0.application_stack.0.node_version") {

if metadata.ResourceData.HasChange("site_config.0.application_stack.0.node_version") || winAppStack.NodeVersion != "" {
if appSettings == nil {
appSettings = make(map[string]string)
}
Expand Down
Expand Up @@ -896,7 +896,7 @@ 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.HasChanges("app_settings", "site_config") || metadata.ResourceData.HasChange("site_config.0.health_check_eviction_time_in_min") || metadata.ResourceData.HasChange("site_config.0.application_stack.0.node_version") {
if metadata.ResourceData.HasChanges("app_settings", "site_config") || metadata.ResourceData.HasChange("site_config.0.health_check_eviction_time_in_min") {
appSettingsUpdate := helpers.ExpandAppSettingsForUpdate(model.Properties.SiteConfig.AppSettings)
appSettingsProps := *appSettingsUpdate.Properties
appSettingsProps["WEBSITE_HEALTHCHECK_MAXPINGFAILURES"] = strconv.Itoa(int(state.SiteConfig[0].HealthCheckEvictionTime))
Expand Down
59 changes: 59 additions & 0 deletions internal/services/appservice/windows_web_app_slot_resource_test.go
Expand Up @@ -784,6 +784,14 @@ func TestAccWindowsWebAppSlot_withNode12(t *testing.T) {
),
},
data.ImportStep("site_credential.0.password"),
{
Config: r.nodeWithAppSettings(data, "~12"),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("site_config.0.application_stack.0.node_version").HasValue("~12"),
),
},
data.ImportStep("site_credential.0.password"),
})
}

Expand All @@ -799,6 +807,14 @@ func TestAccWindowsWebAppSlot_withNode14(t *testing.T) {
),
},
data.ImportStep("site_credential.0.password"),
{
Config: r.nodeWithAppSettings(data, "~14"),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("site_config.0.application_stack.0.node_version").HasValue("~14"),
),
},
data.ImportStep("site_credential.0.password"),
})
}

Expand All @@ -814,6 +830,14 @@ func TestAccWindowsWebAppSlot_withNode18(t *testing.T) {
),
},
data.ImportStep("site_credential.0.password"),
{
Config: r.nodeWithAppSettings(data, "~18"),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("site_config.0.application_stack.0.node_version").HasValue("~18"),
),
},
data.ImportStep("site_credential.0.password"),
})
}

Expand All @@ -829,6 +853,14 @@ func TestAccWindowsWebAppSlot_withNode20(t *testing.T) {
),
},
data.ImportStep("site_credential.0.password"),
{
Config: r.nodeWithAppSettings(data, "~20"),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("site_config.0.application_stack.0.node_version").HasValue("~20"),
),
},
data.ImportStep("site_credential.0.password"),
})
}

Expand Down Expand Up @@ -2035,6 +2067,33 @@ resource "azurerm_windows_web_app_slot" "test" {
}
}

`, r.baseTemplate(data), data.RandomInteger, nodeVersion)
}

func (r WindowsWebAppSlotResource) nodeWithAppSettings(data acceptance.TestData, nodeVersion string) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}

%s

resource "azurerm_windows_web_app_slot" "test" {
name = "acctestWAS-%d"
app_service_id = azurerm_windows_web_app.test.id

app_settings = {
"foo" = "bar"
}

site_config {
application_stack {
node_version = "%s"
}
}
}


`, r.baseTemplate(data), data.RandomInteger, nodeVersion)
}

Expand Down