-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
[fix] Correctly setreplica_server_id
on azurerm_postgresql_flexible_server_virtual_endpoint
forazurerm_postgresql_flexible_server
s that exist in separate resource groups
#27509
Conversation
azurerm_postgresql_flexible_server_virtual_endpoint
forazurerm_postgresql_flexible_server
s that live in separate regionsazurerm_postgresql_flexible_server_virtual_endpoint
forazurerm_postgresql_flexible_server
s that exist in separate resource groups
azurerm_postgresql_flexible_server_virtual_endpoint
forazurerm_postgresql_flexible_server
s that exist in separate resource groupsreplica_server_id
on azurerm_postgresql_flexible_server_virtual_endpoint
forazurerm_postgresql_flexible_server
s that exist in separate resource groups
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @bruceharrison1984 - Thanks for this PR, it looks mostly good, but there are a few minor changes to take a look at below if you could?
Thanks
internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource_test.go
Outdated
Show resolved
Hide resolved
internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource_test.go
Outdated
Show resolved
Hide resolved
internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource_test.go
Outdated
Show resolved
Hide resolved
internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource_test.go
Outdated
Show resolved
Hide resolved
internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource_test.go
Outdated
Show resolved
Hide resolved
internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource_test.go
Outdated
Show resolved
Hide resolved
internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource_test.go
Outdated
Show resolved
Hide resolved
internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource_test.go
Outdated
Show resolved
Hide resolved
if _, err := client.Delete(ctx, *id); err != nil { | ||
return fmt.Errorf("deleting %s: %+v", *id, err) | ||
// The flexible endpoint API does not store the location/rg information on replicas it only stores the name. | ||
// This lookup is safe because replicas for a given source server are *not* allowed to have identical names |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are the server names we're looking for here guaranteed to be unique per subscription, or could we have a condition where there are multiple servers of the same name in different resource groups that could lead to an unexpected outcome here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The names may not be unique per subscription, however they must be unique per source server. Since we check that the replica name matches, as well as filter those results based on the source server ID we should be protected from selecting an incorrect replica. Even if the names matched, replicas must have unique names per source servers.
TLDR; For a given source server, all replicas associated with the source server must have unique names. By filtering on both conditions, we can confidently pick the correct one even if duplicate named replicas exist within the subscription.
I was worried about this as well, but I believe it is setup in a safe manner.
} | ||
|
||
state.SourceServerId = sourceServerId | ||
state.ReplicaServerId = *replicaServer.Id |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is direct from the lookup API, we can't be sure it will be correctly cased for the expected state (since we validate the input), can we normalise it using servers.ParseFlexibleServerID()
before setting the value into state.ReplicaServerId
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've updated the code to reflect your suggestion
…endpoint_resource_test.go Co-authored-by: jackofallops <[email protected]>
…endpoint_resource_test.go Co-authored-by: jackofallops <[email protected]>
…endpoint_resource_test.go Co-authored-by: jackofallops <[email protected]>
…endpoint_resource_test.go Co-authored-by: jackofallops <[email protected]>
…endpoint_resource_test.go Co-authored-by: jackofallops <[email protected]>
…endpoint_resource_test.go Co-authored-by: jackofallops <[email protected]>
…endpoint_resource_test.go Co-authored-by: jackofallops <[email protected]>
…endpoint_resource_test.go Co-authored-by: jackofallops <[email protected]>
…endpoint_resource_test.go Co-authored-by: jackofallops <[email protected]>
…endpoint_resource_test.go Co-authored-by: jackofallops <[email protected]>
…endpoint_resource_test.go Co-authored-by: jackofallops <[email protected]>
…endpoint_resource_test.go Co-authored-by: jackofallops <[email protected]>
…endpoint_resource_test.go Co-authored-by: jackofallops <[email protected]>
…endpoint_resource_test.go Co-authored-by: jackofallops <[email protected]>
…endpoint_resource_test.go Co-authored-by: jackofallops <[email protected]>
…endpoint_resource_test.go Co-authored-by: jackofallops <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From a hashi customer... THANK YOU FOR THIS @bruceharrison1984
Hi can this be released this week? @jackofallops I think @bruceharrison1984 left Hashicorp recently. Someone else may need to push this |
will this be released soon? |
a314bd6
to
b1bda4d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this @bruceharrison1984. Hope you don't mind I pushed some minor simplifications and additional nil checks to your code.
@stephybun I've got no complaints with someone improving the codebase, and showing me a better way. Thanks! |
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. |
Community Note
Description
This corrects a bug that occurs when the replica server doesn't exist in the same resource group as the source server. Previously, the endpoint would be flagged for changes on the second run. This corrects that issue.
Additionally, if the primary server was stopped it would also try to recreate the virtual endpoint. This also corrects that issue.
Anyone previously affected by this will see non-destructive changes on the first deploy, but the issue should correct it self there after.
This PR also removes the custom poller that was previously necessary. It appears Azure has changed the API so it is no longer necessary.
PR Checklist
For example: “
resource_name_here
- description of change e.g. adding propertynew_property_name_here
”Changes to existing Resource / Data Source
Testing
Change Log
Below please provide what should go into the changelog (if anything) conforming to the Changelog Format documented here.
azurerm_postgresql_flexible_server_virtual_endpoint
- fix bug that affected replicas deployed in different resource groups from the source server [postgresql_flexible_server_virtual_endpoint_resource
incorrectly sets Replica Server ID #27453]This is a (please select all that apply):
Related Issue(s)
Fixes #27453
Fixes #27749
Note
If this PR changes meaningfully during the course of review please update the title and description as required.