From fc599002d2c56452c449a64d140533d44f35028c Mon Sep 17 00:00:00 2001 From: jackofallops Date: Mon, 18 Sep 2023 16:09:15 +0200 Subject: [PATCH] fix docker update settings and add test coverage --- .../helpers/linux_web_app_schema.go | 5 ++++ .../appservice/helpers/web_app_slot_schema.go | 27 ++++++++++++++++--- .../appservice/linux_web_app_resource_test.go | 24 +++++++++++++++++ .../linux_web_app_slot_resource_test.go | 24 +++++++++++++++++ .../windows_web_app_resource_test.go | 8 ++++++ .../windows_web_app_slot_resource_test.go | 4 +-- 6 files changed, 87 insertions(+), 5 deletions(-) diff --git a/internal/services/appservice/helpers/linux_web_app_schema.go b/internal/services/appservice/helpers/linux_web_app_schema.go index 646a4f7c6724..4b367f02898a 100644 --- a/internal/services/appservice/helpers/linux_web_app_schema.go +++ b/internal/services/appservice/helpers/linux_web_app_schema.go @@ -936,6 +936,9 @@ func (s *SiteConfigLinux) ExpandForUpdate(metadata sdk.ResourceMetaData, existin if linuxAppStack.DockerImageName != "" { expanded.LinuxFxVersion = pointer.To(EncodeDockerFxString(linuxAppStack.DockerImageName, linuxAppStack.DockerRegistryUrl)) + if appSettings == nil { + appSettings = map[string]string{} + } appSettings["DOCKER_REGISTRY_SERVER_URL"] = linuxAppStack.DockerRegistryUrl appSettings["DOCKER_REGISTRY_SERVER_USERNAME"] = linuxAppStack.DockerRegistryUsername appSettings["DOCKER_REGISTRY_SERVER_PASSWORD"] = linuxAppStack.DockerRegistryPassword @@ -945,6 +948,8 @@ func (s *SiteConfigLinux) ExpandForUpdate(metadata sdk.ResourceMetaData, existin } } + expanded.AppSettings = ExpandAppSettingsForCreate(appSettings) + if metadata.ResourceData.HasChange("site_config.0.container_registry_managed_identity_client_id") { expanded.AcrUserManagedIdentityID = pointer.To(s.ContainerRegistryMSI) } diff --git a/internal/services/appservice/helpers/web_app_slot_schema.go b/internal/services/appservice/helpers/web_app_slot_schema.go index e521cb96a7f6..b4140bd7fa60 100644 --- a/internal/services/appservice/helpers/web_app_slot_schema.go +++ b/internal/services/appservice/helpers/web_app_slot_schema.go @@ -619,6 +619,11 @@ func (s *SiteConfigLinuxWebAppSlot) ExpandForCreate(appSettings map[string]strin if linuxAppStack.DockerImageName != "" { expanded.LinuxFxVersion = pointer.To(EncodeDockerFxString(linuxAppStack.DockerImageName, linuxAppStack.DockerRegistryUrl)) + + if appSettings == nil { + appSettings = make(map[string]string) + } + appSettings["DOCKER_REGISTRY_SERVER_URL"] = linuxAppStack.DockerRegistryUrl appSettings["DOCKER_REGISTRY_SERVER_USERNAME"] = linuxAppStack.DockerRegistryUsername appSettings["DOCKER_REGISTRY_SERVER_PASSWORD"] = linuxAppStack.DockerRegistryPassword @@ -748,6 +753,11 @@ func (s *SiteConfigLinuxWebAppSlot) ExpandForUpdate(metadata sdk.ResourceMetaDat if linuxAppStack.DockerImageName != "" { expanded.LinuxFxVersion = pointer.To(EncodeDockerFxString(linuxAppStack.DockerImageName, linuxAppStack.DockerRegistryUrl)) + + if appSettings == nil { + appSettings = make(map[string]string) + } + appSettings["DOCKER_REGISTRY_SERVER_URL"] = linuxAppStack.DockerRegistryUrl appSettings["DOCKER_REGISTRY_SERVER_USERNAME"] = linuxAppStack.DockerRegistryUsername appSettings["DOCKER_REGISTRY_SERVER_PASSWORD"] = linuxAppStack.DockerRegistryPassword @@ -756,6 +766,7 @@ func (s *SiteConfigLinuxWebAppSlot) ExpandForUpdate(metadata sdk.ResourceMetaDat expanded.LinuxFxVersion = pointer.To("") } } + expanded.AppSettings = ExpandAppSettingsForCreate(appSettings) if metadata.ResourceData.HasChange("site_config.0.auto_swap_slot_name") { expanded.AutoSwapSlotName = pointer.To(s.AutoSwapSlotName) @@ -1028,15 +1039,19 @@ func (s *SiteConfigWindowsWebAppSlot) ExpandForCreate(appSettings map[string]str if winAppStack.DockerImageName != "" { expanded.WindowsFxVersion = pointer.To(EncodeDockerFxStringWindows(winAppStack.DockerImageName, winAppStack.DockerRegistryUrl)) + + if appSettings == nil { + appSettings = make(map[string]string) + } + appSettings["DOCKER_REGISTRY_SERVER_URL"] = winAppStack.DockerRegistryUrl appSettings["DOCKER_REGISTRY_SERVER_USERNAME"] = winAppStack.DockerRegistryUsername appSettings["DOCKER_REGISTRY_SERVER_PASSWORD"] = winAppStack.DockerRegistryPassword - } - } else { expanded.WindowsFxVersion = pointer.To("") } + expanded.AppSettings = ExpandAppSettingsForCreate(appSettings) if s.AutoSwapSlotName != "" { expanded.AutoSwapSlotName = pointer.To(s.AutoSwapSlotName) @@ -1165,10 +1180,14 @@ func (s *SiteConfigWindowsWebAppSlot) ExpandForUpdate(metadata sdk.ResourceMetaD if winAppStack.DockerImageName != "" { expanded.WindowsFxVersion = pointer.To(EncodeDockerFxStringWindows(winAppStack.DockerImageName, winAppStack.DockerRegistryUrl)) + + if appSettings == nil { + appSettings = make(map[string]string) + } + appSettings["DOCKER_REGISTRY_SERVER_URL"] = winAppStack.DockerRegistryUrl appSettings["DOCKER_REGISTRY_SERVER_USERNAME"] = winAppStack.DockerRegistryUsername appSettings["DOCKER_REGISTRY_SERVER_PASSWORD"] = winAppStack.DockerRegistryPassword - } } else { @@ -1176,6 +1195,8 @@ func (s *SiteConfigWindowsWebAppSlot) ExpandForUpdate(metadata sdk.ResourceMetaD } } + expanded.AppSettings = ExpandAppSettingsForCreate(appSettings) + if metadata.ResourceData.HasChange("site_config.0.auto_swap_slot_name") { expanded.AutoSwapSlotName = pointer.To(s.AutoSwapSlotName) } diff --git a/internal/services/appservice/linux_web_app_resource_test.go b/internal/services/appservice/linux_web_app_resource_test.go index e15421ed3245..928c69114806 100644 --- a/internal/services/appservice/linux_web_app_resource_test.go +++ b/internal/services/appservice/linux_web_app_resource_test.go @@ -1128,6 +1128,30 @@ func TestAccLinuxWebApp_withDockerImageDockerHub(t *testing.T) { }) } +func TestAccLinuxWebApp_withDockerImageDockerHubUpdate(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_linux_web_app", "test") + r := LinuxWebAppResource{} + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.dockerImageName(data, "https://index.docker.io", "nginx:latest"), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("site_config.0.linux_fx_version").HasValue("DOCKER|index.docker.io/nginx:latest"), + ), + }, + data.ImportStep(), + { + Config: r.dockerImageName(data, "https://index.docker.io", "nginx:stable"), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("site_config.0.linux_fx_version").HasValue("DOCKER|index.docker.io/nginx:stable"), + ), + }, + data.ImportStep(), + }) +} + // Change Application stack of an app? func TestAccLinuxWebApp_updateAppStack(t *testing.T) { diff --git a/internal/services/appservice/linux_web_app_slot_resource_test.go b/internal/services/appservice/linux_web_app_slot_resource_test.go index 2c691c65bfa9..42d209d61a05 100644 --- a/internal/services/appservice/linux_web_app_slot_resource_test.go +++ b/internal/services/appservice/linux_web_app_slot_resource_test.go @@ -1106,6 +1106,30 @@ func TestAccLinuxWebAppSlot_withDockerImageDockerHub(t *testing.T) { }) } +func TestAccLinuxWebAppSlot_withDockerImageDockerHubUpdate(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_linux_web_app_slot", "test") + r := LinuxWebAppSlotResource{} + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.dockerImageName(data, "https://index.docker.io", "nginx:latest"), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("site_config.0.linux_fx_version").HasValue("DOCKER|index.docker.io/nginx:latest"), + ), + }, + data.ImportStep(), + { + Config: r.dockerImageName(data, "https://index.docker.io", "nginx:stable"), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("site_config.0.linux_fx_version").HasValue("DOCKER|index.docker.io/nginx:stable"), + ), + }, + data.ImportStep(), + }) +} + // Deployments func TestAccLinuxWebAppSlot_zipDeploy(t *testing.T) { diff --git a/internal/services/appservice/windows_web_app_resource_test.go b/internal/services/appservice/windows_web_app_resource_test.go index f1bfea96c5b0..bcaf1a609592 100644 --- a/internal/services/appservice/windows_web_app_resource_test.go +++ b/internal/services/appservice/windows_web_app_resource_test.go @@ -916,6 +916,14 @@ func TestAccWindowsWebApp_withDockerImageDockerHub(t *testing.T) { ), }, data.ImportStep(), + { + Config: r.dockerImageName(data, "https://index.docker.io", "traefik:v3.0-windowsservercore-1809"), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("site_config.0.windows_fx_version").HasValue("DOCKER|traefik:v3.0-windowsservercore-1809"), + ), + }, + data.ImportStep(), }) } diff --git a/internal/services/appservice/windows_web_app_slot_resource_test.go b/internal/services/appservice/windows_web_app_slot_resource_test.go index 9dd7029de321..48889ee497e3 100644 --- a/internal/services/appservice/windows_web_app_slot_resource_test.go +++ b/internal/services/appservice/windows_web_app_slot_resource_test.go @@ -883,10 +883,10 @@ func TestAccWindowsWebAppSlot_withDockerImageDockerHub(t *testing.T) { data.ResourceTest(t, r, []acceptance.TestStep{ { - Config: r.dockerImageName(data, "https://index.docker.io", "traefik:windowsservercore-1809"), + Config: r.dockerImageName(data, "https://index.docker.io", "traefik:v3.0-windowsservercore-1809"), Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), - check.That(data.ResourceName).Key("site_config.0.windows_fx_version").HasValue("DOCKER|traefik:windowsservercore-1809"), + check.That(data.ResourceName).Key("site_config.0.windows_fx_version").HasValue("DOCKER|traefik:v3.0-windowsservercore-1809"), ), }, data.ImportStep(),