Skip to content

Commit

Permalink
resource/alicloud_privatelink_vpc_endpoint_service_user: add new attr…
Browse files Browse the repository at this point in the history
…ibute user_arn.
  • Loading branch information
ChenHanZhang committed Oct 17, 2024
1 parent 3469650 commit d568622
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 27 deletions.
34 changes: 21 additions & 13 deletions alicloud/resource_alicloud_privatelink_vpc_endpoint_service_user.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// Package alicloud. This file is generated automatically. Please do not modify it manually, thank you!
package alicloud

import (
Expand Down Expand Up @@ -37,6 +36,10 @@ func resourceAliCloudPrivateLinkVpcEndpointServiceUser() *schema.Resource {
Required: true,
ForceNew: true,
},
"user_arn": {
Type: schema.TypeString,
Optional: true,
},
"user_id": {
Type: schema.TypeString,
Required: true,
Expand All @@ -61,9 +64,12 @@ func resourceAliCloudPrivateLinkVpcEndpointServiceUserCreate(d *schema.ResourceD
request = make(map[string]interface{})
query["UserId"] = d.Get("user_id")
query["ServiceId"] = d.Get("service_id")
request["RegionId"] = client.RegionId
query["RegionId"] = client.RegionId
request["ClientToken"] = buildClientToken(action)

if v, ok := d.GetOk("user_arn"); ok {
request["UserARN"] = v
}
if v, ok := d.GetOkExists("dry_run"); ok {
request["DryRun"] = v
}
Expand All @@ -72,18 +78,16 @@ func resourceAliCloudPrivateLinkVpcEndpointServiceUserCreate(d *schema.ResourceD
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 NeedRetry(err) {
if IsExpectedErrors(err, []string{"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_service_user", action, AlibabaCloudSdkGoERROR)
Expand All @@ -108,12 +112,13 @@ func resourceAliCloudPrivateLinkVpcEndpointServiceUserRead(d *schema.ResourceDat
return WrapError(err)
}

d.Set("user_id", objectRaw["UserId"])
parts, err := ParseResourceId(d.Id(), 2)
if err != nil {
return WrapError(err)
if objectRaw["UserId"] != nil {
d.Set("user_id", objectRaw["UserId"])
}

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

return nil
}

Expand All @@ -137,10 +142,13 @@ func resourceAliCloudPrivateLinkVpcEndpointServiceUserDelete(d *schema.ResourceD
request = make(map[string]interface{})
query["UserId"] = parts[1]
query["ServiceId"] = parts[0]
request["RegionId"] = client.RegionId
query["RegionId"] = client.RegionId

request["ClientToken"] = buildClientToken(action)

if v, ok := d.GetOk("user_arn"); ok {
request["UserARN"] = v
}
if v, ok := d.GetOkExists("dry_run"); ok {
request["DryRun"] = v
}
Expand All @@ -158,12 +166,12 @@ func resourceAliCloudPrivateLinkVpcEndpointServiceUserDelete(d *schema.ResourceD
}
return resource.NonRetryableError(err)
}
addDebug(action, response, request)
return nil
})
addDebug(action, response, request)

if err != nil {
if IsExpectedErrors(err, []string{"EndpointServiceNotFound"}) {
if NotFoundError(err) {
return nil
}
return WrapErrorf(err, DefaultErrorMsg, d.Id(), action, AlibabaCloudSdkGoERROR)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ func TestUnitAlicloudPrivatelinkVpcEndpointServiceUser(t *testing.T) {
}

// Test PrivateLink VpcEndpointServiceUser. >>> Resource test cases, automatically generated.
// Case 4876
// Case 生命周期测试- VpcEndpointServiceUser 4876
func TestAccAliCloudPrivateLinkVpcEndpointServiceUser_basic4876(t *testing.T) {
var v map[string]interface{}
resourceId := "alicloud_privatelink_vpc_endpoint_service_user.default"
Expand All @@ -311,20 +311,24 @@ func TestAccAliCloudPrivateLinkVpcEndpointServiceUser_basic4876(t *testing.T) {
{
Config: testAccConfig(map[string]interface{}{
"user_id": "1419992691371925",
"dry_run": "false",
"service_id": "${alicloud_privatelink_vpc_endpoint_service.defaultSaMoag.id}",
"user_arn": "acs:ram:*:1419992691371925:*",
}),
Check: resource.ComposeTestCheckFunc(
testAccCheck(map[string]string{
"user_id": "1419992691371925",
"user_id": CHECKSET,
"dry_run": "false",
"service_id": CHECKSET,
"user_arn": CHECKSET,
}),
),
},
{
ResourceName: resourceId,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"dry_run"},
ImportStateVerifyIgnore: []string{"dry_run", "user_arn"},
},
},
})
Expand All @@ -338,6 +342,9 @@ variable "name" {
default = "%s"
}
data "alicloud_account" "current" {
}
resource "alicloud_privatelink_vpc_endpoint_service" "defaultSaMoag" {
service_description = "test-zejun"
service_resource_type = "nlb"
Expand Down
7 changes: 4 additions & 3 deletions alicloud/service_alicloud_private_link_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ func (s *PrivateLinkServiceV2) SetResourceTags(d *schema.ResourceData, resourceT
}

// SetResourceTags >>> tag function encapsulated.

// DescribePrivateLinkVpcEndpointServiceUser <<< Encapsulated get interface for PrivateLink VpcEndpointServiceUser.

func (s *PrivateLinkServiceV2) DescribePrivateLinkVpcEndpointServiceUser(id string) (object map[string]interface{}, err error) {
Expand All @@ -251,7 +252,7 @@ func (s *PrivateLinkServiceV2) DescribePrivateLinkVpcEndpointServiceUser(id stri
query = make(map[string]interface{})
query["ServiceId"] = parts[0]
query["UserId"] = parts[1]
request["RegionId"] = client.RegionId
query["RegionId"] = client.RegionId

runtime := util.RuntimeOptions{}
runtime.SetAutoretry(true)
Expand All @@ -266,10 +267,9 @@ func (s *PrivateLinkServiceV2) DescribePrivateLinkVpcEndpointServiceUser(id stri
}
return resource.NonRetryableError(err)
}
addDebug(action, response, request)
return nil
})

addDebug(action, response, request)
if err != nil {
if IsExpectedErrors(err, []string{"EndpointServiceNotFound"}) {
return object, WrapErrorf(Error(GetNotFoundMessage("VpcEndpointServiceUser", id)), NotFoundMsg, response)
Expand Down Expand Up @@ -306,6 +306,7 @@ func (s *PrivateLinkServiceV2) PrivateLinkVpcEndpointServiceUserStateRefreshFunc

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
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ description: |-

# alicloud_privatelink_vpc_endpoint_service_user

Provides a Private Link Vpc Endpoint Service User resource. Endpoint service user whitelist.
Provides a Private Link Vpc Endpoint Service User resource.

Endpoint service user whitelist.

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

Expand All @@ -18,12 +20,6 @@ For information about Private Link Vpc Endpoint Service User and how to use it,

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_service_user&exampleId=4dd99c3d-edbb-793b-9ab6-dc2f06139de5919ea744&activeTab=example&spm=docs.r.privatelink_vpc_endpoint_service_user.0.4dd99c3ded&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 = "tfexampleuser"
Expand Down Expand Up @@ -53,9 +49,10 @@ resource "alicloud_privatelink_vpc_endpoint_service_user" "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.
* `service_id` - (Required, ForceNew) The endpoint service ID.
* `user_arn` - (Optional, Available since v1.232.0) The whitelist in the format of ARN.
* `user_id` - (Required, ForceNew) The ID of the Alibaba Cloud account in the whitelist of the endpoint service.

## Attributes Reference
Expand Down

0 comments on commit d568622

Please sign in to comment.