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_postgresql_flexible_server: more support for in-place major version upgrade #28559

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
34 changes: 14 additions & 20 deletions internal/services/postgres/postgresql_flexible_server_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,31 +335,25 @@ func resourcePostgresqlFlexibleServer() *pluginsdk.Resource {
},

CustomizeDiff: pluginsdk.CustomDiffWithAll(func(ctx context.Context, d *pluginsdk.ResourceDiff, v interface{}) error {
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
Original file line number Diff line number Diff line change
Expand Up @@ -1238,7 +1238,6 @@ resource "azurerm_postgresql_flexible_server" "test" {
administrator_login = "adminTerraform"
administrator_password = "QAZwsx123"
storage_mb = 32768
create_mode = "Update"
version = "%s"
sku_name = "GP_Standard_D2s_v3"
zone = "2"
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
Loading