Skip to content

Commit 2d8c358

Browse files
committed
Add GM support to upgrade components
Support the upgrade of Global Manager using the Terraform provider. Signed-off-by: Kobi Samoray <[email protected]>
1 parent bafb4e4 commit 2d8c358

File tree

4 files changed

+86
-17
lines changed

4 files changed

+86
-17
lines changed

docs/guides/upgrade.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,47 @@ When the ESXi software is not upgraded, the finalization stage will fail. There
198198
the NSX management plane, the Edge appliances and the NSX bits on the ESXi hosts, and postpone the ESXi OS upgrade to
199199
a later time.
200200

201+
### Upgrading Global Manager
202+
203+
NSX Global Manager upgrade is similar to Local Manager. Yet, Global Manager has no Edge or Host components and therefore
204+
Doesn't allow the configuration of these components in upgrade groups in the `nsxt_upgrade_run` resource.
205+
206+
The example below uses Terraform to upgrade a Global Manager.
207+
208+
```hcl
209+
provider "nsxt" {
210+
host = "global.manager.somedomain.org"
211+
username = "admin"
212+
password = "AdminPassword"
213+
allow_unverified_ssl = true
214+
global_manager = true // This is required to indicate that we upgrade a Global Manager
215+
}
216+
217+
resource "nsxt_upgrade_prepare" "gm_prepare_res" {
218+
upgrade_bundle_url = var.upgrade_bundle_url
219+
accept_user_agreement = true
220+
}
221+
222+
resource "nsxt_upgrade_precheck_acknowledge" "gm_precheck_ack" {
223+
provider = nsxt.gm_nsxt
224+
225+
precheck_ids = var.gm_precheck_warns
226+
target_version = nsxt_upgrade_prepare.gm_prepare_res.target_version
227+
}
228+
229+
data "nsxt_upgrade_prepare_ready" "gm_ready" {
230+
provider = nsxt.gm_nsxt
231+
232+
upgrade_prepare_id = nsxt_upgrade_prepare.gm_prepare_res.id
233+
depends_on = [nsxt_upgrade_precheck_acknowledge.gm_precheck_ack]
234+
}
235+
236+
resource "nsxt_upgrade_run" "gm_run" {
237+
provider = nsxt.gm_nsxt
238+
upgrade_prepare_ready_id = data.nsxt_upgrade_prepare_ready.gm_ready.id
239+
}
240+
```
241+
201242
### Post upgrade checks
202243
203244
Upgrade post check data sources can be used to examine the results of the edge and host upgrades, to conclude if the

docs/resources/upgrade_run.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,18 +94,21 @@ The following arguments are supported:
9494
* `timeout` - (Optional) Upgrade status check timeout in seconds. Default: 3600 seconds.
9595
* `interval` - (Optional) Interval to check upgrade status in seconds. Default: 30 seconds.
9696
* `delay` - (Optional) Initial delay to start upgrade status checks in seconds. Default: 300 seconds.
97+
* `max_retries` - (Optional) Maximum number of retries before failing the upgrade operation. Default: 100.
98+
99+
**NOTE:** With Global Manager, `edge_group`, `host_group`, `finalize_upgrade_setting`, `edge_upgrade_setting`, `host_upgrade_setting` attributes are not supported.
97100

98101
## Attributes Reference
99102

100103
In addition to arguments listed above, the following attributes are exported:
101104

102105
* `upgrade_plan` - (Computed) Upgrade plan for current upgrade. Upgrade unit groups that are not defined in `edge_group` or `host_group` will also be included here.
103-
* `type` - Component type.
104-
* `id` - ID of the upgrade unit group.
105-
* `enabled` - Flag to indicate whether upgrade of this group is enabled or not.
106-
* `parallel` - Upgrade method to specify whether the upgrade is to be performed in parallel or serially.
107-
* `pause_after_each_upgrade_unit` - Flag to indicate whether upgrade should be paused after upgrade of each upgrade-unit.
108-
* `extended_config` - Extended configuration for the group.
106+
* `type` - Component type.
107+
* `id` - ID of the upgrade unit group.
108+
* `enabled` - Flag to indicate whether upgrade of this group is enabled or not.
109+
* `parallel` - Upgrade method to specify whether the upgrade is to be performed in parallel or serially.
110+
* `pause_after_each_upgrade_unit` - Flag to indicate whether upgrade should be paused after upgrade of each upgrade-unit.
111+
* `extended_config` - Extended configuration for the group.
109112
* `state` - (Computed) Upgrade states of each component
110113
* `type` - Component type.
111114
* `status` - Upgrade status of component.

nsxt/resource_nsxt_upgrade_prepare.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ import (
2525
"github.com/vmware/vsphere-automation-sdk-go/services/nsxt-mp/nsx/upgrade/pre_upgrade_checks"
2626
)
2727

28-
var precheckComponentTypes = []string{"EDGE", "HOST", "MP"}
28+
var lmPrecheckComponentTypes = []string{"EDGE", "HOST", "MP"}
29+
var gmPrecheckComponentTypes = []string{"MP"}
2930

3031
const bundleUploadTimeout int = 3600
3132
const ucUpgradeTimeout int = 3600
@@ -400,7 +401,7 @@ func executePreupgradeChecks(d *schema.ResourceData, m interface{}) error {
400401
return err
401402
}
402403
timeout := d.Get("precheck_timeout").(int)
403-
for _, componentType := range precheckComponentTypes {
404+
for _, componentType := range getPrecheckComponentTypes(m) {
404405
log.Printf("Execute pre-upgrade check on %s", componentType)
405406
err = waitForPrecheckComplete(m, componentType, timeout)
406407
if err != nil {
@@ -410,6 +411,13 @@ func executePreupgradeChecks(d *schema.ResourceData, m interface{}) error {
410411
return nil
411412
}
412413

414+
func getPrecheckComponentTypes(m interface{}) []string {
415+
if isPolicyGlobalManager(m) {
416+
return gmPrecheckComponentTypes
417+
}
418+
return lmPrecheckComponentTypes
419+
}
420+
413421
func getPrecheckErrors(m interface{}, typeParam *string) ([]nsxModel.UpgradeCheckFailure, error) {
414422
connector := getPolicyConnector(m)
415423
client := pre_upgrade_checks.NewFailuresClient(connector)

nsxt/resource_nsxt_upgrade_run.go

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ var upgradeComponentListPost9 = []string{
3535
finalizeUpgradeGroup,
3636
}
3737

38+
var upgradeComponentListGlobalManager = []string{
39+
mpUpgradeGroup,
40+
}
41+
3842
var postCheckComponentList = []string{
3943
edgeUpgradeGroup,
4044
hostUpgradeGroup,
@@ -52,6 +56,7 @@ var componentToSettingKey = map[string]string{
5256

5357
var supportedUpgradeMode = []string{"maintenance_mode", "in_place", "stage_in_vlcm"}
5458
var supportedMaintenanceModeConfigVsanMode = []string{"evacuate_all_data", "ensure_object_accessibility", "no_action"}
59+
var lmOnlyAttributes = []string{"edge_group", "host_group", "finalize_upgrade_setting", "edge_upgrade_setting", "host_upgrade_setting"}
5560

5661
var (
5762
// Default waiting setup in seconds
@@ -100,7 +105,10 @@ func getTargetVersion(m interface{}) (string, error) {
100105
return *obj.TargetVersion, nil
101106
}
102107

103-
func getUpgradeComponentList(targetVersion string) []string {
108+
func getUpgradeComponentList(targetVersion string, m interface{}) []string {
109+
if isPolicyGlobalManager(m) {
110+
return upgradeComponentListGlobalManager
111+
}
104112
if util.VersionHigherOrEqual(targetVersion, "9.0.0") {
105113
return upgradeComponentListPost9
106114
}
@@ -412,6 +420,15 @@ func upgradeRunCreateOrUpdate(d *schema.ResourceData, m interface{}) error {
412420
id = newUUID()
413421
}
414422

423+
// Fail if upgrade groups are configured for global manager
424+
if isPolicyGlobalManager(m) {
425+
for _, attr := range lmOnlyAttributes {
426+
if d.HasChange(attr) {
427+
return fmt.Errorf("attribute %s is not supported for Global Manager", attr)
428+
}
429+
}
430+
}
431+
415432
// Validate that upgrade_prepare_id is actually from the nsxt_upgrade_prepare_ready data source
416433
upgradePrepareReadyID := d.Get("upgrade_prepare_ready_id").(string)
417434
if !util.VerifyVerifiableID(upgradePrepareReadyID, "nsxt_upgrade_prepare_ready") {
@@ -427,7 +444,7 @@ func upgradeRunCreateOrUpdate(d *schema.ResourceData, m interface{}) error {
427444

428445
log.Printf("[INFO] Updating UpgradeUnitGroup and UpgradePlanSetting.")
429446
var hasVLCM bool
430-
err = prepareUpgrade(upgradeClientSet, d, targetVersion, &hasVLCM)
447+
err = prepareUpgrade(upgradeClientSet, d, m, targetVersion, &hasVLCM)
431448
if err != nil {
432449
return handleCreateError("NsxtUpgradeRun", id, err)
433450
}
@@ -442,7 +459,7 @@ func upgradeRunCreateOrUpdate(d *schema.ResourceData, m interface{}) error {
442459
}
443460
}
444461

445-
err = runUpgrade(upgradeClientSet, getPartialUpgradeMap(d, targetVersion), targetVersion, hasVLCM, finalizeUpgrade)
462+
err = runUpgrade(upgradeClientSet, m, getPartialUpgradeMap(d, m, targetVersion), targetVersion, hasVLCM, finalizeUpgrade)
446463
if err != nil {
447464
return handleCreateError("NsxtUpgradeRun", id, err)
448465
}
@@ -453,8 +470,8 @@ func upgradeRunCreateOrUpdate(d *schema.ResourceData, m interface{}) error {
453470
return resourceNsxtUpgradeRunRead(d, m)
454471
}
455472

456-
func prepareUpgrade(upgradeClientSet *upgradeClientSet, d *schema.ResourceData, targetVersion string, hasVLCM *bool) error {
457-
for _, component := range getUpgradeComponentList(targetVersion) {
473+
func prepareUpgrade(upgradeClientSet *upgradeClientSet, d *schema.ResourceData, m interface{}, targetVersion string, hasVLCM *bool) error {
474+
for _, component := range getUpgradeComponentList(targetVersion, m) {
458475
// Customize MP upgrade is not allowed
459476
if component == mpUpgradeGroup || component == finalizeUpgradeGroup {
460477
continue
@@ -515,12 +532,12 @@ func prepareUpgrade(upgradeClientSet *upgradeClientSet, d *schema.ResourceData,
515532
return nil
516533
}
517534

518-
func getPartialUpgradeMap(d *schema.ResourceData, targetVersion string) map[string]bool {
535+
func getPartialUpgradeMap(d *schema.ResourceData, m interface{}, targetVersion string) map[string]bool {
519536
isPartialUpgradeMap := map[string]bool{
520537
edgeUpgradeGroup: false,
521538
hostUpgradeGroup: false,
522539
}
523-
for _, component := range getUpgradeComponentList(targetVersion) {
540+
for _, component := range getUpgradeComponentList(targetVersion, m) {
524541
if component == mpUpgradeGroup || component == finalizeUpgradeGroup {
525542
continue
526543
}
@@ -808,10 +825,10 @@ func updateComponentUpgradePlanSetting(settingClient plan.SettingsClient, d *sch
808825
return err
809826
}
810827

811-
func runUpgrade(upgradeClientSet *upgradeClientSet, partialUpgradeMap map[string]bool, targetVersion string, hasVLCM, finalizeUpgrade bool) error {
828+
func runUpgrade(upgradeClientSet *upgradeClientSet, m interface{}, partialUpgradeMap map[string]bool, targetVersion string, hasVLCM, finalizeUpgrade bool) error {
812829
partialUpgradeExist := false
813830
prevComponent := ""
814-
for _, c := range getUpgradeComponentList(targetVersion) {
831+
for _, c := range getUpgradeComponentList(targetVersion, m) {
815832
component := c
816833
if !finalizeUpgrade && component == finalizeUpgradeGroup {
817834
continue

0 commit comments

Comments
 (0)