From 41dd19190992147ad0f7ed0a0aff00e2523640dc Mon Sep 17 00:00:00 2001 From: Bruce Harrison Date: Wed, 25 Sep 2024 12:45:40 -0500 Subject: [PATCH 01/22] look up replica ID via API --- ...exible_server_virtual_endpoint_resource.go | 31 +++++++++++++++++-- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource.go b/internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource.go index 3072c1c02c7e..46e4b33d21fc 100644 --- a/internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource.go +++ b/internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource.go @@ -11,6 +11,7 @@ import ( "github.com/hashicorp/go-azure-helpers/lang/pointer" "github.com/hashicorp/go-azure-helpers/lang/response" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" "github.com/hashicorp/go-azure-sdk/resource-manager/postgresql/2023-06-01-preview/servers" "github.com/hashicorp/go-azure-sdk/resource-manager/postgresql/2023-06-01-preview/virtualendpoints" "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" @@ -131,6 +132,8 @@ func (r PostgresqlFlexibleServerVirtualEndpointResource) Read() sdk.ResourceFunc Timeout: 5 * time.Minute, Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error { client := metadata.Client.Postgres.VirtualEndpointClient + flexibleServerClient := metadata.Client.Postgres.FlexibleServersClient + state := PostgresqlFlexibleServerVirtualEndpointModel{} id, err := virtualendpoints.ParseVirtualEndpointID(metadata.ResourceData.Id()) @@ -159,9 +162,31 @@ func (r PostgresqlFlexibleServerVirtualEndpointResource) Read() sdk.ResourceFunc return metadata.MarkAsGone(id) } - // Model.Properties.Members should be a tuple => [source_server, replication_server] - state.SourceServerId = servers.NewFlexibleServerID(id.SubscriptionId, id.ResourceGroupName, (*resp.Model.Properties.Members)[0]).ID() - state.ReplicaServerId = servers.NewFlexibleServerID(id.SubscriptionId, id.ResourceGroupName, (*resp.Model.Properties.Members)[1]).ID() + // Model.Properties.Members is a tuple => [source_server, replication_server] + sourceServerName := (*resp.Model.Properties.Members)[0] + replicaServerName := (*resp.Model.Properties.Members)[1] + sourceServerId := servers.NewFlexibleServerID(id.SubscriptionId, id.ResourceGroupName, sourceServerName).ID() + + // 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 + postgresServers, err := flexibleServerClient.ListCompleteMatchingPredicate(ctx, commonids.NewSubscriptionID(id.SubscriptionId), servers.ServerOperationPredicate{ + Name: &replicaServerName, + }) + if err != nil { + return err + } + + // loop to find the replica server associated with this flexible endpoint + var replicaServer servers.Server + for i := 0; i < len(postgresServers.Items); i++ { + postgresServer := postgresServers.Items[i] + if postgresServer.Properties.SourceServerResourceId != nil && *postgresServer.Properties.SourceServerResourceId == sourceServerId { + replicaServer = postgresServer + } + } + + state.SourceServerId = sourceServerId + state.ReplicaServerId = *replicaServer.Id } } From 062ba9c9247be8008681d26987f5cdbcc357b0a1 Mon Sep 17 00:00:00 2001 From: Bruce Harrison Date: Wed, 25 Sep 2024 14:02:35 -0500 Subject: [PATCH 02/22] remove custom poller --- ...server_virtual_endpoint_resource_poller.go | 71 ------------------- ...exible_server_virtual_endpoint_resource.go | 50 ++++++------- ...e_server_virtual_endpoint_resource_test.go | 5 +- 3 files changed, 23 insertions(+), 103 deletions(-) delete mode 100644 internal/services/postgres/custompollers/postgresql_flexible_server_virtual_endpoint_resource_poller.go diff --git a/internal/services/postgres/custompollers/postgresql_flexible_server_virtual_endpoint_resource_poller.go b/internal/services/postgres/custompollers/postgresql_flexible_server_virtual_endpoint_resource_poller.go deleted file mode 100644 index 25315a3031eb..000000000000 --- a/internal/services/postgres/custompollers/postgresql_flexible_server_virtual_endpoint_resource_poller.go +++ /dev/null @@ -1,71 +0,0 @@ -// Copyright (c) HashiCorp, Inc. -// SPDX-License-Identifier: MPL-2.0 - -package custompollers - -import ( - "context" - "fmt" - "time" - - "github.com/hashicorp/go-azure-sdk/resource-manager/postgresql/2023-06-01-preview/virtualendpoints" - "github.com/hashicorp/go-azure-sdk/sdk/client" - "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" -) - -var _ pollers.PollerType = &postgresFlexibleServerVirtualEndpointPoller{} - -type postgresFlexibleServerVirtualEndpointPoller struct { - client *virtualendpoints.VirtualEndpointsClient - id virtualendpoints.VirtualEndpointId -} - -// Workaround due to Azure performing a pseudo-soft delete on virtual endpoints. -// -// - The `DELETE` endpoint does not fully delete the resource, it sets `properties.members` to nil -// -// - Subsequent `GET` operations for the endpoint will always return 200 with empty metadata, so Terraform will hang on `DELETE` -// -// - The only way to currently check for deletion is to check the `properties.members` property -func NewPostgresFlexibleServerVirtualEndpointDeletePoller(client *virtualendpoints.VirtualEndpointsClient, id virtualendpoints.VirtualEndpointId) *postgresFlexibleServerVirtualEndpointPoller { - return &postgresFlexibleServerVirtualEndpointPoller{ - client: client, - id: id, - } -} - -func (p postgresFlexibleServerVirtualEndpointPoller) Poll(ctx context.Context) (*pollers.PollResult, error) { - resp, err := p.client.Get(ctx, p.id) - if err != nil { - return nil, fmt.Errorf("retrieving %s: %+v", p.id, err) - } - - model := resp.Model - - if model != nil && model.Properties != nil { - if model.Properties.Members != nil { - return &pollers.PollResult{ - HttpResponse: &client.Response{ - Response: resp.HttpResponse, - }, - PollInterval: 5 * time.Second, - Status: pollers.PollingStatusInProgress, - }, nil - } - - return &pollers.PollResult{ - HttpResponse: &client.Response{ - Response: resp.HttpResponse, - }, - PollInterval: 5 * time.Second, - Status: pollers.PollingStatusSucceeded, - }, nil - } - - return nil, pollers.PollingFailedError{ - HttpResponse: &client.Response{ - Response: resp.HttpResponse, - }, - Message: fmt.Sprintf("failed to delete %s", p.id), - } -} diff --git a/internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource.go b/internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource.go index 46e4b33d21fc..a3c8ea45f89d 100644 --- a/internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource.go +++ b/internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource.go @@ -14,10 +14,8 @@ import ( "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" "github.com/hashicorp/go-azure-sdk/resource-manager/postgresql/2023-06-01-preview/servers" "github.com/hashicorp/go-azure-sdk/resource-manager/postgresql/2023-06-01-preview/virtualendpoints" - "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" "github.com/hashicorp/terraform-provider-azurerm/internal/locks" "github.com/hashicorp/terraform-provider-azurerm/internal/sdk" - "github.com/hashicorp/terraform-provider-azurerm/internal/services/postgres/custompollers" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation" ) @@ -162,29 +160,17 @@ func (r PostgresqlFlexibleServerVirtualEndpointResource) Read() sdk.ResourceFunc return metadata.MarkAsGone(id) } - // Model.Properties.Members is a tuple => [source_server, replication_server] + // Model.Properties.Members is a tuple => [source_server_id, replication_server_name] sourceServerName := (*resp.Model.Properties.Members)[0] replicaServerName := (*resp.Model.Properties.Members)[1] + sourceServerId := servers.NewFlexibleServerID(id.SubscriptionId, id.ResourceGroupName, sourceServerName).ID() - // 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 - postgresServers, err := flexibleServerClient.ListCompleteMatchingPredicate(ctx, commonids.NewSubscriptionID(id.SubscriptionId), servers.ServerOperationPredicate{ - Name: &replicaServerName, - }) + replicaServer, err := lookupFlexibleServerByName(ctx, flexibleServerClient, id, replicaServerName, sourceServerId) if err != nil { return err } - // loop to find the replica server associated with this flexible endpoint - var replicaServer servers.Server - for i := 0; i < len(postgresServers.Items); i++ { - postgresServer := postgresServers.Items[i] - if postgresServer.Properties.SourceServerResourceId != nil && *postgresServer.Properties.SourceServerResourceId == sourceServerId { - replicaServer = postgresServer - } - } - state.SourceServerId = sourceServerId state.ReplicaServerId = *replicaServer.Id } @@ -209,8 +195,8 @@ func (r PostgresqlFlexibleServerVirtualEndpointResource) Delete() sdk.ResourceFu locks.ByName(id.FlexibleServerName, postgresqlFlexibleServerResourceName) defer locks.UnlockByName(id.FlexibleServerName, postgresqlFlexibleServerResourceName) - if err := DeletePostgresFlexibileServerVirtualEndpoint(ctx, client, id); err != nil { - return err + if err := client.DeleteThenPoll(ctx, *id); err != nil { + return fmt.Errorf("deleting %s: %+v", *id, err) } return nil @@ -256,17 +242,23 @@ func (r PostgresqlFlexibleServerVirtualEndpointResource) Update() sdk.ResourceFu } } -// exposed so we can access from tests -func DeletePostgresFlexibileServerVirtualEndpoint(ctx context.Context, client *virtualendpoints.VirtualEndpointsClient, id *virtualendpoints.VirtualEndpointId) error { - deletePoller := custompollers.NewPostgresFlexibleServerVirtualEndpointDeletePoller(client, *id) - poller := pollers.NewPoller(deletePoller, 5*time.Second, pollers.DefaultNumberOfDroppedConnectionsToAllow) - - 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 +func lookupFlexibleServerByName(ctx context.Context, flexibleServerClient *servers.ServersClient, virtualEndpointId *virtualendpoints.VirtualEndpointId, replicaServerName string, sourceServerId string) (*servers.Server, error) { + postgresServers, err := flexibleServerClient.ListCompleteMatchingPredicate(ctx, commonids.NewSubscriptionID(virtualEndpointId.SubscriptionId), servers.ServerOperationPredicate{ + Name: &replicaServerName, + }) + if err != nil { + return nil, err } - if err := poller.PollUntilDone(ctx); err != nil { - return err + // loop to find the replica server associated with this flexible endpoint + var replicaServer servers.Server + for i := 0; i < len(postgresServers.Items); i++ { + postgresServer := postgresServers.Items[i] + if postgresServer.Properties.SourceServerResourceId != nil && *postgresServer.Properties.SourceServerResourceId == sourceServerId { + replicaServer = postgresServer + } } - return nil + return &replicaServer, nil } diff --git a/internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource_test.go b/internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource_test.go index 9b48f7bc1d6e..f4d97039c306 100644 --- a/internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource_test.go +++ b/internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource_test.go @@ -13,7 +13,6 @@ import ( "github.com/hashicorp/terraform-provider-azurerm/internal/acceptance" "github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" - "github.com/hashicorp/terraform-provider-azurerm/internal/services/postgres" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" "github.com/hashicorp/terraform-provider-azurerm/utils" ) @@ -81,8 +80,8 @@ func (r PostgresqlFlexibleServerVirtualEndpointResource) Destroy(ctx context.Con return nil, err } - if err := postgres.DeletePostgresFlexibileServerVirtualEndpoint(ctx, client.Postgres.VirtualEndpointClient, id); err != nil { - return nil, fmt.Errorf("deleting %s: %+v", id, err) + if err := client.Postgres.VirtualEndpointClient.DeleteThenPoll(ctx, *id); err != nil { + return nil, fmt.Errorf("deleting %s: %+v", *id, err) } return utils.Bool(true), nil From 46efac4d0514b88e1ac3cc7e9f439354fd12f3a7 Mon Sep 17 00:00:00 2001 From: Bruce Harrison Date: Tue, 1 Oct 2024 10:29:46 -0500 Subject: [PATCH 03/22] add test case --- ...e_server_virtual_endpoint_resource_test.go | 251 ++++++++++++++++++ 1 file changed, 251 insertions(+) diff --git a/internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource_test.go b/internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource_test.go index f4d97039c306..2371028f4528 100644 --- a/internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource_test.go +++ b/internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource_test.go @@ -60,6 +60,25 @@ func TestAccPostgresqlFlexibleServerVirtualEndpoint_update(t *testing.T) { }) } +func TestAccPostgresqlFlexibleServerVirtualEndpoint_cross_region(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_postgresql_flexible_server_virtual_endpoint", "test") + r := PostgresqlFlexibleServerVirtualEndpointResource{} + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.crossRegion(), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + data.DisappearsStep(acceptance.DisappearsStepData{ + Config: r.basic, + TestResource: r, + }), + }) +} + func (r PostgresqlFlexibleServerVirtualEndpointResource) Exists(ctx context.Context, clients *clients.Client, state *pluginsdk.InstanceState) (*bool, error) { id, err := virtualendpoints.ParseVirtualEndpointID(state.ID) if err != nil { @@ -199,3 +218,235 @@ resource "azurerm_postgresql_flexible_server_virtual_endpoint" "test" { } `, data.RandomInteger, "eastus", replicaId) // force region due to SKU constraints } + +/** Complex test cases across regions and resource groups */ +func (PostgresqlFlexibleServerVirtualEndpointResource) crossRegion() string { + return ` +provider "azurerm" { + features {} +} + +resource "random_pet" "name_prefix" { + length = 1 +} + +###### EAST RG ###### + +resource "azurerm_resource_group" "east" { + name = "${random_pet.name_prefix.id}-east" + location = "eastus" +} + +resource "azurerm_virtual_network" "east" { + name = "${random_pet.name_prefix.id}-east-vn" + location = azurerm_resource_group.east.location + resource_group_name = azurerm_resource_group.east.name + address_space = ["10.0.0.0/16"] +} + +resource "azurerm_network_security_group" "east" { + name = "${random_pet.name_prefix.id}-east-nsg" + location = azurerm_resource_group.east.location + resource_group_name = azurerm_resource_group.east.name + + security_rule { + name = "allow_all" + priority = 100 + direction = "Inbound" + access = "Allow" + protocol = "Tcp" + source_port_range = "*" + destination_port_range = "*" + source_address_prefix = "*" + destination_address_prefix = "*" + } +} + +resource "azurerm_subnet" "east" { + name = "${random_pet.name_prefix.id}-east-sn" + resource_group_name = azurerm_resource_group.east.name + virtual_network_name = azurerm_virtual_network.east.name + address_prefixes = ["10.0.1.0/24"] + service_endpoints = ["Microsoft.Storage"] + + delegation { + name = "fs" + service_delegation { + name = "Microsoft.DBforPostgreSQL/flexibleServers" + actions = [ + "Microsoft.Network/virtualNetworks/subnets/join/action", + ] + } + } +} + +resource "azurerm_subnet_network_security_group_association" "east" { + subnet_id = azurerm_subnet.east.id + network_security_group_id = azurerm_network_security_group.east.id +} + +resource "azurerm_private_dns_zone" "east" { + name = "${random_pet.name_prefix.id}-pdz.postgres.database.azure.com" + resource_group_name = azurerm_resource_group.east.name + + depends_on = [azurerm_subnet_network_security_group_association.east] +} + +resource "azurerm_virtual_network_peering" "east" { + name = "east-to-west" + resource_group_name = azurerm_resource_group.east.name + virtual_network_name = azurerm_virtual_network.east.name + remote_virtual_network_id = azurerm_virtual_network.west.id + allow_virtual_network_access = true + allow_forwarded_traffic = true +} + +resource "azurerm_private_dns_zone_virtual_network_link" "east" { + name = "${random_pet.name_prefix.id}-east-pdzvnetlink.com" + private_dns_zone_name = azurerm_private_dns_zone.east.name + virtual_network_id = azurerm_virtual_network.east.id + resource_group_name = azurerm_resource_group.east.name + + depends_on = [azurerm_virtual_network_peering.east] +} + +resource "random_password" "pass" { + length = 20 +} + +resource "azurerm_postgresql_flexible_server" "east" { + name = "${random_pet.name_prefix.id}-east-pg" + resource_group_name = azurerm_resource_group.east.name + location = azurerm_resource_group.east.location + version = "13" + public_network_access_enabled = false + administrator_login = "adminTerraform" + administrator_password = random_password.pass.result + sku_name = "GP_Standard_D2s_v3" + + delegated_subnet_id = azurerm_subnet.east.id + private_dns_zone_id = azurerm_private_dns_zone.east.id + + depends_on = [azurerm_private_dns_zone_virtual_network_link.east] + + lifecycle { + ignore_changes = [zone] + } + + timeouts { + create = "120m" + } +} + +resource "azurerm_postgresql_flexible_server_virtual_endpoint" "test" { + name = "${random_pet.name_prefix.id}-endpoint" + source_server_id = azurerm_postgresql_flexible_server.east.id + replica_server_id = azurerm_postgresql_flexible_server.west.id + type = "ReadWrite" +} + +###### WEST RG ###### + +resource "azurerm_resource_group" "west" { + name = "${random_pet.name_prefix.id}-west" + location = "westus" +} + +resource "azurerm_virtual_network" "west" { + name = "${random_pet.name_prefix.id}-west-vn" + location = azurerm_resource_group.west.location + resource_group_name = azurerm_resource_group.west.name + address_space = ["11.0.0.0/16"] +} + +resource "azurerm_network_security_group" "west" { + name = "${random_pet.name_prefix.id}-west-nsg" + location = azurerm_resource_group.west.location + resource_group_name = azurerm_resource_group.west.name + + security_rule { + name = "allow_all" + priority = 100 + direction = "Inbound" + access = "Allow" + protocol = "Tcp" + source_port_range = "*" + destination_port_range = "*" + source_address_prefix = "*" + destination_address_prefix = "*" + } +} + +resource "azurerm_subnet" "west" { + name = "${random_pet.name_prefix.id}-west-sn" + resource_group_name = azurerm_resource_group.west.name + virtual_network_name = azurerm_virtual_network.west.name + address_prefixes = ["11.0.1.0/24"] + service_endpoints = ["Microsoft.Storage"] + + delegation { + name = "fs" + service_delegation { + name = "Microsoft.DBforPostgreSQL/flexibleServers" + actions = [ + "Microsoft.Network/virtualNetworks/subnets/join/action", + ] + } + } +} + +resource "azurerm_subnet_network_security_group_association" "west" { + subnet_id = azurerm_subnet.west.id + network_security_group_id = azurerm_network_security_group.west.id +} + +resource "azurerm_private_dns_zone" "west" { + name = "${random_pet.name_prefix.id}-pdz.postgres.database.azure.com" + resource_group_name = azurerm_resource_group.west.name + + depends_on = [azurerm_subnet_network_security_group_association.west] +} + +resource "azurerm_virtual_network_peering" "west" { + name = "west-to-east" + resource_group_name = azurerm_resource_group.west.name + virtual_network_name = azurerm_virtual_network.west.name + remote_virtual_network_id = azurerm_virtual_network.east.id + allow_virtual_network_access = true + allow_forwarded_traffic = true +} + +resource "azurerm_private_dns_zone_virtual_network_link" "west" { + name = "${random_pet.name_prefix.id}-west-pdzvnetlink.com" + private_dns_zone_name = azurerm_private_dns_zone.west.name + virtual_network_id = azurerm_virtual_network.west.id + resource_group_name = azurerm_resource_group.west.name + + depends_on = [azurerm_virtual_network_peering.west] +} + +resource "azurerm_postgresql_flexible_server" "west" { + name = "${random_pet.name_prefix.id}-west-pg" + resource_group_name = azurerm_resource_group.west.name + location = azurerm_resource_group.west.location + create_mode = "Replica" + source_server_id = azurerm_postgresql_flexible_server.east.id + version = azurerm_postgresql_flexible_server.east.version + public_network_access_enabled = azurerm_postgresql_flexible_server.east.public_network_access_enabled + sku_name = azurerm_postgresql_flexible_server.east.sku_name + + delegated_subnet_id = azurerm_subnet.west.id + private_dns_zone_id = azurerm_private_dns_zone.west.id + + depends_on = [azurerm_private_dns_zone_virtual_network_link.west] + + lifecycle { + ignore_changes = [zone] + } + + timeouts { + create = "120m" + } +} +` +} From 94e28c5de14955a188f90192c06828946f9a6fcc Mon Sep 17 00:00:00 2001 From: Bruce Harrison Date: Tue, 1 Oct 2024 13:27:09 -0500 Subject: [PATCH 04/22] improve tests --- ...exible_server_virtual_endpoint_resource.go | 6 +-- ...e_server_virtual_endpoint_resource_test.go | 50 ++++++++----------- 2 files changed, 24 insertions(+), 32 deletions(-) diff --git a/internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource.go b/internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource.go index a3c8ea45f89d..1836733d796b 100644 --- a/internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource.go +++ b/internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource.go @@ -253,12 +253,12 @@ func lookupFlexibleServerByName(ctx context.Context, flexibleServerClient *serve } // loop to find the replica server associated with this flexible endpoint - var replicaServer servers.Server for i := 0; i < len(postgresServers.Items); i++ { postgresServer := postgresServers.Items[i] if postgresServer.Properties.SourceServerResourceId != nil && *postgresServer.Properties.SourceServerResourceId == sourceServerId { - replicaServer = postgresServer + return &postgresServer, nil } } - return &replicaServer, nil + + return nil, fmt.Errorf("could not locate postgres replica server with name %s", replicaServerName) } diff --git a/internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource_test.go b/internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource_test.go index 2371028f4528..e6e92808735f 100644 --- a/internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource_test.go +++ b/internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource_test.go @@ -66,14 +66,14 @@ func TestAccPostgresqlFlexibleServerVirtualEndpoint_cross_region(t *testing.T) { data.ResourceTest(t, r, []acceptance.TestStep{ { - Config: r.crossRegion(), + Config: r.crossRegion(data), Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, data.ImportStep(), data.DisappearsStep(acceptance.DisappearsStepData{ - Config: r.basic, + Config: r.crossRegion, TestResource: r, }), }) @@ -220,32 +220,28 @@ resource "azurerm_postgresql_flexible_server_virtual_endpoint" "test" { } /** Complex test cases across regions and resource groups */ -func (PostgresqlFlexibleServerVirtualEndpointResource) crossRegion() string { - return ` +func (PostgresqlFlexibleServerVirtualEndpointResource) crossRegion(data acceptance.TestData) string { + return fmt.Sprintf(` provider "azurerm" { features {} } -resource "random_pet" "name_prefix" { - length = 1 -} - ###### EAST RG ###### resource "azurerm_resource_group" "east" { - name = "${random_pet.name_prefix.id}-east" + name = "%[1]d-east" location = "eastus" } resource "azurerm_virtual_network" "east" { - name = "${random_pet.name_prefix.id}-east-vn" + name = "%[1]d-east-vn" location = azurerm_resource_group.east.location resource_group_name = azurerm_resource_group.east.name address_space = ["10.0.0.0/16"] } resource "azurerm_network_security_group" "east" { - name = "${random_pet.name_prefix.id}-east-nsg" + name = "%[1]d-east-nsg" location = azurerm_resource_group.east.location resource_group_name = azurerm_resource_group.east.name @@ -263,7 +259,7 @@ resource "azurerm_network_security_group" "east" { } resource "azurerm_subnet" "east" { - name = "${random_pet.name_prefix.id}-east-sn" + name = "%[1]d-east-sn" resource_group_name = azurerm_resource_group.east.name virtual_network_name = azurerm_virtual_network.east.name address_prefixes = ["10.0.1.0/24"] @@ -286,7 +282,7 @@ resource "azurerm_subnet_network_security_group_association" "east" { } resource "azurerm_private_dns_zone" "east" { - name = "${random_pet.name_prefix.id}-pdz.postgres.database.azure.com" + name = "%[1]d-pdz.postgres.database.azure.com" resource_group_name = azurerm_resource_group.east.name depends_on = [azurerm_subnet_network_security_group_association.east] @@ -302,7 +298,7 @@ resource "azurerm_virtual_network_peering" "east" { } resource "azurerm_private_dns_zone_virtual_network_link" "east" { - name = "${random_pet.name_prefix.id}-east-pdzvnetlink.com" + name = "%[1]d-east-pdzvnetlink.com" private_dns_zone_name = azurerm_private_dns_zone.east.name virtual_network_id = azurerm_virtual_network.east.id resource_group_name = azurerm_resource_group.east.name @@ -310,18 +306,14 @@ resource "azurerm_private_dns_zone_virtual_network_link" "east" { depends_on = [azurerm_virtual_network_peering.east] } -resource "random_password" "pass" { - length = 20 -} - resource "azurerm_postgresql_flexible_server" "east" { - name = "${random_pet.name_prefix.id}-east-pg" + name = "%[1]d-east-pg" resource_group_name = azurerm_resource_group.east.name location = azurerm_resource_group.east.location version = "13" public_network_access_enabled = false administrator_login = "adminTerraform" - administrator_password = random_password.pass.result + administrator_password = "maLTq5SnDBrWfyban7Wz" sku_name = "GP_Standard_D2s_v3" delegated_subnet_id = azurerm_subnet.east.id @@ -339,7 +331,7 @@ resource "azurerm_postgresql_flexible_server" "east" { } resource "azurerm_postgresql_flexible_server_virtual_endpoint" "test" { - name = "${random_pet.name_prefix.id}-endpoint" + name = "%[1]d-endpoint" source_server_id = azurerm_postgresql_flexible_server.east.id replica_server_id = azurerm_postgresql_flexible_server.west.id type = "ReadWrite" @@ -348,19 +340,19 @@ resource "azurerm_postgresql_flexible_server_virtual_endpoint" "test" { ###### WEST RG ###### resource "azurerm_resource_group" "west" { - name = "${random_pet.name_prefix.id}-west" + name = "%[1]d-west" location = "westus" } resource "azurerm_virtual_network" "west" { - name = "${random_pet.name_prefix.id}-west-vn" + name = "%[1]d-west-vn" location = azurerm_resource_group.west.location resource_group_name = azurerm_resource_group.west.name address_space = ["11.0.0.0/16"] } resource "azurerm_network_security_group" "west" { - name = "${random_pet.name_prefix.id}-west-nsg" + name = "%[1]d-west-nsg" location = azurerm_resource_group.west.location resource_group_name = azurerm_resource_group.west.name @@ -378,7 +370,7 @@ resource "azurerm_network_security_group" "west" { } resource "azurerm_subnet" "west" { - name = "${random_pet.name_prefix.id}-west-sn" + name = "%[1]d-west-sn" resource_group_name = azurerm_resource_group.west.name virtual_network_name = azurerm_virtual_network.west.name address_prefixes = ["11.0.1.0/24"] @@ -401,7 +393,7 @@ resource "azurerm_subnet_network_security_group_association" "west" { } resource "azurerm_private_dns_zone" "west" { - name = "${random_pet.name_prefix.id}-pdz.postgres.database.azure.com" + name = "%[1]d-pdz.postgres.database.azure.com" resource_group_name = azurerm_resource_group.west.name depends_on = [azurerm_subnet_network_security_group_association.west] @@ -417,7 +409,7 @@ resource "azurerm_virtual_network_peering" "west" { } resource "azurerm_private_dns_zone_virtual_network_link" "west" { - name = "${random_pet.name_prefix.id}-west-pdzvnetlink.com" + name = "%[1]d-west-pdzvnetlink.com" private_dns_zone_name = azurerm_private_dns_zone.west.name virtual_network_id = azurerm_virtual_network.west.id resource_group_name = azurerm_resource_group.west.name @@ -426,7 +418,7 @@ resource "azurerm_private_dns_zone_virtual_network_link" "west" { } resource "azurerm_postgresql_flexible_server" "west" { - name = "${random_pet.name_prefix.id}-west-pg" + name = "%[1]d-west-pg" resource_group_name = azurerm_resource_group.west.name location = azurerm_resource_group.west.location create_mode = "Replica" @@ -448,5 +440,5 @@ resource "azurerm_postgresql_flexible_server" "west" { create = "120m" } } -` +`, data.RandomInteger) } From 45a1fa317169afc6c4e366370a30cdec49f5278d Mon Sep 17 00:00:00 2001 From: Bruce Harrison Date: Wed, 2 Oct 2024 15:03:42 -0500 Subject: [PATCH 05/22] Update internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource_test.go Co-authored-by: jackofallops <11830746+jackofallops@users.noreply.github.com> --- ...postgresql_flexible_server_virtual_endpoint_resource_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource_test.go b/internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource_test.go index e6e92808735f..e0639bd68946 100644 --- a/internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource_test.go +++ b/internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource_test.go @@ -229,7 +229,7 @@ provider "azurerm" { ###### EAST RG ###### resource "azurerm_resource_group" "east" { - name = "%[1]d-east" + name = "acctest%[1]d-east" location = "eastus" } From 7cf743ede9898158386c8069d6ff6dfec5d7028d Mon Sep 17 00:00:00 2001 From: Bruce Harrison Date: Wed, 2 Oct 2024 15:03:50 -0500 Subject: [PATCH 06/22] Update internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource_test.go Co-authored-by: jackofallops <11830746+jackofallops@users.noreply.github.com> --- ...postgresql_flexible_server_virtual_endpoint_resource_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource_test.go b/internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource_test.go index e0639bd68946..374d41cdba1c 100644 --- a/internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource_test.go +++ b/internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource_test.go @@ -340,7 +340,7 @@ resource "azurerm_postgresql_flexible_server_virtual_endpoint" "test" { ###### WEST RG ###### resource "azurerm_resource_group" "west" { - name = "%[1]d-west" + name = "acctest%[1]d-west" location = "westus" } From 5e047bd1181f913e194a06b7551e7883214f5c92 Mon Sep 17 00:00:00 2001 From: Bruce Harrison Date: Wed, 2 Oct 2024 15:03:56 -0500 Subject: [PATCH 07/22] Update internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource_test.go Co-authored-by: jackofallops <11830746+jackofallops@users.noreply.github.com> --- ...postgresql_flexible_server_virtual_endpoint_resource_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource_test.go b/internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource_test.go index 374d41cdba1c..113564ffad74 100644 --- a/internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource_test.go +++ b/internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource_test.go @@ -234,7 +234,7 @@ resource "azurerm_resource_group" "east" { } resource "azurerm_virtual_network" "east" { - name = "%[1]d-east-vn" + name = "acctest%[1]d-east-vn" location = azurerm_resource_group.east.location resource_group_name = azurerm_resource_group.east.name address_space = ["10.0.0.0/16"] From f9c1d75c39f07d3be164ea1678f5985d4fbb3124 Mon Sep 17 00:00:00 2001 From: Bruce Harrison Date: Wed, 2 Oct 2024 15:04:02 -0500 Subject: [PATCH 08/22] Update internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource_test.go Co-authored-by: jackofallops <11830746+jackofallops@users.noreply.github.com> --- ...postgresql_flexible_server_virtual_endpoint_resource_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource_test.go b/internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource_test.go index 113564ffad74..cc3b8885d405 100644 --- a/internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource_test.go +++ b/internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource_test.go @@ -241,7 +241,7 @@ resource "azurerm_virtual_network" "east" { } resource "azurerm_network_security_group" "east" { - name = "%[1]d-east-nsg" + name = "acctest%[1]d-east-nsg" location = azurerm_resource_group.east.location resource_group_name = azurerm_resource_group.east.name From 251b50a402c4dc5652bb75ff82681cbff4c83236 Mon Sep 17 00:00:00 2001 From: Bruce Harrison Date: Wed, 2 Oct 2024 15:04:07 -0500 Subject: [PATCH 09/22] Update internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource_test.go Co-authored-by: jackofallops <11830746+jackofallops@users.noreply.github.com> --- ...postgresql_flexible_server_virtual_endpoint_resource_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource_test.go b/internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource_test.go index cc3b8885d405..f309be454a96 100644 --- a/internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource_test.go +++ b/internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource_test.go @@ -259,7 +259,7 @@ resource "azurerm_network_security_group" "east" { } resource "azurerm_subnet" "east" { - name = "%[1]d-east-sn" + name = "acctest%[1]d-east-sn" resource_group_name = azurerm_resource_group.east.name virtual_network_name = azurerm_virtual_network.east.name address_prefixes = ["10.0.1.0/24"] From 2cb98cc1704c2a4eda36acf9bc1428aba5baf888 Mon Sep 17 00:00:00 2001 From: Bruce Harrison Date: Wed, 2 Oct 2024 15:04:23 -0500 Subject: [PATCH 10/22] Update internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource_test.go Co-authored-by: jackofallops <11830746+jackofallops@users.noreply.github.com> --- ...postgresql_flexible_server_virtual_endpoint_resource_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource_test.go b/internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource_test.go index f309be454a96..d330e59b0a20 100644 --- a/internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource_test.go +++ b/internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource_test.go @@ -282,7 +282,7 @@ resource "azurerm_subnet_network_security_group_association" "east" { } resource "azurerm_private_dns_zone" "east" { - name = "%[1]d-pdz.postgres.database.azure.com" + name = "acctest%[1]d-pdz.postgres.database.azure.com" resource_group_name = azurerm_resource_group.east.name depends_on = [azurerm_subnet_network_security_group_association.east] From 387338ca5f65330f109c287c0bd0c3c89f1a6d0f Mon Sep 17 00:00:00 2001 From: Bruce Harrison Date: Wed, 2 Oct 2024 15:04:33 -0500 Subject: [PATCH 11/22] Update internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource_test.go Co-authored-by: jackofallops <11830746+jackofallops@users.noreply.github.com> --- ...postgresql_flexible_server_virtual_endpoint_resource_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource_test.go b/internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource_test.go index d330e59b0a20..4fd4405e0050 100644 --- a/internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource_test.go +++ b/internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource_test.go @@ -298,7 +298,7 @@ resource "azurerm_virtual_network_peering" "east" { } resource "azurerm_private_dns_zone_virtual_network_link" "east" { - name = "%[1]d-east-pdzvnetlink.com" + name = "acctest%[1]d-east-pdzvnetlink.com" private_dns_zone_name = azurerm_private_dns_zone.east.name virtual_network_id = azurerm_virtual_network.east.id resource_group_name = azurerm_resource_group.east.name From 7b5d15a565bfd199b688bfc141a970e1f3a987e2 Mon Sep 17 00:00:00 2001 From: Bruce Harrison Date: Wed, 2 Oct 2024 15:04:43 -0500 Subject: [PATCH 12/22] Update internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource_test.go Co-authored-by: jackofallops <11830746+jackofallops@users.noreply.github.com> --- ...postgresql_flexible_server_virtual_endpoint_resource_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource_test.go b/internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource_test.go index 4fd4405e0050..74f93fdd92ae 100644 --- a/internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource_test.go +++ b/internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource_test.go @@ -307,7 +307,7 @@ resource "azurerm_private_dns_zone_virtual_network_link" "east" { } resource "azurerm_postgresql_flexible_server" "east" { - name = "%[1]d-east-pg" + name = "acctest%[1]d-east-pg" resource_group_name = azurerm_resource_group.east.name location = azurerm_resource_group.east.location version = "13" From 20063328060fabd80701cedd7c206cdf4510d47c Mon Sep 17 00:00:00 2001 From: Bruce Harrison Date: Wed, 2 Oct 2024 15:04:50 -0500 Subject: [PATCH 13/22] Update internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource_test.go Co-authored-by: jackofallops <11830746+jackofallops@users.noreply.github.com> --- ...postgresql_flexible_server_virtual_endpoint_resource_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource_test.go b/internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource_test.go index 74f93fdd92ae..5af128f51b27 100644 --- a/internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource_test.go +++ b/internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource_test.go @@ -400,7 +400,7 @@ resource "azurerm_private_dns_zone" "west" { } resource "azurerm_virtual_network_peering" "west" { - name = "west-to-east" + name = "acctest-pfs%[1]d-west-to-east" resource_group_name = azurerm_resource_group.west.name virtual_network_name = azurerm_virtual_network.west.name remote_virtual_network_id = azurerm_virtual_network.east.id From e17cc5969ce13be5fcc4d8172f1bc2528b5c6987 Mon Sep 17 00:00:00 2001 From: Bruce Harrison Date: Wed, 2 Oct 2024 15:05:00 -0500 Subject: [PATCH 14/22] Update internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource_test.go Co-authored-by: jackofallops <11830746+jackofallops@users.noreply.github.com> --- ...postgresql_flexible_server_virtual_endpoint_resource_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource_test.go b/internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource_test.go index 5af128f51b27..649e224ee5bd 100644 --- a/internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource_test.go +++ b/internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource_test.go @@ -331,7 +331,7 @@ resource "azurerm_postgresql_flexible_server" "east" { } resource "azurerm_postgresql_flexible_server_virtual_endpoint" "test" { - name = "%[1]d-endpoint" + name = "acctest%[1]d-endpoint" source_server_id = azurerm_postgresql_flexible_server.east.id replica_server_id = azurerm_postgresql_flexible_server.west.id type = "ReadWrite" From cfcac61fa9dfbcd7dd09e5ae1e0238adb7625c3c Mon Sep 17 00:00:00 2001 From: Bruce Harrison Date: Wed, 2 Oct 2024 15:05:07 -0500 Subject: [PATCH 15/22] Update internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource_test.go Co-authored-by: jackofallops <11830746+jackofallops@users.noreply.github.com> --- ...postgresql_flexible_server_virtual_endpoint_resource_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource_test.go b/internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource_test.go index 649e224ee5bd..8c30e5ae4035 100644 --- a/internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource_test.go +++ b/internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource_test.go @@ -345,7 +345,7 @@ resource "azurerm_resource_group" "west" { } resource "azurerm_virtual_network" "west" { - name = "%[1]d-west-vn" + name = "acctest%[1]d-west-vn" location = azurerm_resource_group.west.location resource_group_name = azurerm_resource_group.west.name address_space = ["11.0.0.0/16"] From be50e69c832bd980b9b745eb4a4619338e772c4f Mon Sep 17 00:00:00 2001 From: Bruce Harrison Date: Wed, 2 Oct 2024 15:05:15 -0500 Subject: [PATCH 16/22] Update internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource_test.go Co-authored-by: jackofallops <11830746+jackofallops@users.noreply.github.com> --- ...postgresql_flexible_server_virtual_endpoint_resource_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource_test.go b/internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource_test.go index 8c30e5ae4035..8ec9262ad0de 100644 --- a/internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource_test.go +++ b/internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource_test.go @@ -352,7 +352,7 @@ resource "azurerm_virtual_network" "west" { } resource "azurerm_network_security_group" "west" { - name = "%[1]d-west-nsg" + name = "acctest%[1]d-west-nsg" location = azurerm_resource_group.west.location resource_group_name = azurerm_resource_group.west.name From a6106be09d2b18728d74834b13a55375f2e249a0 Mon Sep 17 00:00:00 2001 From: Bruce Harrison Date: Wed, 2 Oct 2024 15:05:23 -0500 Subject: [PATCH 17/22] Update internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource_test.go Co-authored-by: jackofallops <11830746+jackofallops@users.noreply.github.com> --- ...postgresql_flexible_server_virtual_endpoint_resource_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource_test.go b/internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource_test.go index 8ec9262ad0de..8af3d1783922 100644 --- a/internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource_test.go +++ b/internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource_test.go @@ -370,7 +370,7 @@ resource "azurerm_network_security_group" "west" { } resource "azurerm_subnet" "west" { - name = "%[1]d-west-sn" + name = "acctest%[1]d-west-sn" resource_group_name = azurerm_resource_group.west.name virtual_network_name = azurerm_virtual_network.west.name address_prefixes = ["11.0.1.0/24"] From 360432c54c0686fe8f3bd33d988c7728fc1d9471 Mon Sep 17 00:00:00 2001 From: Bruce Harrison Date: Wed, 2 Oct 2024 15:05:31 -0500 Subject: [PATCH 18/22] Update internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource_test.go Co-authored-by: jackofallops <11830746+jackofallops@users.noreply.github.com> --- ...postgresql_flexible_server_virtual_endpoint_resource_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource_test.go b/internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource_test.go index 8af3d1783922..e7b717764d9b 100644 --- a/internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource_test.go +++ b/internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource_test.go @@ -393,7 +393,7 @@ resource "azurerm_subnet_network_security_group_association" "west" { } resource "azurerm_private_dns_zone" "west" { - name = "%[1]d-pdz.postgres.database.azure.com" + name = "acctest%[1]d-pdz.postgres.database.azure.com" resource_group_name = azurerm_resource_group.west.name depends_on = [azurerm_subnet_network_security_group_association.west] From e095372ac1b304e70b829bb786e8c4ba392fe065 Mon Sep 17 00:00:00 2001 From: Bruce Harrison Date: Wed, 2 Oct 2024 15:05:42 -0500 Subject: [PATCH 19/22] Update internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource_test.go Co-authored-by: jackofallops <11830746+jackofallops@users.noreply.github.com> --- ...postgresql_flexible_server_virtual_endpoint_resource_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource_test.go b/internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource_test.go index e7b717764d9b..fbd2eb74f776 100644 --- a/internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource_test.go +++ b/internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource_test.go @@ -409,7 +409,7 @@ resource "azurerm_virtual_network_peering" "west" { } resource "azurerm_private_dns_zone_virtual_network_link" "west" { - name = "%[1]d-west-pdzvnetlink.com" + name = "acctest%[1]d-west-pdzvnetlink.com" private_dns_zone_name = azurerm_private_dns_zone.west.name virtual_network_id = azurerm_virtual_network.west.id resource_group_name = azurerm_resource_group.west.name From 3484e8ac9618eacadcc52a79a1635a7adbb66964 Mon Sep 17 00:00:00 2001 From: Bruce Harrison Date: Wed, 2 Oct 2024 15:05:47 -0500 Subject: [PATCH 20/22] Update internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource_test.go Co-authored-by: jackofallops <11830746+jackofallops@users.noreply.github.com> --- ...postgresql_flexible_server_virtual_endpoint_resource_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource_test.go b/internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource_test.go index fbd2eb74f776..af5e2bf42221 100644 --- a/internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource_test.go +++ b/internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource_test.go @@ -418,7 +418,7 @@ resource "azurerm_private_dns_zone_virtual_network_link" "west" { } resource "azurerm_postgresql_flexible_server" "west" { - name = "%[1]d-west-pg" + name = "acctest%[1]d-west-pg" resource_group_name = azurerm_resource_group.west.name location = azurerm_resource_group.west.location create_mode = "Replica" From a427e1e08309df91b0bf8f1301d65807e75f07b5 Mon Sep 17 00:00:00 2001 From: Bruce Harrison Date: Wed, 2 Oct 2024 15:38:57 -0500 Subject: [PATCH 21/22] parse server ID before setting state --- ...ostgresql_flexible_server_virtual_endpoint_resource.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource.go b/internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource.go index 1836733d796b..3af93ea0759f 100644 --- a/internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource.go +++ b/internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource.go @@ -172,7 +172,13 @@ func (r PostgresqlFlexibleServerVirtualEndpointResource) Read() sdk.ResourceFunc } state.SourceServerId = sourceServerId - state.ReplicaServerId = *replicaServer.Id + + replicaId, err := servers.ParseFlexibleServerID(*replicaServer.Id) + if err != nil { + return err + } + + state.ReplicaServerId = replicaId.ID() } } From b1bda4dd13b991bf0766dece2ec68fa0f69843fb Mon Sep 17 00:00:00 2001 From: Steph Date: Thu, 24 Oct 2024 14:59:37 +0200 Subject: [PATCH 22/22] minor simplifications on variable assignments and for loop --- ...exible_server_virtual_endpoint_resource.go | 23 ++++++++++--------- ...e_server_virtual_endpoint_resource_test.go | 2 +- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource.go b/internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource.go index 3af93ea0759f..c5ca00ab05bf 100644 --- a/internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource.go +++ b/internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource.go @@ -161,8 +161,8 @@ func (r PostgresqlFlexibleServerVirtualEndpointResource) Read() sdk.ResourceFunc } // Model.Properties.Members is a tuple => [source_server_id, replication_server_name] - sourceServerName := (*resp.Model.Properties.Members)[0] - replicaServerName := (*resp.Model.Properties.Members)[1] + sourceServerName := (*props.Members)[0] + replicaServerName := (*props.Members)[1] sourceServerId := servers.NewFlexibleServerID(id.SubscriptionId, id.ResourceGroupName, sourceServerName).ID() @@ -173,12 +173,14 @@ func (r PostgresqlFlexibleServerVirtualEndpointResource) Read() sdk.ResourceFunc state.SourceServerId = sourceServerId - replicaId, err := servers.ParseFlexibleServerID(*replicaServer.Id) - if err != nil { - return err - } + if replicaServer != nil { + replicaId, err := servers.ParseFlexibleServerID(*replicaServer.Id) + if err != nil { + return err + } - state.ReplicaServerId = replicaId.ID() + state.ReplicaServerId = replicaId.ID() + } } } @@ -259,10 +261,9 @@ func lookupFlexibleServerByName(ctx context.Context, flexibleServerClient *serve } // loop to find the replica server associated with this flexible endpoint - for i := 0; i < len(postgresServers.Items); i++ { - postgresServer := postgresServers.Items[i] - if postgresServer.Properties.SourceServerResourceId != nil && *postgresServer.Properties.SourceServerResourceId == sourceServerId { - return &postgresServer, nil + for _, server := range postgresServers.Items { + if server.Properties != nil && pointer.From(server.Properties.SourceServerResourceId) == sourceServerId { + return &server, nil } } diff --git a/internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource_test.go b/internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource_test.go index af5e2bf42221..1d2973e58f6c 100644 --- a/internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource_test.go +++ b/internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource_test.go @@ -60,7 +60,7 @@ func TestAccPostgresqlFlexibleServerVirtualEndpoint_update(t *testing.T) { }) } -func TestAccPostgresqlFlexibleServerVirtualEndpoint_cross_region(t *testing.T) { +func TestAccPostgresqlFlexibleServerVirtualEndpoint_crossRegion(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_postgresql_flexible_server_virtual_endpoint", "test") r := PostgresqlFlexibleServerVirtualEndpointResource{}