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

Conversation

xiaxyi
Copy link
Contributor

@xiaxyi xiaxyi commented Jul 12, 2023

Fixes

  1. Since app_setting exists in two places, one is under site_config while the other is under site, current, when user sets the docker related settings in site_config such as docker_registry_url, docker_registry_username and docker_registry_password, these settings are not being updated correctly in app_setting under Site. The app_setting under site_config is not taking any effects...
  2. handle provider crash due to nil map.

fix #22379
fix #22436
fix #22435
fix #22548

Copy link
Member

@jackofallops jackofallops left a comment

Choose a reason for hiding this comment

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

Hi @xiaxyi - Thanks for this PR, I've left some comments below to more cleanly resolve the reported bugs, if you can take a look?

Thanks!

Comment on lines +939 to +941
if appSettings == nil {
appSettings = map[string]string{}
}
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.

Comment on lines +622 to +624
if appSettings == nil {
appSettings = map[string]string{}
}
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.

Comment on lines +754 to +756
if appSettings == nil {
appSettings = map[string]string{}
}
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.

Comment on lines +1037 to +1039
if appSettings == nil {
appSettings = map[string]string{}
}
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

Comment on lines +1177 to +1179
if appSettings == nil {
appSettings = map[string]string{}
}
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

Comment on lines +795 to +810
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
}
}
}
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

Comment on lines +409 to +424
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
}
}
}

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

Comment on lines +871 to +886
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
}
}
}
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

Comment on lines +388 to +403
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
}
}
}

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

Comment on lines +834 to +849
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
}
}
}
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

@xiaxyi
Copy link
Contributor Author

xiaxyi commented Aug 21, 2023

updated the comment in thread~

@rcskosir rcskosir linked an issue Aug 22, 2023 that may be closed by this pull request
1 task
@james-mwakichako
Copy link

Are we in a position to merge this PR @jackofallops ? We are waiting for this fix

@oletolshaveics
Copy link

Will it be possible to implement the changes suggested by jackofallops and get this merged? Docker based app services are pretty much broken for us at the moment due to this (after we upgraded to azurerm_linux_web_app from azure_app_service).

@jgmchan
Copy link

jgmchan commented Sep 12, 2023

We're in the same position as well, this bug is causing production issues as it keeps removing the DOCKER_* environment variables and this means it won't pull down the latest docker containers.

@oletolshaveics
Copy link

My current work around look like this:

resource "azurerm_linux_web_app" "core_as" {
  name                						= // ...
  // ...

  site_config {
    // ...
	
	application_stack {
		docker_image_name                               = "(redacted)"		
		# I would like to enable these but currently do not
#              docker_registry_url                                  = "https://ghcr.io"
#		docker_registry_username                       = "(redacted)"
#		docker_registry_password                       = data.azurerm_key_vault_secret.ghdr.value
	}
  }

  app_settings = {
	// ...

    # Remove these when the docker settings no longer need to be in app_settings (https://github.com/hashicorp/terraform-provider-azurerm/pull/22484)
    "DOCKER_REGISTRY_SERVER_URL" 			= "https://ghcr.io"
    "DOCKER_REGISTRY_SERVER_USERNAME" 		= "(redacted)"
    "DOCKER_REGISTRY_SERVER_PASSWORD"		= data.azurerm_key_vault_secret.ghdr.value,
  }
}

The 3 app settings are detected as changes on every plan+apply, which is very annoying, but it does work. When I need to initialize an environment from scratch, I have to run Terraform 3(!?) times, before the app settings stabilize. Quite inconvenient, but at least it works.

@jackofallops
Copy link
Member

Hi @xiaxyi I couldn't push changes to your fork to resolve this, so I've opened another PR to get the fixes in. I'm going to close this in favour of #23303

Copy link

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 14, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.