Skip to content

Commit

Permalink
resource/alicloud_privatelink_vpc_endpoint_zone: Silent error reporti…
Browse files Browse the repository at this point in the history
…ng while delete unexist instance.
  • Loading branch information
ChenHanZhang committed Oct 17, 2024
1 parent 5de90e5 commit cb1fd78
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 27 deletions.
34 changes: 20 additions & 14 deletions alicloud/resource_alicloud_privatelink_vpc_endpoint_zone.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func resourceAliCloudPrivateLinkVpcEndpointZoneCreate(d *schema.ResourceData, me
request = make(map[string]interface{})
query["EndpointId"] = d.Get("endpoint_id")
query["ZoneId"] = d.Get("zone_id")
request["RegionId"] = client.RegionId
query["RegionId"] = client.RegionId
request["ClientToken"] = buildClientToken(action)

request["VSwitchId"] = d.Get("vswitch_id")
Expand All @@ -98,18 +98,16 @@ func resourceAliCloudPrivateLinkVpcEndpointZoneCreate(d *schema.ResourceData, me
wait := incrementalWait(3*time.Second, 5*time.Second)
err = resource.Retry(d.Timeout(schema.TimeoutCreate), func() *resource.RetryError {
response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2020-04-15"), StringPointer("AK"), query, request, &runtime)
request["ClientToken"] = buildClientToken(action)

if err != nil {
if IsExpectedErrors(err, []string{"EndpointLocked", "EndpointConnectionOperationDenied", "EndpointOperationDenied", "ConcurrentCallNotSupported"}) || NeedRetry(err) {
wait()
return resource.RetryableError(err)
}
return resource.NonRetryableError(err)
}
addDebug(action, response, request)
return nil
})
addDebug(action, response, request)

if err != nil {
return WrapErrorf(err, DefaultErrorMsg, "alicloud_privatelink_vpc_endpoint_zone", action, AlibabaCloudSdkGoERROR)
Expand Down Expand Up @@ -140,15 +138,22 @@ func resourceAliCloudPrivateLinkVpcEndpointZoneRead(d *schema.ResourceData, meta
return WrapError(err)
}

d.Set("eni_ip", objectRaw["EniIp"])
d.Set("status", objectRaw["ZoneStatus"])
d.Set("vswitch_id", objectRaw["VSwitchId"])
parts, err := ParseResourceId(d.Id(), 2)
if err != nil {
return WrapError(err)
if objectRaw["EniIp"] != nil {
d.Set("eni_ip", objectRaw["EniIp"])
}
if objectRaw["ZoneStatus"] != nil {
d.Set("status", objectRaw["ZoneStatus"])
}
if objectRaw["VSwitchId"] != nil {
d.Set("vswitch_id", objectRaw["VSwitchId"])
}
if objectRaw["ZoneId"] != nil {
d.Set("zone_id", objectRaw["ZoneId"])
}

parts := strings.Split(d.Id(), ":")
d.Set("endpoint_id", parts[0])
d.Set("zone_id", parts[1])

return nil
}

Expand All @@ -172,7 +177,7 @@ func resourceAliCloudPrivateLinkVpcEndpointZoneDelete(d *schema.ResourceData, me
request = make(map[string]interface{})
query["EndpointId"] = parts[0]
query["ZoneId"] = parts[1]
request["RegionId"] = client.RegionId
query["RegionId"] = client.RegionId

request["ClientToken"] = buildClientToken(action)

Expand All @@ -193,12 +198,12 @@ func resourceAliCloudPrivateLinkVpcEndpointZoneDelete(d *schema.ResourceData, me
}
return resource.NonRetryableError(err)
}
addDebug(action, response, request)
return nil
})
addDebug(action, response, request)

if err != nil {
if IsExpectedErrors(err, []string{"EndpointZoneNotFound"}) {
if IsExpectedErrors(err, []string{"EndpointZoneNotFound"}) || NotFoundError(err) {
return nil
}
return WrapErrorf(err, DefaultErrorMsg, d.Id(), action, AlibabaCloudSdkGoERROR)
Expand All @@ -209,5 +214,6 @@ func resourceAliCloudPrivateLinkVpcEndpointZoneDelete(d *schema.ResourceData, me
if _, err := stateConf.WaitForState(); err != nil {
return WrapErrorf(err, IdMsg, d.Id())
}

return nil
}
9 changes: 5 additions & 4 deletions alicloud/service_alicloud_private_link_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,7 @@ func (s *PrivateLinkServiceV2) PrivateLinkVpcEndpointServiceResourceStateRefresh
}

// DescribePrivateLinkVpcEndpointServiceResource >>> Encapsulated.

// DescribePrivateLinkVpcEndpointZone <<< Encapsulated get interface for PrivateLink VpcEndpointZone.

func (s *PrivateLinkServiceV2) DescribePrivateLinkVpcEndpointZone(id string) (object map[string]interface{}, err error) {
Expand All @@ -422,7 +423,7 @@ func (s *PrivateLinkServiceV2) DescribePrivateLinkVpcEndpointZone(id string) (ob
request = make(map[string]interface{})
query = make(map[string]interface{})
query["EndpointId"] = parts[0]
request["RegionId"] = client.RegionId
query["RegionId"] = client.RegionId

runtime := util.RuntimeOptions{}
runtime.SetAutoretry(true)
Expand All @@ -437,10 +438,9 @@ func (s *PrivateLinkServiceV2) DescribePrivateLinkVpcEndpointZone(id string) (ob
}
return resource.NonRetryableError(err)
}
addDebug(action, response, request)
return nil
})

addDebug(action, response, request)
if err != nil {
if IsExpectedErrors(err, []string{"EndpointNotFound"}) {
return object, WrapErrorf(Error(GetNotFoundMessage("VpcEndpointZone", id)), NotFoundMsg, response)
Expand All @@ -460,7 +460,7 @@ func (s *PrivateLinkServiceV2) DescribePrivateLinkVpcEndpointZone(id string) (ob
result, _ := v.([]interface{})
for _, v := range result {
item := v.(map[string]interface{})
if item["ZoneId"] != parts[1] {
if fmt.Sprint(item["ZoneId"]) != parts[1] {
continue
}
return item, nil
Expand All @@ -480,6 +480,7 @@ func (s *PrivateLinkServiceV2) PrivateLinkVpcEndpointZoneStateRefreshFunc(id str

v, err := jsonpath.Get(field, object)
currentStatus := fmt.Sprint(v)

for _, failState := range failStates {
if currentStatus == failState {
return object, currentStatus, WrapError(Error(FailedToReachTargetStatus, currentStatus))
Expand Down
14 changes: 5 additions & 9 deletions website/docs/r/privatelink_vpc_endpoint_zone.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ description: |-

# alicloud_privatelink_vpc_endpoint_zone

Provides a Private Link Vpc Endpoint Zone resource.
Provides a Private Link Vpc Endpoint Zone resource.



For information about Private Link Vpc Endpoint Zone and how to use it, see [What is Vpc Endpoint Zone](https://www.alibabacloud.com/help/en/privatelink/latest/api-privatelink-2020-04-15-addzonetovpcendpoint).

Expand All @@ -18,12 +20,6 @@ For information about Private Link Vpc Endpoint Zone and how to use it, see [Wha

Basic Usage

<div style="display: block;margin-bottom: 40px;"><div class="oics-button" style="float: right;position: absolute;margin-bottom: 10px;">
<a href="https://api.aliyun.com/api-tools/terraform?resource=alicloud_privatelink_vpc_endpoint_zone&exampleId=002be05b-cddb-26ee-e297-a2349d72c10955d7a11d&activeTab=example&spm=docs.r.privatelink_vpc_endpoint_zone.0.002be05bcd&intl_lang=EN_US" target="_blank">
<img alt="Open in AliCloud" src="https://img.alicdn.com/imgextra/i1/O1CN01hjjqXv1uYUlY56FyX_!!6000000006049-55-tps-254-36.svg" style="max-height: 44px; max-width: 100%;">
</a>
</div></div>

```terraform
variable "name" {
default = "tf_example"
Expand Down Expand Up @@ -86,11 +82,11 @@ resource "alicloud_privatelink_vpc_endpoint_zone" "example" {

The following arguments are supported:
* `dry_run` - (Optional) Specifies whether to perform only a dry run, without performing the actual request. Valid values:
- **true**: performs only a dry run. The system checks the request for potential issues, including missing parameter values, incorrect request syntax, and service limits. If the request fails the dry run, an error message is returned. If the request passes the dry run, the DryRunOperation error code is returned.
- `true`: performs only a dry run. The system checks the request for potential issues, including missing parameter values, incorrect request syntax, and service limits. If the request fails the dry run, an error message is returned. If the request passes the dry run, the DryRunOperation error code is returned.
- **false (default)**: performs a dry run and performs the actual request. If the request passes the dry run, a 2xx HTTP status code is returned and the operation is performed.
* `endpoint_id` - (Required, ForceNew) The endpoint ID.
* `eni_ip` - (Optional, ForceNew, Computed, Available since v1.212.0) The IP address of the endpoint ENI.
* `vswitch_id` - (Required, ForceNew) The ID of the vSwitch in the zone. .
* `vswitch_id` - (Required, ForceNew) The ID of the vSwitch in the zone.
* `zone_id` - (Optional, ForceNew) The zone ID.

## Attributes Reference
Expand Down

0 comments on commit cb1fd78

Please sign in to comment.