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

Remove forceNew for zone and standby_availability_zone of azurerm_postgresql_flexible_server #13507

Merged
merged 12 commits into from
Oct 21, 2021

Conversation

neil-yechenwei
Copy link
Contributor

@neil-yechenwei neil-yechenwei commented Sep 26, 2021

fixes #13443

Symptom:
Currently, TF would recreate this resource when zone and standby_availability_zone is changed.

Expected behavior:
After confirmed with service team, TF shouldn't recreate this resource when zone and standby_availability_zone is changed, which means failover is triggered once zone and standby_availability_zone is changed and failover between zone and standby_availability_zone is only supported when their values are exchanged.

Failover is implemented by separate API not update API.

--- PASS: TestAccPostgresqlflexibleServer_basic (564.91s)
--- PASS: TestAccPostgresqlflexibleServer_requiresImport (598.20s)
--- PASS: TestAccPostgresqlflexibleServer_updateMaintenanceWindow (1090.05s)
--- PASS: TestAccPostgresqlflexibleServer_complete (1170.18s)
--- PASS: TestAccPostgresqlflexibleServer_updateSku (1490.18s)
--- PASS: TestAccPostgresqlflexibleServer_failover (1582.92s)
--- PASS: TestAccPostgresqlflexibleServer_pitr (1954.23s)
--- PASS: TestAccPostgresqlflexibleServer_completeUpdate (2148.29s)

Copy link
Contributor

@tombuildsstuff tombuildsstuff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hey @neil-yechenwei

Thanks for this PR.

I've taken a look through and left a few comments inline - if we can fix those up then we should be able to take another look.

Thanks!

"zone": {
Type: pluginsdk.TypeString,
Optional: true,
Computed: true,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't be Computed, since we should highlight the change when this occurs/isn't specified:

Suggested change
Computed: true,

Similarly, is there a reason this isn't Required? In other clouds it's the convention to have to specify a zone when creating resources

Copy link
Contributor Author

@neil-yechenwei neil-yechenwei Oct 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TF would cause diff when it isn't specified. Because service backend would set it with random zone when it isn't specified in request body. So suggest to keep "Computed: true".

Service team confirmed generally user doesn't care where zone is. Service backend would optimize according to the actual situation and the success rate of the creation would be higher. So it isn't required property.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@neil-yechenwei as above this needs to become un-computed here

Copy link
Contributor Author

@neil-yechenwei neil-yechenwei Oct 21, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tombuildsstuff , as service team confirmed user doesn't care where zone is, so I think we shouldn't highlight the change when it isn't specified. Does it make sense?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@neil-yechenwei this is a core tenant of Terraform that we'll show you the drift - so this has to be uncomputed - I've opened #13843

"standby_availability_zone": {
Type: pluginsdk.TypeString,
Optional: true,
Computed: true,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(same here)

Copy link
Contributor Author

@neil-yechenwei neil-yechenwei Oct 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TF would cause diff when it isn't specified. Because service backend would set it with random zone when it isn't specified in request body. So suggest to keep "Computed: true".

Service team confirmed generally user doesn't care where standby_availability_zone is. Service backend would optimize according to the actual situation and the success rate of the creation would be higher. So it isn't required property.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@neil-yechenwei as above this needs to become un-computed here

Copy link
Contributor Author

@neil-yechenwei neil-yechenwei Oct 21, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as service team confirmed user doesn't care where zone is, so I think we shouldn't highlight the change when it isn't specified. Does it make sense?

@@ -626,8 +692,11 @@ func expandFlexibleServerHighAvailability(inputs []interface{}) *postgresqlflexi
Mode: postgresqlflexibleservers.HighAvailabilityMode(input["mode"].(string)),
}

if v, ok := input["standby_availability_zone"]; ok && v.(string) != "" {
result.StandbyAvailabilityZone = utils.String(v.(string))
// service team confirmed it doesn't support to update `standby_availability_zone` after the PostgreSQL Flexible Server resource is created
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so then how do users fail-back?

Copy link
Contributor Author

@neil-yechenwei neil-yechenwei Oct 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Service team confirmed we shouldn't use update operation to fail-back. fail back should be implemented by restart with failover. For instance, zone is set to 1 and standby_availability_zone is set to 2 in tf config. Then we can failover zone to 2 and standby_availability_zone to 1 using restart with failover api after creation.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@neil-yechenwei so in that scenario, how do users fail-back? e.g.

  • Provision with zone = 1 and standby_zone = 2
  • Failover so that zone = 2 and standby_zone = 1
  • Failback so that zone = 1 and standby_zone = 2

(we should also probably rename this field to standby_zone)

Copy link
Contributor Author

@neil-yechenwei neil-yechenwei Oct 21, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Users need to keep zone=1 and standby_availability_zone=2 in TF config and run tf apply to failback after automatically failover.

(standby_availability_zone stands for healthy zone not unhealthy zone. So suggest to keep this name.)

@@ -91,7 +91,7 @@ The following arguments are supported:

* `administrator_password` - (Optional) The Password associated with the `administrator_login` for the PostgreSQL Flexible Server. Required when `create_mode` is `Default`.

* `zone` - (Optional) The availability zone of the PostgreSQL Flexible Server. Possible values are `1`, `2` and `3`. Changing this forces a new PostgreSQL Flexible Server to be created.
* `zone` - (Optional) The availability zone of the PostgreSQL Flexible Server. Possible values are `1`, `2` and `3`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Availability Zones available change per-region - some support No Zones, some support 1 & 2, others support 1, 2 and 3. We should add a callout to explain this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep("administrator_password", "create_mode"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we also add a step to fail-back here too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

@github-actions github-actions bot added size/L and removed size/M labels Oct 13, 2021
@neil-yechenwei
Copy link
Contributor Author

neil-yechenwei commented Oct 13, 2021

Thanks @tombuildsstuff , I've updated code. Please have another look. Thanks in advance.

@katbyte katbyte added this to the v2.82.0 milestone Oct 21, 2021
@katbyte katbyte merged commit 6a3ec6c into hashicorp:main Oct 21, 2021
katbyte added a commit that referenced this pull request Oct 21, 2021
@github-actions
Copy link

This functionality has been released in v2.82.0 of the Terraform Provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you!

katbyte pushed a commit that referenced this pull request Nov 18, 2021
@github-actions
Copy link

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 22, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Terraform wants to destroy PostgreSQL Flexible Server after failover
4 participants