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_[linux|windows]_web_app[_slot] fix docker app_stack update #23303

Merged
merged 1 commit into from
Sep 19, 2023
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
}
Expand Down
27 changes: 24 additions & 3 deletions internal/services/appservice/helpers/web_app_slot_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -1165,17 +1180,23 @@ 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 {
expanded.WindowsFxVersion = pointer.To("")
}
}

expanded.AppSettings = ExpandAppSettingsForCreate(appSettings)

if metadata.ResourceData.HasChange("site_config.0.auto_swap_slot_name") {
expanded.AutoSwapSlotName = pointer.To(s.AutoSwapSlotName)
}
Expand Down
24 changes: 24 additions & 0 deletions internal/services/appservice/linux_web_app_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down