Skip to content

Commit 0e11d30

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 2870375 commit 0e11d30

File tree

4 files changed

+80
-11
lines changed

4 files changed

+80
-11
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: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ 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

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
@@ -36,6 +36,10 @@ var upgradeComponentListPost9 = []string{
3636
finalizeUpgradeGroup,
3737
}
3838

39+
var upgradeComponentListGlobalManager = []string{
40+
mpUpgradeGroup,
41+
}
42+
3943
var postCheckComponentList = []string{
4044
edgeUpgradeGroup,
4145
hostUpgradeGroup,
@@ -53,6 +57,7 @@ var componentToSettingKey = map[string]string{
5357

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

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

104-
func getUpgradeComponentList(targetVersion string) []string {
109+
func getUpgradeComponentList(targetVersion string, m interface{}) []string {
110+
if isPolicyGlobalManager(m) {
111+
return upgradeComponentListGlobalManager
112+
}
105113
if util.VersionHigherOrEqual(targetVersion, "9.0.0") {
106114
return upgradeComponentListPost9
107115
}
@@ -413,6 +421,15 @@ func upgradeRunCreateOrUpdate(d *schema.ResourceData, m interface{}) error {
413421
id = newUUID()
414422
}
415423

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

429446
log.Printf("[INFO] Updating UpgradeUnitGroup and UpgradePlanSetting.")
430447
var hasVLCM bool
431-
err = prepareUpgrade(upgradeClientSet, d, targetVersion, &hasVLCM)
448+
err = prepareUpgrade(upgradeClientSet, d, m, targetVersion, &hasVLCM)
432449
if err != nil {
433450
return handleCreateError("NsxtUpgradeRun", id, err)
434451
}
@@ -443,7 +460,7 @@ func upgradeRunCreateOrUpdate(d *schema.ResourceData, m interface{}) error {
443460
}
444461
}
445462

446-
err = runUpgrade(upgradeClientSet, getPartialUpgradeMap(d, targetVersion), targetVersion, hasVLCM, finalizeUpgrade)
463+
err = runUpgrade(upgradeClientSet, m, getPartialUpgradeMap(d, m, targetVersion), targetVersion, hasVLCM, finalizeUpgrade)
447464
if err != nil {
448465
return handleCreateError("NsxtUpgradeRun", id, err)
449466
}
@@ -454,8 +471,8 @@ func upgradeRunCreateOrUpdate(d *schema.ResourceData, m interface{}) error {
454471
return resourceNsxtUpgradeRunRead(d, m)
455472
}
456473

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

519-
func getPartialUpgradeMap(d *schema.ResourceData, targetVersion string) map[string]bool {
536+
func getPartialUpgradeMap(d *schema.ResourceData, m interface{}, targetVersion string) map[string]bool {
520537
isPartialUpgradeMap := map[string]bool{
521538
edgeUpgradeGroup: false,
522539
hostUpgradeGroup: false,
523540
}
524-
for _, component := range getUpgradeComponentList(targetVersion) {
541+
for _, component := range getUpgradeComponentList(targetVersion, m) {
525542
if component == mpUpgradeGroup || component == finalizeUpgradeGroup {
526543
continue
527544
}
@@ -816,10 +833,10 @@ func updateComponentUpgradePlanSetting(settingClient plan.SettingsClient, d *sch
816833
return err
817834
}
818835

819-
func runUpgrade(upgradeClientSet *upgradeClientSet, partialUpgradeMap map[string]bool, targetVersion string, hasVLCM, finalizeUpgrade bool) error {
836+
func runUpgrade(upgradeClientSet *upgradeClientSet, m interface{}, partialUpgradeMap map[string]bool, targetVersion string, hasVLCM, finalizeUpgrade bool) error {
820837
partialUpgradeExist := false
821838
prevComponent := ""
822-
for _, c := range getUpgradeComponentList(targetVersion) {
839+
for _, c := range getUpgradeComponentList(targetVersion, m) {
823840
component := c
824841
if !finalizeUpgrade && component == finalizeUpgradeGroup {
825842
continue

0 commit comments

Comments
 (0)