From 1077d056d15b0d28a8d852329b1ae0b77e0c6617 Mon Sep 17 00:00:00 2001 From: chenhanzhang Date: Thu, 21 Nov 2024 16:35:36 +0800 Subject: [PATCH] resource/alicloud_privatelink_vpc_endpoint_service: add new attribue region_id. --- ...icloud_privatelink_vpc_endpoint_service.go | 166 +++++++++++------- ...d_privatelink_vpc_endpoint_service_test.go | 20 +-- ...atelink_vpc_endpoint_service.html.markdown | 47 +++-- 3 files changed, 134 insertions(+), 99 deletions(-) diff --git a/alicloud/resource_alicloud_privatelink_vpc_endpoint_service.go b/alicloud/resource_alicloud_privatelink_vpc_endpoint_service.go index 8a37dd001989..58b5f09e70b8 100644 --- a/alicloud/resource_alicloud_privatelink_vpc_endpoint_service.go +++ b/alicloud/resource_alicloud_privatelink_vpc_endpoint_service.go @@ -1,4 +1,3 @@ -// Package alicloud. This file is generated automatically. Please do not modify it manually, thank you! package alicloud import ( @@ -34,8 +33,8 @@ func resourceAliCloudPrivateLinkVpcEndpointService() *schema.Resource { "connect_bandwidth": { Type: schema.TypeInt, Optional: true, - ValidateFunc: IntBetween(100, 10240), Computed: true, + ValidateFunc: IntBetween(100, 10240), }, "create_time": { Type: schema.TypeString, @@ -48,10 +47,14 @@ func resourceAliCloudPrivateLinkVpcEndpointService() *schema.Resource { "payer": { Type: schema.TypeString, Optional: true, - ForceNew: true, Computed: true, + ForceNew: true, ValidateFunc: StringInSlice([]string{"Endpoint", "EndpointService"}, false), }, + "region_id": { + Type: schema.TypeString, + Computed: true, + }, "resource_group_id": { Type: schema.TypeString, Optional: true, @@ -72,9 +75,9 @@ func resourceAliCloudPrivateLinkVpcEndpointService() *schema.Resource { "service_resource_type": { Type: schema.TypeString, Optional: true, - ValidateFunc: StringInSlice([]string{"slb", "nlb", "alb"}, false), - ForceNew: true, Computed: true, + ForceNew: true, + ValidateFunc: StringInSlice([]string{"slb", "alb", "nlb"}, false), }, "service_support_ipv6": { Type: schema.TypeBool, @@ -115,37 +118,40 @@ func resourceAliCloudPrivateLinkVpcEndpointServiceCreate(d *schema.ResourceData, request["RegionId"] = client.RegionId request["ClientToken"] = buildClientToken(action) - if v, ok := d.GetOk("service_description"); ok { - request["ServiceDescription"] = v - } - if v, ok := d.GetOkExists("auto_accept_connection"); ok { - request["AutoAcceptEnabled"] = v - } - if v, ok := d.GetOk("payer"); ok { - request["Payer"] = v - } - if v, ok := d.GetOkExists("dry_run"); ok { - request["DryRun"] = v - } if v, ok := d.GetOk("resource_group_id"); ok { request["ResourceGroupId"] = v } + if v, ok := d.GetOk("tags"); ok { + tagsMap := ConvertTags(v.(map[string]interface{})) + request = expandTagsToMap(request, tagsMap) + } + + if v, ok := d.GetOkExists("service_support_ipv6"); ok { + request["ServiceSupportIPv6"] = v + } if v, ok := d.GetOk("service_resource_type"); ok { request["ServiceResourceType"] = v } if v, ok := d.GetOkExists("zone_affinity_enabled"); ok { request["ZoneAffinityEnabled"] = v } - if v, ok := d.GetOkExists("service_support_ipv6"); ok { - request["ServiceSupportIPv6"] = v + if v, ok := d.GetOk("service_description"); ok { + request["ServiceDescription"] = v + } + if v, ok := d.GetOkExists("auto_accept_connection"); ok { + request["AutoAcceptEnabled"] = v + } + if v, ok := d.GetOkExists("dry_run"); ok { + request["DryRun"] = v + } + if v, ok := d.GetOk("payer"); ok { + request["Payer"] = v } runtime := util.RuntimeOptions{} runtime.SetAutoretry(true) 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) { wait() @@ -153,9 +159,9 @@ func resourceAliCloudPrivateLinkVpcEndpointServiceCreate(d *schema.ResourceData, } 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", action, AlibabaCloudSdkGoERROR) @@ -186,19 +192,51 @@ func resourceAliCloudPrivateLinkVpcEndpointServiceRead(d *schema.ResourceData, m return WrapError(err) } - d.Set("auto_accept_connection", objectRaw["AutoAcceptEnabled"]) - d.Set("connect_bandwidth", objectRaw["ConnectBandwidth"]) - d.Set("create_time", objectRaw["CreateTime"]) - d.Set("payer", objectRaw["Payer"]) - d.Set("resource_group_id", objectRaw["ResourceGroupId"]) - d.Set("service_business_status", objectRaw["ServiceBusinessStatus"]) - d.Set("service_description", objectRaw["ServiceDescription"]) - d.Set("service_domain", objectRaw["ServiceDomain"]) - d.Set("service_resource_type", objectRaw["ServiceResourceType"]) - d.Set("service_support_ipv6", objectRaw["ServiceSupportIPv6"]) - d.Set("status", objectRaw["ServiceStatus"]) - d.Set("vpc_endpoint_service_name", objectRaw["ServiceName"]) - d.Set("zone_affinity_enabled", objectRaw["ZoneAffinityEnabled"]) + if objectRaw["AddressIpVersion"] != nil { + d.Set("address_ip_version", objectRaw["AddressIpVersion"]) + } + if objectRaw["AutoAcceptEnabled"] != nil { + d.Set("auto_accept_connection", objectRaw["AutoAcceptEnabled"]) + } + if objectRaw["ConnectBandwidth"] != nil { + d.Set("connect_bandwidth", objectRaw["ConnectBandwidth"]) + } + if objectRaw["CreateTime"] != nil { + d.Set("create_time", objectRaw["CreateTime"]) + } + if objectRaw["Payer"] != nil { + d.Set("payer", objectRaw["Payer"]) + } + if objectRaw["RegionId"] != nil { + d.Set("region_id", objectRaw["RegionId"]) + } + if objectRaw["ResourceGroupId"] != nil { + d.Set("resource_group_id", objectRaw["ResourceGroupId"]) + } + if objectRaw["ServiceBusinessStatus"] != nil { + d.Set("service_business_status", objectRaw["ServiceBusinessStatus"]) + } + if objectRaw["ServiceDescription"] != nil { + d.Set("service_description", objectRaw["ServiceDescription"]) + } + if objectRaw["ServiceDomain"] != nil { + d.Set("service_domain", objectRaw["ServiceDomain"]) + } + if objectRaw["ServiceResourceType"] != nil { + d.Set("service_resource_type", objectRaw["ServiceResourceType"]) + } + if objectRaw["ServiceSupportIPv6"] != nil { + d.Set("service_support_ipv6", objectRaw["ServiceSupportIPv6"]) + } + if objectRaw["ServiceStatus"] != nil { + d.Set("status", objectRaw["ServiceStatus"]) + } + if objectRaw["ServiceName"] != nil { + d.Set("vpc_endpoint_service_name", objectRaw["ServiceName"]) + } + if objectRaw["ZoneAffinityEnabled"] != nil { + d.Set("zone_affinity_enabled", objectRaw["ZoneAffinityEnabled"]) + } objectRaw, err = privateLinkServiceV2.DescribeListTagResources(d.Id()) if err != nil { @@ -218,6 +256,7 @@ func resourceAliCloudPrivateLinkVpcEndpointServiceUpdate(d *schema.ResourceData, var query map[string]interface{} update := false d.Partial(true) + action := "UpdateVpcEndpointServiceAttribute" conn, err := client.NewPrivatelinkClient() if err != nil { @@ -225,7 +264,7 @@ func resourceAliCloudPrivateLinkVpcEndpointServiceUpdate(d *schema.ResourceData, } request = make(map[string]interface{}) query = make(map[string]interface{}) - query["ServiceId"] = d.Id() + request["ServiceId"] = d.Id() request["RegionId"] = client.RegionId request["ClientToken"] = buildClientToken(action) if !d.IsNewResource() && d.HasChange("service_description") { @@ -238,22 +277,27 @@ func resourceAliCloudPrivateLinkVpcEndpointServiceUpdate(d *schema.ResourceData, request["AutoAcceptEnabled"] = d.Get("auto_accept_connection") } + if !d.IsNewResource() && d.HasChange("service_support_ipv6") { + update = true + request["ServiceSupportIPv6"] = d.Get("service_support_ipv6") + } + if d.HasChange("connect_bandwidth") { update = true request["ConnectBandwidth"] = d.Get("connect_bandwidth") } - if v, ok := d.GetOkExists("dry_run"); ok { - request["DryRun"] = v - } if !d.IsNewResource() && d.HasChange("zone_affinity_enabled") { update = true request["ZoneAffinityEnabled"] = d.Get("zone_affinity_enabled") } - if !d.IsNewResource() && d.HasChange("service_support_ipv6") { + if v, ok := d.GetOkExists("dry_run"); ok { + request["DryRun"] = v + } + if d.HasChange("address_ip_version") { update = true - request["ServiceSupportIPv6"] = d.Get("service_support_ipv6") + request["AddressIpVersion"] = d.Get("address_ip_version") } if update { @@ -262,26 +306,19 @@ func resourceAliCloudPrivateLinkVpcEndpointServiceUpdate(d *schema.ResourceData, wait := incrementalWait(3*time.Second, 5*time.Second) err = resource.Retry(d.Timeout(schema.TimeoutUpdate), 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{"EndpointServiceOperationDenied", "EndpointServiceLocked"}) || NeedRetry(err) { + if IsExpectedErrors(err, []string{"EndpointServiceOperationDenied", "ConcurrentCallNotSupported", "EndpointServiceLocked"}) || 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, d.Id(), action, AlibabaCloudSdkGoERROR) } - d.SetPartial("service_description") - d.SetPartial("auto_accept_connection") - d.SetPartial("connect_bandwidth") - d.SetPartial("zone_affinity_enabled") - d.SetPartial("service_support_ipv6") } update = false action = "ChangeResourceGroup" @@ -291,21 +328,24 @@ func resourceAliCloudPrivateLinkVpcEndpointServiceUpdate(d *schema.ResourceData, } request = make(map[string]interface{}) query = make(map[string]interface{}) - query["ResourceId"] = d.Id() + request["ResourceId"] = d.Id() + if _, ok := d.GetOk("resource_group_id"); ok && !d.IsNewResource() && d.HasChange("resource_group_id") { update = true - request["ResourceGroupId"] = d.Get("resource_group_id") + } + request["ResourceGroupId"] = d.Get("resource_group_id") + if !d.IsNewResource() && d.HasChange("region_id") { + update = true + request["ResourceRegionId"] = d.Get("region_id") } - query["ResourceType"] = "VpcEndpointService" - query["ResourceRegionId"] = client.RegionId + request["ResourceType"] = "VpcEndpointService" if update { runtime := util.RuntimeOptions{} runtime.SetAutoretry(true) wait := incrementalWait(3*time.Second, 5*time.Second) err = resource.Retry(d.Timeout(schema.TimeoutUpdate), func() *resource.RetryError { response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2020-04-15"), StringPointer("AK"), query, request, &runtime) - if err != nil { if NeedRetry(err) { wait() @@ -313,9 +353,9 @@ func resourceAliCloudPrivateLinkVpcEndpointServiceUpdate(d *schema.ResourceData, } return resource.NonRetryableError(err) } - addDebug(action, response, request) return nil }) + addDebug(action, response, request) if err != nil { return WrapErrorf(err, DefaultErrorMsg, d.Id(), action, AlibabaCloudSdkGoERROR) } @@ -324,15 +364,13 @@ func resourceAliCloudPrivateLinkVpcEndpointServiceUpdate(d *schema.ResourceData, if _, err := stateConf.WaitForState(); err != nil { return WrapErrorf(err, IdMsg, d.Id()) } - d.SetPartial("resource_group_id") } if d.HasChange("tags") { privateLinkServiceV2 := PrivateLinkServiceV2{client} - if err := privateLinkServiceV2.SetResourceTags(d, "vpcendpointservice"); err != nil { + if err := privateLinkServiceV2.SetResourceTags(d, "VpcEndpointService"); err != nil { return WrapError(err) } - d.SetPartial("tags") } d.Partial(false) return resourceAliCloudPrivateLinkVpcEndpointServiceRead(d, meta) @@ -350,9 +388,8 @@ func resourceAliCloudPrivateLinkVpcEndpointServiceDelete(d *schema.ResourceData, return WrapError(err) } request = make(map[string]interface{}) - query["ServiceId"] = d.Id() + request["ServiceId"] = d.Id() request["RegionId"] = client.RegionId - request["ClientToken"] = buildClientToken(action) if v, ok := d.GetOkExists("dry_run"); ok { @@ -366,18 +403,18 @@ func resourceAliCloudPrivateLinkVpcEndpointServiceDelete(d *schema.ResourceData, request["ClientToken"] = buildClientToken(action) if err != nil { - if IsExpectedErrors(err, []string{"EndpointServiceConnectionDependence"}) || NeedRetry(err) { + if IsExpectedErrors(err, []string{"EndpointServiceConnectionDependence", "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 { - if IsExpectedErrors(err, []string{"EndpointServiceNotFound"}) { + if IsExpectedErrors(err, []string{"EndpointServiceNotFound"}) || NotFoundError(err) { return nil } return WrapErrorf(err, DefaultErrorMsg, d.Id(), action, AlibabaCloudSdkGoERROR) @@ -388,5 +425,6 @@ func resourceAliCloudPrivateLinkVpcEndpointServiceDelete(d *schema.ResourceData, if _, err := stateConf.WaitForState(); err != nil { return WrapErrorf(err, IdMsg, d.Id()) } + return nil } diff --git a/alicloud/resource_alicloud_privatelink_vpc_endpoint_service_test.go b/alicloud/resource_alicloud_privatelink_vpc_endpoint_service_test.go index fe56e947f399..47cc6ab751fd 100644 --- a/alicloud/resource_alicloud_privatelink_vpc_endpoint_service_test.go +++ b/alicloud/resource_alicloud_privatelink_vpc_endpoint_service_test.go @@ -559,6 +559,16 @@ func TestAccAliCloudPrivateLinkVpcEndpointService_basic4837(t *testing.T) { }), ), }, + //{ + // Config: testAccConfig(map[string]interface{}{ + // "service_support_ipv6": "true", + // }), + // Check: resource.ComposeTestCheckFunc( + // testAccCheck(map[string]string{ + // "service_support_ipv6": "true", + // }), + // ), + //}, { Config: testAccConfig(map[string]interface{}{ "service_support_ipv6": "false", @@ -569,16 +579,6 @@ func TestAccAliCloudPrivateLinkVpcEndpointService_basic4837(t *testing.T) { }), ), }, - { - Config: testAccConfig(map[string]interface{}{ - "service_support_ipv6": "true", - }), - Check: resource.ComposeTestCheckFunc( - testAccCheck(map[string]string{ - "service_support_ipv6": "true", - }), - ), - }, { Config: testAccConfig(map[string]interface{}{ "zone_affinity_enabled": "false", diff --git a/website/docs/r/privatelink_vpc_endpoint_service.html.markdown b/website/docs/r/privatelink_vpc_endpoint_service.html.markdown index 887e0700fd0f..481aa6113864 100644 --- a/website/docs/r/privatelink_vpc_endpoint_service.html.markdown +++ b/website/docs/r/privatelink_vpc_endpoint_service.html.markdown @@ -8,7 +8,9 @@ description: |- # alicloud_privatelink_vpc_endpoint_service -Provides a Private Link Vpc Endpoint Service resource. +Provides a Private Link Vpc Endpoint Service resource. + + For information about Private Link Vpc Endpoint Service and how to use it, see [What is Vpc Endpoint Service](https://www.alibabacloud.com/help/en/privatelink/latest/api-privatelink-2020-04-15-createvpcendpointservice). @@ -18,12 +20,6 @@ For information about Private Link Vpc Endpoint Service and how to use it, see [ Basic Usage -
- ```terraform variable "name" { default = "tf_example" @@ -40,34 +36,35 @@ resource "alicloud_privatelink_vpc_endpoint_service" "example" { The following arguments are supported: * `auto_accept_connection` - (Optional) Indicates whether the endpoint service automatically accepts endpoint connection requests. Valid values: - - **true** - - **false**. -* `connect_bandwidth` - (Optional, Computed) The default bandwidth of the endpoint connection. Valid values: 100 to 10240. Unit: Mbit/s. + - `true` + - `false` +* `connect_bandwidth` - (Optional, Computed, Int) The default bandwidth of the endpoint connection. Valid values: 100 to 10240. Unit: Mbit/s. * `dry_run` - (Optional) Specifies whether to perform only a dry run, without performing the actual request. - - **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. * `payer` - (Optional, ForceNew, Computed) The payer of the endpoint service. Valid values: - - **Endpoint**: the service consumer. - - **EndpointService**: the service provider. -* `resource_group_id` - (Optional, Computed, Available since v1.212.0) The resource group ID. + - `Endpoint`: the service consumer. + - `EndpointService`: the service provider. +* `resource_group_id` - (Optional, Computed) The resource group ID. * `service_description` - (Optional) The description of the endpoint service. -* `service_resource_type` - (Optional, ForceNew, Computed, Available since v1.212.0) Service resource type, value: - - **slb**: indicates that the service resource type is Classic Load Balancer (CLB). - - **alb**: indicates that the service resource type is Application Load Balancer (ALB). - - **nlb**: indicates that the service resource type is Network Load Balancer (NLB). -* `service_support_ipv6` - (Optional, Computed, Available since v1.212.0) Specifies whether to enable IPv6 for the endpoint service. Valid values: - - **true** - - **false (default)**. -* `tags` - (Optional, Map, Available since v1.212.0) The list of tags. -* `zone_affinity_enabled` - (Optional, Computed, Available since v1.212.0) Specifies whether to first resolve the domain name of the nearest endpoint that is associated with the endpoint service. Valid values: - - **true** - - **false (default)**. +* `service_resource_type` - (Optional, ForceNew, Computed) Service resource type, value: + - `slb`: indicates that the service resource type is Classic Load Balancer (CLB). + - `alb`: indicates that the service resource type is Application Load Balancer (ALB). + - `nlb`: indicates that the service resource type is Network Load Balancer (NLB). +* `service_support_ipv6` - (Optional, Computed, Deprecated since v1.235.0) Specifies whether to enable IPv6 for the endpoint service. Valid values: + - `true` + - **false (default)** +* `tags` - (Optional, Map) The list of tags. +* `zone_affinity_enabled` - (Optional, Computed) Specifies whether to first resolve the domain name of the nearest endpoint that is associated with the endpoint service. Valid values: + - `true` + - **false (default)** ## Attributes Reference The following attributes are exported: * `id` - The ID of the resource supplied above. * `create_time` - The time when the endpoint service was created. +* `region_id` - The ID of the region to which the endpoint service belongs. * `service_business_status` - The service state of the endpoint service. * `service_domain` - The domain name of the endpoint service. * `status` - The state of the endpoint service.