Skip to content

Commit

Permalink
improve func
Browse files Browse the repository at this point in the history
  • Loading branch information
lonegunmanb committed Dec 26, 2023
1 parent e7486d7 commit 136c5a3
Showing 1 changed file with 8 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -774,13 +774,13 @@ func resourceOrchestratedVirtualMachineScaleSetUpdate(d *pluginsdk.ResourceData,
osProfileRaw := d.Get("os_profile").([]interface{})
vmssOsProfile := compute.VirtualMachineScaleSetUpdateOSProfile{}
var windowsConfig *compute.WindowsConfiguration
withWinCfg := func(set func()) {
withWinCfg := func() *compute.WindowsConfiguration {
if windowsConfig == nil {
windowsConfig = &compute.WindowsConfiguration{
PatchSettings: &compute.PatchSettings{},
}
}
set()
return windowsConfig
}
linuxConfig := compute.LinuxConfiguration{}

Expand Down Expand Up @@ -817,36 +817,28 @@ func resourceOrchestratedVirtualMachineScaleSetUpdate(d *pluginsdk.ResourceData,
}

if d.HasChange("os_profile.0.windows_configuration.0.enable_automatic_updates") {
withWinCfg(func() {
windowsConfig.EnableAutomaticUpdates = utils.Bool(winConfig["enable_automatic_updates"].(bool))
})
withWinCfg().EnableAutomaticUpdates = utils.Bool(winConfig["enable_automatic_updates"].(bool))
}

if d.HasChange("os_profile.0.windows_configuration.0.provision_vm_agent") {
if isHotpatchEnabledImage && !provisionVMAgent {
return fmt.Errorf("when referencing a hotpatching enabled image the 'provision_vm_agent' field must always be set to 'true', got %q", strconv.FormatBool(provisionVMAgent))
}
withWinCfg(func() {
windowsConfig.ProvisionVMAgent = utils.Bool(provisionVMAgent)
})
withWinCfg().ProvisionVMAgent = utils.Bool(provisionVMAgent)
}

if d.HasChange("os_profile.0.windows_configuration.0.patch_assessment_mode") {
if !provisionVMAgent && (patchAssessmentMode == string(compute.WindowsPatchAssessmentModeAutomaticByPlatform)) {
return fmt.Errorf("when the 'patch_assessment_mode' field is set to %q the 'provision_vm_agent' must always be set to 'true'", compute.WindowsPatchAssessmentModeAutomaticByPlatform)
}
withWinCfg(func() {
windowsConfig.PatchSettings.AssessmentMode = compute.WindowsPatchAssessmentMode(patchAssessmentMode)
})
withWinCfg().PatchSettings.AssessmentMode = compute.WindowsPatchAssessmentMode(patchAssessmentMode)
}

if d.HasChange("os_profile.0.windows_configuration.0.patch_mode") {
if isHotpatchEnabledImage && (patchMode != string(compute.WindowsVMGuestPatchModeAutomaticByPlatform)) {
return fmt.Errorf("when referencing a hotpatching enabled image the 'patch_mode' field must always be set to %q, got %q", compute.WindowsVMGuestPatchModeAutomaticByPlatform, patchMode)
}
withWinCfg(func() {
windowsConfig.PatchSettings.PatchMode = compute.WindowsVMGuestPatchMode(patchMode)
})
withWinCfg().PatchSettings.PatchMode = compute.WindowsVMGuestPatchMode(patchMode)
}

// Disabling hotpatching is not supported in images that support hotpatching
Expand All @@ -857,19 +849,15 @@ func resourceOrchestratedVirtualMachineScaleSetUpdate(d *pluginsdk.ResourceData,
if isHotpatchEnabledImage && !hotpatchingEnabled {
return fmt.Errorf("when referencing a hotpatching enabled image the 'hotpatching_enabled' field must always be set to 'true', got %q", strconv.FormatBool(hotpatchingEnabled))
}
withWinCfg(func() {
windowsConfig.PatchSettings.EnableHotpatching = utils.Bool(hotpatchingEnabled)
})
withWinCfg().PatchSettings.EnableHotpatching = utils.Bool(hotpatchingEnabled)
}

if d.HasChange("os_profile.0.windows_configuration.0.secret") {
vmssOsProfile.Secrets = expandWindowsSecrets(winConfig["secret"].([]interface{}))
}

if d.HasChange("os_profile.0.windows_configuration.0.timezone") {
withWinCfg(func() {
windowsConfig.TimeZone = utils.String(winConfig["timezone"].(string))
})
withWinCfg().TimeZone = utils.String(winConfig["timezone"].(string))
}

if d.HasChange("os_profile.0.windows_configuration.0.winrm_listener") {
Expand Down

0 comments on commit 136c5a3

Please sign in to comment.