Skip to content

Commit

Permalink
azurerm_windows_web_app_slot - FIX node version reset to "0.12.1"…
Browse files Browse the repository at this point in the history
… during update (#25489)

* fix(azurerm_windows_web_app_slot): correctly set NodeJS & app settings properties

* ref(windows_web_app_slot): Resolve comments (part 1)

* tests(windows_web_app_slot): Cover update to avoid regression removal version

* ref(windows_web_app_slot): Resolve comment

* ref(windows_web_app_slot): Resolve comment (last)

* fix(lint): Replace "tab" by "spaces" in acceptance test block
  • Loading branch information
Apokalypt committed Apr 18, 2024
1 parent 29e2a60 commit 95bfb3a
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 2 deletions.
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

0 comments on commit 95bfb3a

Please sign in to comment.