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[linux]_web_app_[slot] - add docker setting to app_setting block #22484

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
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{}
}
Comment on lines +939 to +941
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This avoids the crash, but unfortunately doesn't correctly address the bug of the values not being set, as the line

expanded.AppSettings = ExpandAppSettingsForCreate(appSettings)

is missing from this function.

appSettings["DOCKER_REGISTRY_SERVER_URL"] = linuxAppStack.DockerRegistryUrl
appSettings["DOCKER_REGISTRY_SERVER_USERNAME"] = linuxAppStack.DockerRegistryUsername
appSettings["DOCKER_REGISTRY_SERVER_PASSWORD"] = linuxAppStack.DockerRegistryPassword
Expand Down
12 changes: 12 additions & 0 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,9 @@ func (s *SiteConfigLinuxWebAppSlot) ExpandForCreate(appSettings map[string]strin

if linuxAppStack.DockerImageName != "" {
expanded.LinuxFxVersion = pointer.To(EncodeDockerFxString(linuxAppStack.DockerImageName, linuxAppStack.DockerRegistryUrl))
if appSettings == nil {
appSettings = map[string]string{}
}
Comment on lines +622 to +624
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above, the missing values bug is due to the app settings not being written to the expand via

	expanded.AppSettings = ExpandAppSettingsForCreate(appSettings)

after the entries are added.

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 +751,9 @@ func (s *SiteConfigLinuxWebAppSlot) ExpandForUpdate(metadata sdk.ResourceMetaDat

if linuxAppStack.DockerImageName != "" {
expanded.LinuxFxVersion = pointer.To(EncodeDockerFxString(linuxAppStack.DockerImageName, linuxAppStack.DockerRegistryUrl))
if appSettings == nil {
appSettings = map[string]string{}
}
Comment on lines +754 to +756
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, as above.

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 @@ -1028,6 +1034,9 @@ func (s *SiteConfigWindowsWebAppSlot) ExpandForCreate(appSettings map[string]str

if winAppStack.DockerImageName != "" {
expanded.WindowsFxVersion = pointer.To(EncodeDockerFxStringWindows(winAppStack.DockerImageName, winAppStack.DockerRegistryUrl))
if appSettings == nil {
appSettings = map[string]string{}
}
Comment on lines +1037 to +1039
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

again here

appSettings["DOCKER_REGISTRY_SERVER_URL"] = winAppStack.DockerRegistryUrl
appSettings["DOCKER_REGISTRY_SERVER_USERNAME"] = winAppStack.DockerRegistryUsername
appSettings["DOCKER_REGISTRY_SERVER_PASSWORD"] = winAppStack.DockerRegistryPassword
Expand Down Expand Up @@ -1165,6 +1174,9 @@ func (s *SiteConfigWindowsWebAppSlot) ExpandForUpdate(metadata sdk.ResourceMetaD

if winAppStack.DockerImageName != "" {
expanded.WindowsFxVersion = pointer.To(EncodeDockerFxStringWindows(winAppStack.DockerImageName, winAppStack.DockerRegistryUrl))
if appSettings == nil {
appSettings = map[string]string{}
}
Comment on lines +1177 to +1179
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and again here

appSettings["DOCKER_REGISTRY_SERVER_URL"] = winAppStack.DockerRegistryUrl
appSettings["DOCKER_REGISTRY_SERVER_USERNAME"] = winAppStack.DockerRegistryUsername
appSettings["DOCKER_REGISTRY_SERVER_PASSWORD"] = winAppStack.DockerRegistryPassword
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,9 @@ func (s *SiteConfigWindows) ExpandForCreate(appSettings map[string]string) (*web

if winAppStack.DockerImageName != "" {
expanded.WindowsFxVersion = pointer.To(EncodeDockerFxStringWindows(winAppStack.DockerImageName, winAppStack.DockerRegistryUrl))
if appSettings == nil {
appSettings = map[string]string{}
}
Comment on lines +528 to +530
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and again here

appSettings["DOCKER_REGISTRY_SERVER_URL"] = winAppStack.DockerRegistryUrl
appSettings["DOCKER_REGISTRY_SERVER_USERNAME"] = winAppStack.DockerRegistryUsername
appSettings["DOCKER_REGISTRY_SERVER_PASSWORD"] = winAppStack.DockerRegistryPassword
Expand Down Expand Up @@ -659,6 +662,9 @@ func (s *SiteConfigWindows) ExpandForUpdate(metadata sdk.ResourceMetaData, exist

if winAppStack.DockerImageName != "" {
expanded.WindowsFxVersion = pointer.To(EncodeDockerFxStringWindows(winAppStack.DockerImageName, winAppStack.DockerRegistryUrl))
if appSettings == nil {
appSettings = map[string]string{}
}
appSettings["DOCKER_REGISTRY_SERVER_URL"] = winAppStack.DockerRegistryUrl
appSettings["DOCKER_REGISTRY_SERVER_USERNAME"] = winAppStack.DockerRegistryUsername
appSettings["DOCKER_REGISTRY_SERVER_PASSWORD"] = winAppStack.DockerRegistryPassword
Expand Down
33 changes: 32 additions & 1 deletion internal/services/appservice/linux_web_app_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,22 @@ func (r LinuxWebAppResource) Create() sdk.ResourceFunc {

metadata.SetID(id)

if siteConfigAppSetting := siteConfig.AppSettings; siteConfigAppSetting != nil && len(*siteConfigAppSetting) > 0 {
if webApp.AppSettings == nil {
webApp.AppSettings = make(map[string]string)
}
for _, pair := range *siteConfigAppSetting {
if pair.Name == nil || pair.Value == nil {
continue
}
if *pair.Name == "DOCKER_REGISTRY_SERVER_URL" ||
*pair.Name == "DOCKER_REGISTRY_SERVER_USERNAME" ||
*pair.Name == "DOCKER_REGISTRY_SERVER_PASSWORD" {
webApp.AppSettings[*pair.Name] = *pair.Value
}
}
}

Comment on lines +393 to +408
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't be necessary with with the above bug fixes in the expands.

appSettingsUpdate := helpers.ExpandAppSettingsForUpdate(webApp.AppSettings)
if metadata.ResourceData.HasChange("site_config.0.health_check_eviction_time_in_min") {
appSettingsUpdate.Properties["WEBSITE_HEALTHCHECK_MAXPINGFAILURES"] = pointer.To(strconv.Itoa(webApp.SiteConfig[0].HealthCheckEvictionTime))
Expand Down Expand Up @@ -804,7 +820,22 @@ func (r LinuxWebAppResource) 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") || metadata.ResourceData.HasChange("site_config.0.health_check_eviction_time_in_min") {
if metadata.ResourceData.HasChange("app_settings") || metadata.ResourceData.HasChange("site_config.0.health_check_eviction_time_in_min") || metadata.ResourceData.HasChanges("site_config.0.application_stack") {
if siteConfigAppSetting := existing.SiteConfig.AppSettings; siteConfigAppSetting != nil && len(*siteConfigAppSetting) > 0 {
if state.AppSettings == nil {
state.AppSettings = make(map[string]string)
}
for _, pair := range *siteConfigAppSetting {
if pair.Name == nil || pair.Value == nil {
continue
}
if *pair.Name == "DOCKER_REGISTRY_SERVER_URL" ||
*pair.Name == "DOCKER_REGISTRY_SERVER_USERNAME" ||
*pair.Name == "DOCKER_REGISTRY_SERVER_PASSWORD" {
state.AppSettings[*pair.Name] = *pair.Value
}
}
}
Comment on lines +823 to +838
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as above, the fixes to the expands should remove the need for this

appSettingsUpdate := helpers.ExpandAppSettingsForUpdate(state.AppSettings)
appSettingsUpdate.Properties["WEBSITE_HEALTHCHECK_MAXPINGFAILURES"] = pointer.To(strconv.Itoa(state.SiteConfig[0].HealthCheckEvictionTime))

Expand Down
33 changes: 32 additions & 1 deletion internal/services/appservice/linux_web_app_slot_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,22 @@ func (r LinuxWebAppSlotResource) Create() sdk.ResourceFunc {

metadata.SetID(id)

if siteConfigAppSetting := siteConfig.AppSettings; siteConfigAppSetting != nil && len(*siteConfigAppSetting) > 0 {
if webAppSlot.AppSettings == nil {
webAppSlot.AppSettings = make(map[string]string)
}
for _, pair := range *siteConfigAppSetting {
if pair.Name == nil || pair.Value == nil {
continue
}
if *pair.Name == "DOCKER_REGISTRY_SERVER_URL" ||
*pair.Name == "DOCKER_REGISTRY_SERVER_USERNAME" ||
*pair.Name == "DOCKER_REGISTRY_SERVER_PASSWORD" {
webAppSlot.AppSettings[*pair.Name] = *pair.Value
}
}
}

Comment on lines +372 to +387
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

again here

appSettings := helpers.ExpandAppSettingsForUpdate(webAppSlot.AppSettings)
if metadata.ResourceData.HasChange("site_config.0.health_check_eviction_time_in_min") {
appSettings.Properties["WEBSITE_HEALTHCHECK_MAXPINGFAILURES"] = pointer.To(strconv.Itoa(webAppSlot.SiteConfig[0].HealthCheckEvictionTime))
Expand Down Expand Up @@ -776,7 +792,22 @@ func (r LinuxWebAppSlotResource) 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") || metadata.ResourceData.HasChange("site_config.0.health_check_eviction_time_in_min") {
if metadata.ResourceData.HasChange("app_settings") || metadata.ResourceData.HasChange("site_config.0.health_check_eviction_time_in_min") || metadata.ResourceData.HasChanges("site_config.0.application_stack") {
if siteConfigAppSetting := existing.SiteConfig.AppSettings; siteConfigAppSetting != nil && len(*siteConfigAppSetting) > 0 {
if state.AppSettings == nil {
state.AppSettings = make(map[string]string)
}
for _, pair := range *siteConfigAppSetting {
if pair.Name == nil || pair.Value == nil {
continue
}
if *pair.Name == "DOCKER_REGISTRY_SERVER_URL" ||
*pair.Name == "DOCKER_REGISTRY_SERVER_USERNAME" ||
*pair.Name == "DOCKER_REGISTRY_SERVER_PASSWORD" {
state.AppSettings[*pair.Name] = *pair.Value
}
}
}
Comment on lines +795 to +810
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and here

appSettingsUpdate := helpers.ExpandAppSettingsForUpdate(state.AppSettings)
appSettingsUpdate.Properties["WEBSITE_HEALTHCHECK_MAXPINGFAILURES"] = pointer.To(strconv.Itoa(state.SiteConfig[0].HealthCheckEvictionTime))

Expand Down
33 changes: 32 additions & 1 deletion internal/services/appservice/windows_web_app_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,22 @@ func (r WindowsWebAppResource) Create() sdk.ResourceFunc {
}
}

if siteConfigAppSetting := siteConfig.AppSettings; siteConfigAppSetting != nil && len(*siteConfigAppSetting) > 0 {
if webApp.AppSettings == nil {
webApp.AppSettings = make(map[string]string)
}
for _, pair := range *siteConfigAppSetting {
if pair.Name == nil || pair.Value == nil {
continue
}
if *pair.Name == "DOCKER_REGISTRY_SERVER_URL" ||
*pair.Name == "DOCKER_REGISTRY_SERVER_USERNAME" ||
*pair.Name == "DOCKER_REGISTRY_SERVER_PASSWORD" {
webApp.AppSettings[*pair.Name] = *pair.Value
}
}
}

Comment on lines +409 to +424
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and here

appSettings := helpers.ExpandAppSettingsForUpdate(webApp.AppSettings)
if metadata.ResourceData.HasChange("site_config.0.health_check_eviction_time_in_min") {
appSettings.Properties["WEBSITE_HEALTHCHECK_MAXPINGFAILURES"] = pointer.To(strconv.Itoa(webApp.SiteConfig[0].HealthCheckEvictionTime))
Expand Down Expand Up @@ -852,7 +868,22 @@ 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") || metadata.ResourceData.HasChange("site_config.0.health_check_eviction_time_in_min") {
if metadata.ResourceData.HasChange("app_settings") || metadata.ResourceData.HasChange("site_config.0.health_check_eviction_time_in_min") || metadata.ResourceData.HasChanges("site_config.0.application_stack") {
if siteConfigAppSetting := existing.SiteConfig.AppSettings; siteConfigAppSetting != nil && len(*siteConfigAppSetting) > 0 {
if state.AppSettings == nil {
state.AppSettings = make(map[string]string)
}
for _, pair := range *siteConfigAppSetting {
if pair.Name == nil || pair.Value == nil {
continue
}
if *pair.Name == "DOCKER_REGISTRY_SERVER_URL" ||
*pair.Name == "DOCKER_REGISTRY_SERVER_USERNAME" ||
*pair.Name == "DOCKER_REGISTRY_SERVER_PASSWORD" {
state.AppSettings[*pair.Name] = *pair.Value
}
}
}
Comment on lines +871 to +886
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

again here

appSettingsUpdate := helpers.ExpandAppSettingsForUpdate(state.AppSettings)
appSettingsUpdate.Properties["WEBSITE_HEALTHCHECK_MAXPINGFAILURES"] = pointer.To(strconv.Itoa(state.SiteConfig[0].HealthCheckEvictionTime))
if _, err := client.UpdateApplicationSettings(ctx, id.ResourceGroup, id.SiteName, *appSettingsUpdate); err != nil {
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 @@ -385,6 +385,22 @@ func (r WindowsWebAppSlotResource) Create() sdk.ResourceFunc {
}
}

if siteConfigAppSetting := siteConfig.AppSettings; siteConfigAppSetting != nil && len(*siteConfigAppSetting) > 0 {
if webAppSlot.AppSettings == nil {
webAppSlot.AppSettings = make(map[string]string)
}
for _, pair := range *siteConfigAppSetting {
if pair.Name == nil || pair.Value == nil {
continue
}
if *pair.Name == "DOCKER_REGISTRY_SERVER_URL" ||
*pair.Name == "DOCKER_REGISTRY_SERVER_USERNAME" ||
*pair.Name == "DOCKER_REGISTRY_SERVER_PASSWORD" {
webAppSlot.AppSettings[*pair.Name] = *pair.Value
}
}
}

Comment on lines +388 to +403
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and again here

appSettings := helpers.ExpandAppSettingsForUpdate(webAppSlot.AppSettings)
if metadata.ResourceData.HasChange("site_config.0.health_check_eviction_time_in_min") {
appSettings.Properties["WEBSITE_HEALTHCHECK_MAXPINGFAILURES"] = pointer.To(strconv.Itoa(webAppSlot.SiteConfig[0].HealthCheckEvictionTime))
Expand Down Expand Up @@ -815,10 +831,27 @@ 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") || 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.HasChange("app_settings") || metadata.ResourceData.HasChange("site_config.0.health_check_eviction_time_in_min") || metadata.ResourceData.HasChange("site_config.0.application_stack") {
if siteConfigAppSetting := existing.SiteConfig.AppSettings; siteConfigAppSetting != nil && len(*siteConfigAppSetting) > 0 {
if state.AppSettings == nil {
state.AppSettings = make(map[string]string)
}
for _, pair := range *siteConfigAppSetting {
if pair.Name == nil || pair.Value == nil {
continue
}
if *pair.Name == "DOCKER_REGISTRY_SERVER_URL" ||
*pair.Name == "DOCKER_REGISTRY_SERVER_USERNAME" ||
*pair.Name == "DOCKER_REGISTRY_SERVER_PASSWORD" {
state.AppSettings[*pair.Name] = *pair.Value
}
}
}
Comment on lines +834 to +849
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and here

appSettingsUpdate := helpers.ExpandAppSettingsForUpdate(state.AppSettings)
appSettingsUpdate.Properties["WEBSITE_HEALTHCHECK_MAXPINGFAILURES"] = pointer.To(strconv.Itoa(state.SiteConfig[0].HealthCheckEvictionTime))
appSettingsUpdate.Properties["WEBSITE_NODE_DEFAULT_VERSION"] = pointer.To(state.SiteConfig[0].ApplicationStack[0].NodeVersion)
if metadata.ResourceData.HasChange("site_config.0.application_stack.0.node_version") {
appSettingsUpdate.Properties["WEBSITE_NODE_DEFAULT_VERSION"] = pointer.To(state.SiteConfig[0].ApplicationStack[0].NodeVersion)
}
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