Skip to content

Commit

Permalink
pg server support in-place major version upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
wuxu92 committed Jan 20, 2025
1 parent ce9d7aa commit 6bb5ef4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 22 deletions.
33 changes: 14 additions & 19 deletions internal/services/postgres/postgresql_flexible_server_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,31 +335,26 @@ func resourcePostgresqlFlexibleServer() *pluginsdk.Resource {
},

CustomizeDiff: pluginsdk.CustomDiffWithAll(func(ctx context.Context, d *pluginsdk.ResourceDiff, v interface{}) error {

Check failure on line 337 in internal/services/postgres/postgresql_flexible_server_resource.go

View workflow job for this annotation

GitHub Actions / golint

unnecessary leading newline (whitespace)
createModeVal := d.Get("create_mode").(string)

if createModeVal == string(servers.CreateModeUpdate) {
// as create_mode should never change after creation, we can ignore it when checking for version changes
if d.HasChange("version") {
oldVersionVal, newVersionVal := d.GetChange("version")
// `version` value has been validated already, ignore the parse errors is safe
oldVersion, _ := strconv.ParseInt(oldVersionVal.(string), 10, 32)
newVersion, _ := strconv.ParseInt(newVersionVal.(string), 10, 32)

if oldVersionVal != "" && newVersionVal != "" {
oldVersion, err := strconv.ParseInt(oldVersionVal.(string), 10, 32)
if err != nil {
return err
}

newVersion, err := strconv.ParseInt(newVersionVal.(string), 10, 32)
if err != nil {
return err
}

if oldVersion < newVersion {
return nil
}
if oldVersion > newVersion {
d.ForceNew("version")
}
}

d.ForceNew("create_mode")
d.ForceNew("version")

if d.HasChange("create_mode") {
// if create_mode is set to `Update`, then we can update it rather than force new
if d.Get("create_mode").(string) != string(servers.CreateModeForUpdateUpdate) {
return nil
}
d.ForceNew("create_mode")
}
return nil
}, func(ctx context.Context, diff *pluginsdk.ResourceDiff, v interface{}) error {
oldLoginName, _ := diff.GetChange("administrator_login")
Expand Down
4 changes: 1 addition & 3 deletions website/docs/r/postgresql_flexible_server.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,7 @@ The following arguments are supported:

* `create_mode` - (Optional) The creation mode which can be used to restore or replicate existing servers. Possible values are `Default`, `GeoRestore`, `PointInTimeRestore`, `Replica` and `Update`. Changing this forces a new PostgreSQL Flexible Server to be created.

-> **Note:** `create_mode` cannot be changed once it's set since it's a parameter at creation.

-> **Note:** While creating the resource, `create_mode` cannot be set to `Update`.
-> **Note:** `create_mode` cannot be changed to other values than `Update`, it's set since it's a parameter at creation. It's optional to change it to `Update` when do a major version upgrade.

* `delegated_subnet_id` - (Optional) The ID of the virtual network subnet to create the PostgreSQL Flexible Server. The provided subnet should not have any other resource deployed in it and this subnet will be delegated to the PostgreSQL Flexible Server, if not already delegated. Changing this forces a new PostgreSQL Flexible Server to be created.

Expand Down

0 comments on commit 6bb5ef4

Please sign in to comment.