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 a bug in app_settings #24221

Merged
merged 3 commits into from
Dec 13, 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
14 changes: 11 additions & 3 deletions internal/services/appservice/helpers/common_web_app_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -1219,10 +1219,18 @@ func FlattenConnectionStrings(appConnectionStrings web.ConnectionStringDictionar
return connectionStrings
}

func ExpandAppSettingsForUpdate(settings map[string]string) *web.StringDictionary {
func ExpandAppSettingsForUpdate(siteConfigSettings *[]web.NameValuePair) *web.StringDictionary {
appSettings := make(map[string]*string)
for k, v := range settings {
appSettings[k] = pointer.To(v)
if siteConfigSettings == nil {
return &web.StringDictionary{
Properties: appSettings,
}
}

for _, v := range *siteConfigSettings {
if name := pointer.From(v.Name); name != "" {
appSettings[name] = v.Value
}
}

return &web.StringDictionary{
Expand Down
16 changes: 14 additions & 2 deletions internal/services/appservice/helpers/web_app_slot_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -993,10 +993,14 @@ func (s *SiteConfigWindowsWebAppSlot) ExpandForCreate(appSettings map[string]str
expanded.AppCommandLine = pointer.To(s.AppCommandLine)
}

expanded.AppSettings = ExpandAppSettingsForCreate(appSettings)

if len(s.ApplicationStack) == 1 {
winAppStack := s.ApplicationStack[0]
if winAppStack.NodeVersion != "" {
if appSettings == nil {
appSettings = make(map[string]string)
}
appSettings["WEBSITE_NODE_DEFAULT_VERSION"] = winAppStack.NodeVersion
}
if winAppStack.NetFrameworkVersion != "" {
expanded.NetFrameworkVersion = pointer.To(winAppStack.NetFrameworkVersion)
}
Expand Down Expand Up @@ -1027,6 +1031,7 @@ func (s *SiteConfigWindowsWebAppSlot) ExpandForCreate(appSettings map[string]str
expanded.JavaContainerVersion = pointer.To(winAppStack.JavaContainerVersion)
}
}

if !features.FourPointOhBeta() {
if winAppStack.DockerContainerName != "" || winAppStack.DockerContainerRegistry != "" || winAppStack.DockerContainerTag != "" {
if winAppStack.DockerContainerRegistry != "" {
Expand All @@ -1051,6 +1056,7 @@ func (s *SiteConfigWindowsWebAppSlot) ExpandForCreate(appSettings map[string]str
} else {
expanded.WindowsFxVersion = pointer.To("")
}

expanded.AppSettings = ExpandAppSettingsForCreate(appSettings)

if s.AutoSwapSlotName != "" {
Expand Down Expand Up @@ -1138,6 +1144,12 @@ func (s *SiteConfigWindowsWebAppSlot) ExpandForUpdate(metadata sdk.ResourceMetaD
if metadata.ResourceData.HasChange("site_config.0.application_stack") {
if len(s.ApplicationStack) == 1 {
winAppStack := s.ApplicationStack[0]
if metadata.ResourceData.HasChange("site_config.0.application_stack.0.node_version") {
if appSettings == nil {
appSettings = make(map[string]string)
}
appSettings["WEBSITE_NODE_DEFAULT_VERSION"] = winAppStack.NodeVersion
}
if winAppStack.NetFrameworkVersion != "" {
expanded.NetFrameworkVersion = pointer.To(winAppStack.NetFrameworkVersion)
}
Expand Down
19 changes: 17 additions & 2 deletions internal/services/appservice/helpers/windows_web_app_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -479,10 +479,14 @@ func (s *SiteConfigWindows) ExpandForCreate(appSettings map[string]string) (*web
expanded.AppCommandLine = pointer.To(s.AppCommandLine)
}

expanded.AppSettings = ExpandAppSettingsForCreate(appSettings)

if len(s.ApplicationStack) == 1 {
winAppStack := s.ApplicationStack[0]
if winAppStack.NodeVersion != "" {
if appSettings == nil {
appSettings = make(map[string]string)
}
appSettings["WEBSITE_NODE_DEFAULT_VERSION"] = winAppStack.NodeVersion
}
if winAppStack.NetFrameworkVersion != "" {
expanded.NetFrameworkVersion = pointer.To(winAppStack.NetFrameworkVersion)
}
Expand Down Expand Up @@ -513,6 +517,7 @@ func (s *SiteConfigWindows) ExpandForCreate(appSettings map[string]string) (*web
expanded.JavaContainerVersion = pointer.To(winAppStack.JavaContainerVersion)
}
}

if !features.FourPointOhBeta() {
if winAppStack.DockerContainerName != "" || winAppStack.DockerContainerRegistry != "" || winAppStack.DockerContainerTag != "" {
if winAppStack.DockerContainerRegistry != "" {
Expand All @@ -535,6 +540,8 @@ func (s *SiteConfigWindows) ExpandForCreate(appSettings map[string]string) (*web
expanded.WindowsFxVersion = pointer.To("")
}

expanded.AppSettings = ExpandAppSettingsForCreate(appSettings)

if s.ContainerRegistryUserMSI != "" {
expanded.AcrUserManagedIdentityID = pointer.To(s.ContainerRegistryUserMSI)
}
Expand Down Expand Up @@ -617,6 +624,12 @@ func (s *SiteConfigWindows) ExpandForUpdate(metadata sdk.ResourceMetaData, exist
if metadata.ResourceData.HasChange("site_config.0.application_stack") {
if len(s.ApplicationStack) == 1 {
winAppStack := s.ApplicationStack[0]
if metadata.ResourceData.HasChange("site_config.0.application_stack.0.node_version") {
if appSettings == nil {
appSettings = make(map[string]string)
}
appSettings["WEBSITE_NODE_DEFAULT_VERSION"] = winAppStack.NodeVersion
}
if metadata.ResourceData.HasChanges("site_config.0.application_stack.0.dotnet_version", "site_config.0.application_stack.0.dotnet_core_version") {
switch {
case winAppStack.NetFrameworkVersion != "":
Expand Down Expand Up @@ -682,6 +695,8 @@ func (s *SiteConfigWindows) ExpandForUpdate(metadata sdk.ResourceMetaData, exist
}
}

expanded.AppSettings = ExpandAppSettingsForCreate(appSettings)

if metadata.ResourceData.HasChange("site_config.0.virtual_application") {
expanded.VirtualApplications = expandVirtualApplicationsForUpdate(s.VirtualApplications)
} else {
Expand Down
8 changes: 4 additions & 4 deletions internal/services/appservice/linux_web_app_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ func (r LinuxWebAppResource) Create() sdk.ResourceFunc {

metadata.SetID(id)

appSettingsUpdate := helpers.ExpandAppSettingsForUpdate(webApp.AppSettings)
appSettingsUpdate := helpers.ExpandAppSettingsForUpdate(siteConfig.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 @@ -814,7 +814,7 @@ func (r LinuxWebAppResource) Update() sdk.ResourceFunc {
existing.Tags = tags.FromTypedObject(state.Tags)
}

if metadata.ResourceData.HasChange("site_config") || servicePlanChange {
if metadata.ResourceData.HasChanges("site_config", "app_settings") || servicePlanChange {
existing.SiteConfig, err = sc.ExpandForUpdate(metadata, existing.SiteConfig, state.AppSettings)
if err != nil {
return err
Expand Down Expand Up @@ -855,8 +855,8 @@ 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") {
appSettingsUpdate := helpers.ExpandAppSettingsForUpdate(state.AppSettings)
if metadata.ResourceData.HasChanges("app_settings", "site_config") || metadata.ResourceData.HasChange("site_config.0.health_check_eviction_time_in_min") {
appSettingsUpdate := helpers.ExpandAppSettingsForUpdate(existing.SiteConfig.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
8 changes: 4 additions & 4 deletions internal/services/appservice/linux_web_app_slot_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ func (r LinuxWebAppSlotResource) Create() sdk.ResourceFunc {

metadata.SetID(id)

appSettings := helpers.ExpandAppSettingsForUpdate(webAppSlot.AppSettings)
appSettings := helpers.ExpandAppSettingsForUpdate(siteConfig.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 @@ -813,7 +813,7 @@ func (r LinuxWebAppSlotResource) Update() sdk.ResourceFunc {
existing.Tags = tags.FromTypedObject(state.Tags)
}

if metadata.ResourceData.HasChange("site_config") {
if metadata.ResourceData.HasChanges("site_config", "app_settings") {
sc := state.SiteConfig[0]
siteConfig, err := sc.ExpandForUpdate(metadata, existing.SiteConfig, state.AppSettings)
if err != nil {
Expand Down Expand Up @@ -856,8 +856,8 @@ 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") {
appSettingsUpdate := helpers.ExpandAppSettingsForUpdate(state.AppSettings)
if metadata.ResourceData.HasChanges("app_settings", "site_config") || metadata.ResourceData.HasChange("site_config.0.health_check_eviction_time_in_min") {
appSettingsUpdate := helpers.ExpandAppSettingsForUpdate(existing.SiteConfig.AppSettings)
appSettingsUpdate.Properties["WEBSITE_HEALTHCHECK_MAXPINGFAILURES"] = pointer.To(strconv.Itoa(state.SiteConfig[0].HealthCheckEvictionTime))

if _, err := client.UpdateApplicationSettingsSlot(ctx, id.ResourceGroup, id.SiteName, *appSettingsUpdate, id.SlotName); err != nil {
Expand Down
14 changes: 4 additions & 10 deletions internal/services/appservice/windows_web_app_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,12 +351,6 @@ func (r WindowsWebAppResource) Create() sdk.ResourceFunc {
currentStack := ""
if len(sc.ApplicationStack) == 1 {
currentStack = sc.ApplicationStack[0].CurrentStack
if currentStack == helpers.CurrentStackNode || sc.ApplicationStack[0].NodeVersion != "" {
if webApp.AppSettings == nil {
webApp.AppSettings = make(map[string]string, 0)
}
webApp.AppSettings["WEBSITE_NODE_DEFAULT_VERSION"] = sc.ApplicationStack[0].NodeVersion
}
}

expandedIdentity, err := expandIdentity(metadata.ResourceData.Get("identity").([]interface{}))
Expand Down Expand Up @@ -420,7 +414,7 @@ func (r WindowsWebAppResource) Create() sdk.ResourceFunc {
}
}

appSettings := helpers.ExpandAppSettingsForUpdate(webApp.AppSettings)
appSettings := helpers.ExpandAppSettingsForUpdate(siteConfig.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 @@ -878,7 +872,7 @@ func (r WindowsWebAppResource) Update() sdk.ResourceFunc {
currentStack = sc.ApplicationStack[0].CurrentStack
}

if metadata.ResourceData.HasChange("site_config") || servicePlanChange {
if metadata.ResourceData.HasChanges("site_config", "app_settings") || servicePlanChange {
existing.SiteConfig, err = sc.ExpandForUpdate(metadata, existing.SiteConfig, state.AppSettings)
if err != nil {
return err
Expand Down Expand Up @@ -912,8 +906,8 @@ 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") {
appSettingsUpdate := helpers.ExpandAppSettingsForUpdate(state.AppSettings)
if metadata.ResourceData.HasChanges("app_settings", "site_config") || metadata.ResourceData.HasChange("site_config.0.health_check_eviction_time_in_min") {
appSettingsUpdate := helpers.ExpandAppSettingsForUpdate(existing.SiteConfig.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 {
return fmt.Errorf("updating App Settings for Windows %s: %+v", id, err)
Expand Down
14 changes: 4 additions & 10 deletions internal/services/appservice/windows_web_app_slot_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,12 +332,6 @@ func (r WindowsWebAppSlotResource) Create() sdk.ResourceFunc {
currentStack := ""
if len(sc.ApplicationStack) == 1 {
currentStack = sc.ApplicationStack[0].CurrentStack
if currentStack == helpers.CurrentStackNode || sc.ApplicationStack[0].NodeVersion != "" {
if webAppSlot.AppSettings == nil {
webAppSlot.AppSettings = make(map[string]string, 0)
}
webAppSlot.AppSettings["WEBSITE_NODE_DEFAULT_VERSION"] = sc.ApplicationStack[0].NodeVersion
}
}

expandedIdentity, err := expandIdentity(metadata.ResourceData.Get("identity").([]interface{}))
Expand Down Expand Up @@ -407,7 +401,7 @@ func (r WindowsWebAppSlotResource) Create() sdk.ResourceFunc {
}
}

appSettings := helpers.ExpandAppSettingsForUpdate(webAppSlot.AppSettings)
appSettings := helpers.ExpandAppSettingsForUpdate(siteConfig.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 @@ -839,7 +833,7 @@ func (r WindowsWebAppSlotResource) Update() sdk.ResourceFunc {
currentStack = sc.ApplicationStack[0].CurrentStack
}

if metadata.ResourceData.HasChange("site_config") {
if metadata.ResourceData.HasChanges("site_config", "app_settings") {
existing.SiteConfig, err = sc.ExpandForUpdate(metadata, existing.SiteConfig, state.AppSettings)
if err != nil {
return err
Expand Down Expand Up @@ -895,8 +889,8 @@ 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") {
appSettingsUpdate := helpers.ExpandAppSettingsForUpdate(state.AppSettings)
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") {
appSettingsUpdate := helpers.ExpandAppSettingsForUpdate(existing.SiteConfig.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 _, err := client.UpdateApplicationSettingsSlot(ctx, id.ResourceGroup, id.SiteName, *appSettingsUpdate, id.SlotName); err != nil {
Expand Down
Loading