Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resource/alicloud_privatelink_vpc_endpoint_service: add new attribue region_id. #7889

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
166 changes: 102 additions & 64 deletions alicloud/resource_alicloud_privatelink_vpc_endpoint_service.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 @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -115,47 +118,50 @@ 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()
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", action, AlibabaCloudSdkGoERROR)
Expand Down Expand Up @@ -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 {
Expand All @@ -218,14 +256,15 @@ func resourceAliCloudPrivateLinkVpcEndpointServiceUpdate(d *schema.ResourceData,
var query map[string]interface{}
update := false
d.Partial(true)

action := "UpdateVpcEndpointServiceAttribute"
conn, err := client.NewPrivatelinkClient()
if err != nil {
return WrapError(err)
}
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") {
Expand All @@ -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 {
Expand All @@ -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"
Expand All @@ -291,31 +328,34 @@ 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()
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)
}
Expand All @@ -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)
Expand All @@ -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 {
Expand All @@ -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)
Expand All @@ -388,5 +425,6 @@ func resourceAliCloudPrivateLinkVpcEndpointServiceDelete(d *schema.ResourceData,
if _, err := stateConf.WaitForState(); err != nil {
return WrapErrorf(err, IdMsg, d.Id())
}

return nil
}
20 changes: 10 additions & 10 deletions alicloud/resource_alicloud_privatelink_vpc_endpoint_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
Loading
Loading