Skip to content

Commit

Permalink
[New Resource] - azurerm_postgresql_flexible_server_virtual_endpoint (
Browse files Browse the repository at this point in the history
#26708)

* add virtual endpoint client to postgres client.go

* expose virtual endpoint client

* add resource file

* build out methods

* complete initial pass

* all behaviors implemented

* fix index error

* workaround api limitation

* refine behavior

* remove unnecessary update or create logic

* add test file

* complete basic tests

* fix tests

* first tests pass

* complete tests

* fix fmt

* add docs page

* fix description

* lock region during test

* fix typo

* update docs

* fix timeouts

* update to new format

* add service to typed services list

* add properties to state upon read

* get rid of if/else nesting

* alphabetize services lists

* Update internal/services/postgres/custompollers/postgresql_flexible_server_virtual_endpoint_resource_poller.go

Add context to error message

Co-authored-by: stephybun <[email protected]>

* Update internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource.go

Use built-in function for ID validation

Co-authored-by: stephybun <[email protected]>

* add validation to name prop

* reorder services

* remove test provider feature

* Update website/docs/r/azurerm_postgresql_flexible_server_virtual_endpoint.html.markdown

Capitalization

Co-authored-by: stephybun <[email protected]>

* Update website/docs/r/azurerm_postgresql_flexible_server_virtual_endpoint.html.markdown

use standardized import example

Co-authored-by: stephybun <[email protected]>

* Update internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource_test.go

Use standard error message

Co-authored-by: stephybun <[email protected]>

* Update internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource.go

use standard pointer conversion

Co-authored-by: stephybun <[email protected]>

* add pointer import

* Update internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource.go

properly exit Delete method

Co-authored-by: stephybun <[email protected]>

* Update internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource_test.go

use standard error message

Co-authored-by: stephybun <[email protected]>

* Update internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource.go

use standard pointer conversion

Co-authored-by: stephybun <[email protected]>

* Update internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource_test.go

use more explicit pointer conversion on return type

Co-authored-by: stephybun <[email protected]>

* Update internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource.go

Use consistent styling

Co-authored-by: stephybun <[email protected]>

* fixup

* Update internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource_test.go

remove unnecessary test conditions

Co-authored-by: stephybun <[email protected]>

* fix fmt

* add test for update

* slightly tweak test for readability

* rename docs page, add note

* shorten resource names to avoid errors

* Update internal/services/postgres/postgresql_flexible_server_virtual_endpoint_resource.go

Co-authored-by: stephybun <[email protected]>

---------

Co-authored-by: stephybun <[email protected]>
  • Loading branch information
bruceharrison1984 and stephybun authored Aug 9, 2024
1 parent a6156b2 commit 4af1907
Show file tree
Hide file tree
Showing 23 changed files with 1,554 additions and 23 deletions.
45 changes: 23 additions & 22 deletions internal/provider/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,9 @@ func SupportedTypedServices() []sdk.TypedServiceRegistration {
eventhub.Registration{},
fluidrelay.Registration{},
graphservices.Registration{},
storagecache.Registration{},
hybridcompute.Registration{},
iothub.Registration{},
iotcentral.Registration{},
iothub.Registration{},
keyvault.Registration{},
kusto.Registration{},
labservice.Registration{},
Expand All @@ -187,36 +186,38 @@ func SupportedTypedServices() []sdk.TypedServiceRegistration {
maintenance.Registration{},
managedhsm.Registration{},
media.Registration{},
monitor.Registration{},
mobilenetwork.Registration{},
monitor.Registration{},
mssql.Registration{},
mssqlmanagedinstance.Registration{},
mysql.Registration{},
network.Registration{},
netapp.Registration{},
network.Registration{},
networkfunction.Registration{},
newrelic.Registration{},
nginx.Registration{},
orbital.Registration{},
paloalto.Registration{},
policy.Registration{},
postgres.Registration{},
privatednsresolver.Registration{},
recoveryservices.Registration{},
redis.Registration{},
redhatopenshift.Registration{},
redis.Registration{},
resource.Registration{},
search.Registration{},
securitycenter.Registration{},
sentinel.Registration{},
serviceconnector.Registration{},
servicefabricmanaged.Registration{},
servicenetworking.Registration{},
signalr.Registration{},
springcloud.Registration{},
storage.Registration{},
storagecache.Registration{},
storagemover.Registration{},
signalr.Registration{},
subscription.Registration{},
orbital.Registration{},
streamanalytics.Registration{},
search.Registration{},
springcloud.Registration{},
securitycenter.Registration{},
subscription.Registration{},
systemcentervirtualmachinemanager.Registration{},
vmware.Registration{},
voiceservices.Registration{},
Expand All @@ -234,7 +235,6 @@ func SupportedUntypedServices() []sdk.UntypedServiceRegistration {
analysisservices.Registration{},
apimanagement.Registration{},
appconfiguration.Registration{},
springcloud.Registration{},
applicationinsights.Registration{},
arckubernetes.Registration{},
attestation.Registration{},
Expand All @@ -250,16 +250,16 @@ func SupportedUntypedServices() []sdk.UntypedServiceRegistration {
compute.Registration{},
confidentialledger.Registration{},
connections.Registration{},
containers.Registration{},
consumption.Registration{},
containers.Registration{},
cosmos.Registration{},
customproviders.Registration{},
dashboard.Registration{},
databasemigration.Registration{},
databoxedge.Registration{},
databricks.Registration{},
datadog.Registration{},
datafactory.Registration{},
databasemigration.Registration{},
databoxedge.Registration{},
dataprotection.Registration{},
datashare.Registration{},
desktopvirtualization.Registration{},
Expand All @@ -272,31 +272,31 @@ func SupportedUntypedServices() []sdk.UntypedServiceRegistration {
eventhub.Registration{},
firewall.Registration{},
frontdoor.Registration{},
storagecache.Registration{},
hsm.Registration{},
hdinsight.Registration{},
healthcare.Registration{},
iothub.Registration{},
hsm.Registration{},
iotcentral.Registration{},
iothub.Registration{},
iottimeseriesinsights.Registration{},
keyvault.Registration{},
kusto.Registration{},
legacy.Registration{},
lighthouse.Registration{},
loadbalancer.Registration{},
loganalytics.Registration{},
logic.Registration{},
logz.Registration{},
machinelearning.Registration{},
maintenance.Registration{},
managedapplications.Registration{},
lighthouse.Registration{},
managementgroup.Registration{},
managedhsm.Registration{},
managedidentity.Registration{},
managementgroup.Registration{},
maps.Registration{},
mariadb.Registration{},
media.Registration{},
mixedreality.Registration{},
monitor.Registration{},
managedidentity.Registration{},
mssql.Registration{},
mssqlmanagedinstance.Registration{},
mysql.Registration{},
Expand All @@ -320,12 +320,13 @@ func SupportedUntypedServices() []sdk.UntypedServiceRegistration {
servicebus.Registration{},
servicefabric.Registration{},
signalr.Registration{},
springcloud.Registration{},
sql.Registration{},
storage.Registration{},
storagecache.Registration{},
streamanalytics.Registration{},
subscription.Registration{},
synapse.Registration{},
iottimeseriesinsights.Registration{},
trafficmanager.Registration{},
videoanalyzer.Registration{},
vmware.Registration{},
Expand Down
9 changes: 9 additions & 0 deletions internal/services/postgres/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
flexibleserverdatabases "github.com/hashicorp/go-azure-sdk/resource-manager/postgresql/2022-12-01/databases"
flexibleserverfirewallrules "github.com/hashicorp/go-azure-sdk/resource-manager/postgresql/2022-12-01/firewallrules"
flexibleservers "github.com/hashicorp/go-azure-sdk/resource-manager/postgresql/2023-06-01-preview/servers"
flexibleservervirtualendpoints "github.com/hashicorp/go-azure-sdk/resource-manager/postgresql/2023-06-01-preview/virtualendpoints"
"github.com/hashicorp/terraform-provider-azurerm/internal/common"
)

Expand All @@ -40,6 +41,7 @@ type Client struct {
VirtualNetworkRulesClient *virtualnetworkrules.VirtualNetworkRulesClient
ServerAdministratorsClient *serveradministrators.ServerAdministratorsClient
ReplicasClient *replicas.ReplicasClient
VirtualEndpointClient *flexibleservervirtualendpoints.VirtualEndpointsClient
}

func NewClient(o *common.ClientOptions) (*Client, error) {
Expand Down Expand Up @@ -133,6 +135,12 @@ func NewClient(o *common.ClientOptions) (*Client, error) {
}
o.Configure(flexibleServerAdministratorsClient.Client, o.Authorizers.ResourceManager)

virtualEndpointClient, err := flexibleservervirtualendpoints.NewVirtualEndpointsClientWithBaseURI(o.Environment.ResourceManager)
if err != nil {
return nil, fmt.Errorf("building FlexibleServerVirtualEndpoint client: %+v", err)
}
o.Configure(virtualEndpointClient.Client, o.Authorizers.ResourceManager)

return &Client{
ConfigurationsClient: configurationsClient,
DatabasesClient: databasesClient,
Expand All @@ -149,5 +157,6 @@ func NewClient(o *common.ClientOptions) (*Client, error) {
VirtualNetworkRulesClient: virtualNetworkRulesClient,
ServerAdministratorsClient: serverAdministratorsClient,
ReplicasClient: replicasClient,
VirtualEndpointClient: virtualEndpointClient,
}, nil
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// 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),
}
}
Loading

0 comments on commit 4af1907

Please sign in to comment.