From 8d5dbb882c2d157de269535198925ca1b604eb3e Mon Sep 17 00:00:00 2001 From: Lance <74246744+Lance52259@users.noreply.github.com> Date: Wed, 31 Mar 2021 10:36:18 +0800 Subject: [PATCH] fix: vpcep approval can working cross-project (#1010) --- .../resource_huaweicloud_vpcep_approval.go | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/huaweicloud/resource_huaweicloud_vpcep_approval.go b/huaweicloud/resource_huaweicloud_vpcep_approval.go index 4ec7e16296..80463cc458 100644 --- a/huaweicloud/resource_huaweicloud_vpcep_approval.go +++ b/huaweicloud/resource_huaweicloud_vpcep_approval.go @@ -194,7 +194,7 @@ func doConnectionAction(d *schema.ResourceData, client *golangsdk.ServiceClient, stateConf := &resource.StateChangeConf{ Pending: []string{"creating", "pendingAcceptance"}, Target: []string{targetStatus}, - Refresh: waitForVPCEndpointStatus(client, epID), + Refresh: waitForVPCEndpointConnected(client, serviceID, epID), Timeout: d.Timeout(schema.TimeoutCreate), Delay: 3 * time.Second, MinTimeout: 3 * time.Second, @@ -210,3 +210,22 @@ func doConnectionAction(d *schema.ResourceData, client *golangsdk.ServiceClient, return nil } + +func waitForVPCEndpointConnected(vpcepClient *golangsdk.ServiceClient, serviceId, endpointId string) resource.StateRefreshFunc { + return func() (interface{}, string, error) { + listOpts := services.ListConnOpts{ + EndpointID: endpointId, + } + connections, err := services.ListConnections(vpcepClient, serviceId, listOpts) + if err != nil { + if _, ok := err.(golangsdk.ErrDefault404); ok { + return connections, "deleted", nil + } + return connections, "error", err + } + if len(connections) == 1 && connections[0].EndpointID == endpointId { + return connections, connections[0].Status, nil + } + return connections, "deleted", nil + } +}