From a9ee7fa046cebf99747ae92ee8104e6d5930cf0a Mon Sep 17 00:00:00 2001 From: zjhe Date: Mon, 11 Apr 2022 11:36:58 +0800 Subject: [PATCH 1/7] try to add retry on creation --- internal/services/network/private_endpoint_resource.go | 1 + 1 file changed, 1 insertion(+) diff --git a/internal/services/network/private_endpoint_resource.go b/internal/services/network/private_endpoint_resource.go index 6bb98833fd41..b0f838f778cb 100644 --- a/internal/services/network/private_endpoint_resource.go +++ b/internal/services/network/private_endpoint_resource.go @@ -14,6 +14,7 @@ import ( "github.com/hashicorp/go-azure-sdk/resource-manager/postgresql/2017-12-01/servers" "github.com/hashicorp/go-azure-sdk/resource-manager/privatedns/2018-09-01/privatezones" "github.com/hashicorp/go-azure-sdk/resource-manager/signalr/2022-02-01/signalr" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/hashicorp/terraform-provider-azurerm/helpers/azure" "github.com/hashicorp/terraform-provider-azurerm/helpers/tf" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" From 651a54516f91029bb36cb6be6ef3c55f2b3eb2ab Mon Sep 17 00:00:00 2001 From: zjhe Date: Wed, 1 Jun 2022 09:44:53 +0800 Subject: [PATCH 2/7] retry on update and poll --- .../network/private_endpoint_resource.go | 37 +++++++++++++------ 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/internal/services/network/private_endpoint_resource.go b/internal/services/network/private_endpoint_resource.go index b0f838f778cb..decfaaa03e7a 100644 --- a/internal/services/network/private_endpoint_resource.go +++ b/internal/services/network/private_endpoint_resource.go @@ -290,17 +290,32 @@ func resourcePrivateEndpointCreate(d *pluginsdk.ResourceData, meta interface{}) //goland:noinspection GoDeferInLoop defer locks.UnlockByName(cosmosDbResId, "azurerm_private_endpoint") } + err = pluginsdk.Retry(d.Timeout(pluginsdk.TimeoutCreate), func() *resource.RetryError { + future, err := client.CreateOrUpdate(ctx, id.ResourceGroup, id.Name, parameters) + if err != nil { + if strings.EqualFold(err.Error(), "is missing required parameter 'group Id'") { + return &resource.RetryError{ + Err: fmt.Errorf("creating Private Endpoint %q (Resource Group %q) due to missing 'group Id', ensure that the 'subresource_names' type is populated: %+v", id.Name, id.ResourceGroup, err), + Retryable: false, + } + } else { + return &resource.RetryError{ + Err: fmt.Errorf("creating Private Endpoint %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err), + Retryable: false, + } + } + } - future, err := client.CreateOrUpdate(ctx, id.ResourceGroup, id.Name, parameters) - if err != nil { - if strings.EqualFold(err.Error(), "is missing required parameter 'group Id'") { - return fmt.Errorf("creating Private Endpoint %q (Resource Group %q) due to missing 'group Id', ensure that the 'subresource_names' type is populated: %+v", id.Name, id.ResourceGroup, err) - } else { - return fmt.Errorf("creating Private Endpoint %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err) + if err = future.WaitForCompletionRef(ctx, client.Client); err != nil { + return &resource.RetryError{ + Err: fmt.Errorf("waiting for creation of Private Endpoint %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err), + Retryable: strings.Contains(strings.ToLower(err.Error()), "retryable"), + } } - } - if err = future.WaitForCompletionRef(ctx, client.Client); err != nil { - return fmt.Errorf("waiting for creation of Private Endpoint %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err) + return nil + }) + if err != nil { + return err } d.SetId(id.ID()) @@ -664,7 +679,7 @@ func flattenPrivateLinkEndpointServiceConnection(serviceConnections *[]network.P // There is a bug from service, the PE created from portal could be with the connection id for postgresql server "Microsoft.DBForPostgreSQL" instead of "Microsoft.DBforPostgreSQL" // and for Mysql and MariaDB if strings.Contains(strings.ToLower(privateConnectionId), "microsoft.dbforpostgresql") { - if serverId, err := servers.ParseServerID(privateConnectionId); err == nil { + if serverId, err := postgresqlParse.ServerID(privateConnectionId); err == nil { privateConnectionId = serverId.ID() } } @@ -726,7 +741,7 @@ func flattenPrivateLinkEndpointServiceConnection(serviceConnections *[]network.P // There is a bug from service, the PE created from portal could be with the connection id for postgresql server "Microsoft.DBForPostgreSQL" instead of "Microsoft.DBforPostgreSQL" // and for Mysql and MariaDB if strings.Contains(strings.ToLower(privateConnectionId), "microsoft.dbforpostgresql") { - if serverId, err := servers.ParseServerID(privateConnectionId); err == nil { + if serverId, err := postgresqlParse.ServerID(privateConnectionId); err == nil { privateConnectionId = serverId.ID() } } From d2775dbdb1fab3b456be1456c3fa8e7815949d04 Mon Sep 17 00:00:00 2001 From: zjhe Date: Fri, 29 Jul 2022 12:38:29 +0800 Subject: [PATCH 3/7] add lock on subnet id on create/update/delete, change retryable error message as kt adviced --- .../network/private_endpoint_resource.go | 15 +++++-- .../network/private_endpoint_resource_test.go | 39 +++++++++++++++++++ 2 files changed, 51 insertions(+), 3 deletions(-) diff --git a/internal/services/network/private_endpoint_resource.go b/internal/services/network/private_endpoint_resource.go index decfaaa03e7a..f889bfe4c340 100644 --- a/internal/services/network/private_endpoint_resource.go +++ b/internal/services/network/private_endpoint_resource.go @@ -290,6 +290,9 @@ func resourcePrivateEndpointCreate(d *pluginsdk.ResourceData, meta interface{}) //goland:noinspection GoDeferInLoop defer locks.UnlockByName(cosmosDbResId, "azurerm_private_endpoint") } + locks.ByName(subnetId, "azurerm_private_endpoint") + defer locks.UnlockByName(subnetId, "azurerm_private_endpoint") + err = pluginsdk.Retry(d.Timeout(pluginsdk.TimeoutCreate), func() *resource.RetryError { future, err := client.CreateOrUpdate(ctx, id.ResourceGroup, id.Name, parameters) if err != nil { @@ -309,7 +312,7 @@ func resourcePrivateEndpointCreate(d *pluginsdk.ResourceData, meta interface{}) if err = future.WaitForCompletionRef(ctx, client.Client); err != nil { return &resource.RetryError{ Err: fmt.Errorf("waiting for creation of Private Endpoint %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err), - Retryable: strings.Contains(strings.ToLower(err.Error()), "retryable"), + Retryable: strings.Contains(strings.ToLower(err.Error()), "Resource is in Updating state and the last operation that updated/is updating the resource is PutSubnetOperation"), } } return nil @@ -395,6 +398,9 @@ func resourcePrivateEndpointUpdate(d *pluginsdk.ResourceData, meta interface{}) Tags: tags.Expand(d.Get("tags").(map[string]interface{})), } + locks.ByName(subnetId, "azurerm_private_endpoint") + defer locks.UnlockByName(subnetId, "azurerm_private_endpoint") + future, err := client.CreateOrUpdate(ctx, id.ResourceGroup, id.Name, parameters) if err != nil { if strings.EqualFold(err.Error(), "is missing required parameter 'group Id'") { @@ -563,6 +569,7 @@ func resourcePrivateEndpointDelete(d *pluginsdk.ResourceData, meta interface{}) } log.Printf("[DEBUG] Deleted the Private DNS Zone Group associated with Private Endpoint %q / Resource Group %q.", id.Name, id.ResourceGroup) + subnetId := d.Get("subnet_id").(string) privateServiceConnections := d.Get("private_service_connection").([]interface{}) parameters := network.PrivateEndpoint{ PrivateEndpointProperties: &network.PrivateEndpointProperties{ @@ -576,6 +583,8 @@ func resourcePrivateEndpointDelete(d *pluginsdk.ResourceData, meta interface{}) //goland:noinspection GoDeferInLoop defer locks.UnlockByName(cosmosDbResId, "azurerm_private_endpoint") } + locks.ByName(subnetId, "azurerm_private_endpoint") + defer locks.UnlockByName(subnetId, "azurerm_private_endpoint") log.Printf("[DEBUG] Deleting the Private Endpoint %q / Resource Group %q..", id.Name, id.ResourceGroup) future, err := client.Delete(ctx, id.ResourceGroup, id.Name) @@ -679,7 +688,7 @@ func flattenPrivateLinkEndpointServiceConnection(serviceConnections *[]network.P // There is a bug from service, the PE created from portal could be with the connection id for postgresql server "Microsoft.DBForPostgreSQL" instead of "Microsoft.DBforPostgreSQL" // and for Mysql and MariaDB if strings.Contains(strings.ToLower(privateConnectionId), "microsoft.dbforpostgresql") { - if serverId, err := postgresqlParse.ServerID(privateConnectionId); err == nil { + if serverId, err := servers.ParseServerID(privateConnectionId); err == nil { privateConnectionId = serverId.ID() } } @@ -741,7 +750,7 @@ func flattenPrivateLinkEndpointServiceConnection(serviceConnections *[]network.P // There is a bug from service, the PE created from portal could be with the connection id for postgresql server "Microsoft.DBForPostgreSQL" instead of "Microsoft.DBforPostgreSQL" // and for Mysql and MariaDB if strings.Contains(strings.ToLower(privateConnectionId), "microsoft.dbforpostgresql") { - if serverId, err := postgresqlParse.ServerID(privateConnectionId); err == nil { + if serverId, err := servers.ParseServerID(privateConnectionId); err == nil { privateConnectionId = serverId.ID() } } diff --git a/internal/services/network/private_endpoint_resource_test.go b/internal/services/network/private_endpoint_resource_test.go index 56bd2a674ce1..f3d1728217f9 100644 --- a/internal/services/network/private_endpoint_resource_test.go +++ b/internal/services/network/private_endpoint_resource_test.go @@ -242,6 +242,25 @@ func (t PrivateEndpointResource) Exists(ctx context.Context, clients *clients.Cl return utils.Bool(resp.ID != nil), nil } +func TestAccPrivateEndpoint_multipleInstances(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_private_endpoint", "test") + r := PrivateEndpointResource{} + + instanceCount := 5 + var checks []pluginsdk.TestCheckFunc + for i := 0; i < instanceCount; i++ { + checks = append(checks, check.That(fmt.Sprintf("%s.%d", data.ResourceName, i)).ExistsInAzure(r)) + } + + config := r.multipleInstances(data, instanceCount) + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: config, + Check: acceptance.ComposeTestCheckFunc(checks...), + }, + }) +} + func (PrivateEndpointResource) template(data acceptance.TestData, seviceCfg string) string { return fmt.Sprintf(` provider "azurerm" { @@ -748,3 +767,23 @@ resource "azurerm_private_endpoint" "test" { } `, r.template(data, r.serviceAutoApprove(data)), data.RandomInteger) } + +func (r PrivateEndpointResource) multipleInstances(data acceptance.TestData, count int) string { + return fmt.Sprintf(` +%s + +resource "azurerm_private_endpoint" "test" { + count = %d + name = "acctest-privatelink-%d-${count.index}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location + subnet_id = azurerm_subnet.endpoint.id + + private_service_connection { + name = azurerm_private_link_service.test.name + is_manual_connection = false + private_connection_resource_id = azurerm_private_link_service.test.id + } +} +`, r.template(data, r.serviceAutoApprove(data)), count, data.RandomInteger) +} From 3f1569a94ccf67b10ed766012c47632059939e9c Mon Sep 17 00:00:00 2001 From: zjhe Date: Fri, 29 Jul 2022 17:10:34 +0800 Subject: [PATCH 4/7] Fix tf lint issue --- internal/services/network/private_endpoint_resource_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/services/network/private_endpoint_resource_test.go b/internal/services/network/private_endpoint_resource_test.go index f3d1728217f9..36a8eee71679 100644 --- a/internal/services/network/private_endpoint_resource_test.go +++ b/internal/services/network/private_endpoint_resource_test.go @@ -773,7 +773,7 @@ func (r PrivateEndpointResource) multipleInstances(data acceptance.TestData, cou %s resource "azurerm_private_endpoint" "test" { - count = %d + count = %d name = "acctest-privatelink-%d-${count.index}" resource_group_name = azurerm_resource_group.test.name location = azurerm_resource_group.test.location From 518663224a04e6ae4f704dc6712cd46cceca5e73 Mon Sep 17 00:00:00 2001 From: zjhe Date: Wed, 10 Aug 2022 14:03:14 +0800 Subject: [PATCH 5/7] Fix private link service id error when use alias by adding retry --- .../network/private_endpoint_resource.go | 31 ++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/internal/services/network/private_endpoint_resource.go b/internal/services/network/private_endpoint_resource.go index f889bfe4c340..836564ff810c 100644 --- a/internal/services/network/private_endpoint_resource.go +++ b/internal/services/network/private_endpoint_resource.go @@ -283,6 +283,15 @@ func resourcePrivateEndpointCreate(d *pluginsdk.ResourceData, meta interface{}) Tags: tags.Expand(d.Get("tags").(map[string]interface{})), } + err = validatePrivateLinkServiceId(*parameters.PrivateEndpointProperties.PrivateLinkServiceConnections) + if err != nil { + return err + } + err = validatePrivateLinkServiceId(*parameters.PrivateEndpointProperties.ManualPrivateLinkServiceConnections) + if err != nil { + return err + } + cosmosDbResIds := getCosmosDbResIdInPrivateServiceConnections(parameters.PrivateEndpointProperties) for _, cosmosDbResId := range cosmosDbResIds { log.Printf("[DEBUG] Add Lock For Private Endpoint %q, lock name: %q", id.Name, cosmosDbResId) @@ -295,12 +304,18 @@ func resourcePrivateEndpointCreate(d *pluginsdk.ResourceData, meta interface{}) err = pluginsdk.Retry(d.Timeout(pluginsdk.TimeoutCreate), func() *resource.RetryError { future, err := client.CreateOrUpdate(ctx, id.ResourceGroup, id.Name, parameters) + if err != nil { if strings.EqualFold(err.Error(), "is missing required parameter 'group Id'") { return &resource.RetryError{ Err: fmt.Errorf("creating Private Endpoint %q (Resource Group %q) due to missing 'group Id', ensure that the 'subresource_names' type is populated: %+v", id.Name, id.ResourceGroup, err), Retryable: false, } + } else if strings.Contains(err.Error(), "PrivateLinkServiceId Invalid private link service id") { + return &resource.RetryError{ + Err: fmt.Errorf("creating Private Endpoint %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err), + Retryable: true, + } } else { return &resource.RetryError{ Err: fmt.Errorf("creating Private Endpoint %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err), @@ -312,7 +327,7 @@ func resourcePrivateEndpointCreate(d *pluginsdk.ResourceData, meta interface{}) if err = future.WaitForCompletionRef(ctx, client.Client); err != nil { return &resource.RetryError{ Err: fmt.Errorf("waiting for creation of Private Endpoint %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err), - Retryable: strings.Contains(strings.ToLower(err.Error()), "Resource is in Updating state and the last operation that updated/is updating the resource is PutSubnetOperation"), + Retryable: false, } } return nil @@ -336,6 +351,20 @@ func resourcePrivateEndpointCreate(d *pluginsdk.ResourceData, meta interface{}) return resourcePrivateEndpointRead(d, meta) } +func validatePrivateLinkServiceId(endpoints []network.PrivateLinkServiceConnection) error { + for _, connection := range endpoints { + _, errors := azure.ValidateResourceID(*connection.PrivateLinkServiceID, "PrivateLinkServiceID") + if len(errors) == 0 { + continue + } + _, errors = validate.PrivateConnectionResourceAlias(*connection.PrivateLinkServiceID, "PrivateLinkServiceID") + if len(errors) != 0 { + return fmt.Errorf("PrivateLinkServiceId Invalid: %q", *connection.PrivateLinkServiceID) + } + } + return nil +} + func getCosmosDbResIdInPrivateServiceConnections(p *network.PrivateEndpointProperties) []string { var ids []string exists := make(map[string]struct{}) From 7a48ddbfbd40ee1225b8308c7a80e5bfc957f120 Mon Sep 17 00:00:00 2001 From: zjhe Date: Wed, 10 Aug 2022 16:40:45 +0800 Subject: [PATCH 6/7] Add update to test. Convert if-elseif to switch to finx golint issue --- .../network/private_endpoint_resource.go | 78 ++++++++++++++----- .../network/private_endpoint_resource_test.go | 41 ++++++++-- 2 files changed, 91 insertions(+), 28 deletions(-) diff --git a/internal/services/network/private_endpoint_resource.go b/internal/services/network/private_endpoint_resource.go index 836564ff810c..a7617490aef7 100644 --- a/internal/services/network/private_endpoint_resource.go +++ b/internal/services/network/private_endpoint_resource.go @@ -304,26 +304,30 @@ func resourcePrivateEndpointCreate(d *pluginsdk.ResourceData, meta interface{}) err = pluginsdk.Retry(d.Timeout(pluginsdk.TimeoutCreate), func() *resource.RetryError { future, err := client.CreateOrUpdate(ctx, id.ResourceGroup, id.Name, parameters) - if err != nil { - if strings.EqualFold(err.Error(), "is missing required parameter 'group Id'") { - return &resource.RetryError{ - Err: fmt.Errorf("creating Private Endpoint %q (Resource Group %q) due to missing 'group Id', ensure that the 'subresource_names' type is populated: %+v", id.Name, id.ResourceGroup, err), - Retryable: false, + switch { + case strings.EqualFold(err.Error(), "is missing required parameter 'group Id'"): + { + return &resource.RetryError{ + Err: fmt.Errorf("creating Private Endpoint %q (Resource Group %q) due to missing 'group Id', ensure that the 'subresource_names' type is populated: %+v", id.Name, id.ResourceGroup, err), + Retryable: false, + } } - } else if strings.Contains(err.Error(), "PrivateLinkServiceId Invalid private link service id") { - return &resource.RetryError{ - Err: fmt.Errorf("creating Private Endpoint %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err), - Retryable: true, + case strings.Contains(err.Error(), "PrivateLinkServiceId Invalid private link service id"): + { + return &resource.RetryError{ + Err: fmt.Errorf("creating Private Endpoint %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err), + Retryable: true, + } } - } else { + default: return &resource.RetryError{ Err: fmt.Errorf("creating Private Endpoint %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err), Retryable: false, } } } - + if err = future.WaitForCompletionRef(ctx, client.Client); err != nil { return &resource.RetryError{ Err: fmt.Errorf("waiting for creation of Private Endpoint %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err), @@ -427,19 +431,53 @@ func resourcePrivateEndpointUpdate(d *pluginsdk.ResourceData, meta interface{}) Tags: tags.Expand(d.Get("tags").(map[string]interface{})), } + err = validatePrivateLinkServiceId(*parameters.PrivateEndpointProperties.PrivateLinkServiceConnections) + if err != nil { + return err + } + err = validatePrivateLinkServiceId(*parameters.PrivateEndpointProperties.ManualPrivateLinkServiceConnections) + if err != nil { + return err + } + locks.ByName(subnetId, "azurerm_private_endpoint") defer locks.UnlockByName(subnetId, "azurerm_private_endpoint") - future, err := client.CreateOrUpdate(ctx, id.ResourceGroup, id.Name, parameters) - if err != nil { - if strings.EqualFold(err.Error(), "is missing required parameter 'group Id'") { - return fmt.Errorf("updating Private Endpoint %q (Resource Group %q) due to missing 'group Id', ensure that the 'subresource_names' type is populated: %+v", id.Name, id.ResourceGroup, err) - } else { - return fmt.Errorf("updating Private Endpoint %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err) + err = pluginsdk.Retry(d.Timeout(pluginsdk.TimeoutCreate), func() *resource.RetryError { + future, err := client.CreateOrUpdate(ctx, id.ResourceGroup, id.Name, parameters) + if err != nil { + switch { + case strings.EqualFold(err.Error(), "is missing required parameter 'group Id'"): + { + return &resource.RetryError{ + Err: fmt.Errorf("updating Private Endpoint %q (Resource Group %q) due to missing 'group Id', ensure that the 'subresource_names' type is populated: %+v", id.Name, id.ResourceGroup, err), + Retryable: false, + } + } + case strings.Contains(err.Error(), "PrivateLinkServiceId Invalid private link service id"): + { + return &resource.RetryError{ + Err: fmt.Errorf("creating Private Endpoint %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err), + Retryable: true, + } + } + default: + return &resource.RetryError{ + Err: fmt.Errorf("updating Private Endpoint %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err), + } + } } - } - if err = future.WaitForCompletionRef(ctx, client.Client); err != nil { - return fmt.Errorf("waiting for update of Private Endpoint %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err) + + if err = future.WaitForCompletionRef(ctx, client.Client); err != nil { + return &resource.RetryError{ + Err: fmt.Errorf("waiting for update of Private Endpoint %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err), + Retryable: false, + } + } + return nil + }) + if err != nil { + return err } // 1 Private Endpoint can have 1 Private DNS Zone Group - so to update we need to Delete & Recreate diff --git a/internal/services/network/private_endpoint_resource_test.go b/internal/services/network/private_endpoint_resource_test.go index 36a8eee71679..e32e8b8fdbc0 100644 --- a/internal/services/network/private_endpoint_resource_test.go +++ b/internal/services/network/private_endpoint_resource_test.go @@ -215,7 +215,7 @@ func TestAccPrivateEndpoint_privateConnectionAlias(t *testing.T) { data.ResourceTest(t, r, []acceptance.TestStep{ { - Config: r.privateConnectionAlias(data), + Config: r.privateConnectionAlias(data, false), Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("subnet_id").Exists(), @@ -228,6 +228,22 @@ func TestAccPrivateEndpoint_privateConnectionAlias(t *testing.T) { }) } +func TestAccPrivateEndpoint_updateToPrivateConnectionAlias(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_private_endpoint", "test") + r := PrivateEndpointResource{} + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.privateConnectionAlias(data, false), + }, + data.ImportStep(), + { + Config: r.privateConnectionAlias(data, true), + }, + data.ImportStep(), + }) +} + func (t PrivateEndpointResource) Exists(ctx context.Context, clients *clients.Client, state *pluginsdk.InstanceState) (*bool, error) { id, err := parse.PrivateEndpointID(state.ID) if err != nil { @@ -270,7 +286,7 @@ provider "azurerm" { data "azurerm_subscription" "current" {} resource "azurerm_resource_group" "test" { - name = "acctestRG-privatelink-%d" + name = "zjhe-acctestRG-privatelink-%d" location = "%s" } @@ -435,7 +451,7 @@ provider "azurerm" { } resource "azurerm_resource_group" "test" { - name = "acctestRG-privatelink-%d" + name = "zjhe-acctestRG-privatelink-%d" location = "%s" } @@ -515,7 +531,7 @@ provider "azurerm" { } resource "azurerm_resource_group" "test" { - name = "acctestRG-privatelink-%d" + name = "zjhe-acctestRG-privatelink-%d" location = "%s" } @@ -590,7 +606,7 @@ provider "azurerm" { } resource "azurerm_resource_group" "test" { - name = "acctestRG-privatelink-%d" + name = "zjhe-acctestRG-privatelink-%d" location = "%s" } @@ -675,7 +691,7 @@ provider "azurerm" { } resource "azurerm_resource_group" "test" { - name = "acctestRG-privatelink-%d" + name = "zjhe-acctestRG-privatelink-%d" location = "%s" } @@ -748,7 +764,15 @@ resource "azurerm_private_endpoint" "test" { `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func (r PrivateEndpointResource) privateConnectionAlias(data acceptance.TestData) string { +func (r PrivateEndpointResource) privateConnectionAlias(data acceptance.TestData, withTags bool) string { + tags := ` + tags = { + env = "TEST" + } +` + if !withTags { + tags = "" + } return fmt.Sprintf(` %s @@ -764,8 +788,9 @@ resource "azurerm_private_endpoint" "test" { private_connection_resource_alias = azurerm_private_link_service.test.alias request_message = "test" } +%s } -`, r.template(data, r.serviceAutoApprove(data)), data.RandomInteger) +`, r.template(data, r.serviceAutoApprove(data)), data.RandomInteger, tags) } func (r PrivateEndpointResource) multipleInstances(data acceptance.TestData, count int) string { From c856eaa3482aa8d779b29537509bc2caa0f7d7e1 Mon Sep 17 00:00:00 2001 From: zjhe Date: Wed, 10 Aug 2022 16:50:38 +0800 Subject: [PATCH 7/7] Fix fmt issue --- internal/services/network/private_endpoint_resource.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/services/network/private_endpoint_resource.go b/internal/services/network/private_endpoint_resource.go index a7617490aef7..b44545122cda 100644 --- a/internal/services/network/private_endpoint_resource.go +++ b/internal/services/network/private_endpoint_resource.go @@ -327,7 +327,7 @@ func resourcePrivateEndpointCreate(d *pluginsdk.ResourceData, meta interface{}) } } } - + if err = future.WaitForCompletionRef(ctx, client.Client); err != nil { return &resource.RetryError{ Err: fmt.Errorf("waiting for creation of Private Endpoint %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err),