From 927bf9e5ed8af33b3f260672d1261057e5a74bd0 Mon Sep 17 00:00:00 2001 From: neil-yechenwei Date: Thu, 9 Feb 2023 12:24:49 +0800 Subject: [PATCH] azurerm_postgresql_flexible_server_active_directory_administrator - add locks to fix concurrent issue --- ...ostgresql_flexible_server_aad_administrator_resource.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/internal/services/postgres/postgresql_flexible_server_aad_administrator_resource.go b/internal/services/postgres/postgresql_flexible_server_aad_administrator_resource.go index c6eceb5531c7..794d037c4779 100644 --- a/internal/services/postgres/postgresql_flexible_server_aad_administrator_resource.go +++ b/internal/services/postgres/postgresql_flexible_server_aad_administrator_resource.go @@ -10,6 +10,7 @@ import ( "github.com/hashicorp/go-azure-sdk/resource-manager/postgresql/2022-12-01/administrators" "github.com/hashicorp/terraform-provider-azurerm/helpers/tf" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" + "github.com/hashicorp/terraform-provider-azurerm/internal/locks" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation" "github.com/hashicorp/terraform-provider-azurerm/internal/timeouts" @@ -85,6 +86,9 @@ func resourcePostgresqlFlexibleServerAdministratorCreate(d *pluginsdk.ResourceDa id := administrators.NewAdministratorID(subscriptionId, d.Get("resource_group_name").(string), d.Get("server_name").(string), d.Get("object_id").(string)) + locks.ByName(id.FlexibleServerName, postgresqlFlexibleServerResourceName) + defer locks.UnlockByName(id.FlexibleServerName, postgresqlFlexibleServerResourceName) + if d.IsNewResource() { existing, err := client.Get(ctx, id) if err != nil { @@ -162,6 +166,9 @@ func resourcePostgresqlFlexibleServerAdministratorDelete(d *pluginsdk.ResourceDa return err } + locks.ByName(id.FlexibleServerName, postgresqlFlexibleServerResourceName) + defer locks.UnlockByName(id.FlexibleServerName, postgresqlFlexibleServerResourceName) + if err := client.DeleteThenPoll(ctx, *id); err != nil { return fmt.Errorf("deleting %s: %+v", *id, err) }