From 30fd4011ff3fdf6cc0f0f5bf607db64428e1cb11 Mon Sep 17 00:00:00 2001 From: chenhanzhang Date: Thu, 26 Dec 2024 09:28:46 +0800 Subject: [PATCH] resource/alicloud_vpc_peer_connection: add new attribute link_type, region_id; resource/alicloud_vpc_peer_connection_accepter: add new attribute link_type, region_id. --- .../resource_alicloud_vpc_peer_connection.go | 202 +++++++++++------- ...e_alicloud_vpc_peer_connection_accepter.go | 41 +++- ...cloud_vpc_peer_connection_accepter_test.go | 4 + ...ource_alicloud_vpc_peer_connection_test.go | 140 ++++++++++++ alicloud/service_alicloud_vpc_peer_v2.go | 29 ++- .../docs/r/vpc_peer_connection.html.markdown | 75 ++++--- ...vpc_peer_connection_accepter.html.markdown | 22 +- 7 files changed, 371 insertions(+), 142 deletions(-) diff --git a/alicloud/resource_alicloud_vpc_peer_connection.go b/alicloud/resource_alicloud_vpc_peer_connection.go index 48a294772b93..8bf1009519af 100644 --- a/alicloud/resource_alicloud_vpc_peer_connection.go +++ b/alicloud/resource_alicloud_vpc_peer_connection.go @@ -7,6 +7,7 @@ import ( "time" "github.com/PaesslerAG/jsonpath" + util "github.com/alibabacloud-go/tea-utils/service" "github.com/aliyun/terraform-provider-alicloud/alicloud/connectivity" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" @@ -65,11 +66,21 @@ func resourceAliCloudVpcPeerPeerConnection() *schema.Resource { Type: schema.TypeBool, Optional: true, }, + "link_type": { + Type: schema.TypeString, + Optional: true, + Computed: true, + ValidateFunc: StringInSlice([]string{"Platinum", "Gold", "Silver"}, false), + }, "peer_connection_name": { Type: schema.TypeString, Optional: true, Computed: true, }, + "region_id": { + Type: schema.TypeString, + Computed: true, + }, "resource_group_id": { Type: schema.TypeString, Optional: true, @@ -100,7 +111,7 @@ func resourceAliCloudVpcPeerPeerConnectionCreate(d *schema.ResourceData, meta in query := make(map[string]interface{}) var err error request = make(map[string]interface{}) - query["RegionId"] = client.RegionId + request["RegionId"] = client.RegionId request["ClientToken"] = buildClientToken(action) request["VpcId"] = d.Get("vpc_id") @@ -122,6 +133,11 @@ func resourceAliCloudVpcPeerPeerConnectionCreate(d *schema.ResourceData, meta in if v, ok := d.GetOkExists("dry_run"); ok { request["DryRun"] = v } + if v, ok := d.GetOk("link_type"); ok { + request["LinkType"] = 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 = client.RpcPost("VpcPeer", "2022-01-01", action, query, request, true) @@ -132,9 +148,9 @@ func resourceAliCloudVpcPeerPeerConnectionCreate(d *schema.ResourceData, meta in } return resource.NonRetryableError(err) } - addDebug(action, response, request) return nil }) + addDebug(action, response, request) if err != nil { return WrapErrorf(err, DefaultErrorMsg, "alicloud_vpc_peer_connection", action, AlibabaCloudSdkGoERROR) @@ -180,9 +196,15 @@ func resourceAliCloudVpcPeerPeerConnectionRead(d *schema.ResourceData, meta inte if objectRaw["Description"] != nil { d.Set("description", objectRaw["Description"]) } + if objectRaw["LinkType"] != nil { + d.Set("link_type", objectRaw["LinkType"]) + } if objectRaw["Name"] != nil { d.Set("peer_connection_name", objectRaw["Name"]) } + if objectRaw["RegionId"] != nil { + d.Set("region_id", objectRaw["RegionId"]) + } if objectRaw["ResourceGroupId"] != nil { d.Set("resource_group_id", objectRaw["ResourceGroupId"]) } @@ -221,83 +243,6 @@ func resourceAliCloudVpcPeerPeerConnectionUpdate(d *schema.ResourceData, meta in var query map[string]interface{} update := false d.Partial(true) - action := "ModifyVpcPeerConnection" - var err error - request = make(map[string]interface{}) - query = make(map[string]interface{}) - request["InstanceId"] = d.Id() - - request["ClientToken"] = buildClientToken(action) - if !d.IsNewResource() && d.HasChange("description") { - update = true - request["Description"] = d.Get("description") - } - - if !d.IsNewResource() && d.HasChange("bandwidth") { - update = true - request["Bandwidth"] = d.Get("bandwidth") - } - - if !d.IsNewResource() && d.HasChange("peer_connection_name") { - update = true - request["Name"] = d.Get("peer_connection_name") - } - - if v, ok := d.GetOkExists("dry_run"); ok { - request["DryRun"] = v - } - if update { - wait := incrementalWait(3*time.Second, 5*time.Second) - err = resource.Retry(d.Timeout(schema.TimeoutUpdate), func() *resource.RetryError { - response, err = client.RpcPost("VpcPeer", "2022-01-01", action, query, request, true) - if err != nil { - if NeedRetry(err) { - wait() - return resource.RetryableError(err) - } - return resource.NonRetryableError(err) - } - addDebug(action, response, request) - return nil - }) - if err != nil { - return WrapErrorf(err, DefaultErrorMsg, d.Id(), action, AlibabaCloudSdkGoERROR) - } - vpcPeerServiceV2 := VpcPeerServiceV2{client} - stateConf := BuildStateConf([]string{}, []string{"Activated"}, d.Timeout(schema.TimeoutUpdate), 5*time.Second, vpcPeerServiceV2.VpcPeerPeerConnectionStateRefreshFunc(d.Id(), "Status", []string{})) - if _, err := stateConf.WaitForState(); err != nil { - return WrapErrorf(err, IdMsg, d.Id()) - } - } - update = false - action = "MoveResourceGroup" - request = make(map[string]interface{}) - query = make(map[string]interface{}) - query["ResourceId"] = d.Id() - query["RegionId"] = client.RegionId - request["ResourceType"] = "PeerConnection" - if _, ok := d.GetOk("resource_group_id"); ok && !d.IsNewResource() && d.HasChange("resource_group_id") { - update = true - } - request["NewResourceGroupId"] = d.Get("resource_group_id") - if update { - wait := incrementalWait(3*time.Second, 5*time.Second) - err = resource.Retry(d.Timeout(schema.TimeoutUpdate), func() *resource.RetryError { - response, err = client.RpcPost("VpcPeer", "2022-01-01", action, query, request, false) - if err != nil { - if NeedRetry(err) { - wait() - return resource.RetryableError(err) - } - return resource.NonRetryableError(err) - } - addDebug(action, response, request) - return nil - }) - if err != nil { - return WrapErrorf(err, DefaultErrorMsg, d.Id(), action, AlibabaCloudSdkGoERROR) - } - } if d.HasChange("status") { vpcPeerServiceV2 := VpcPeerServiceV2{client} @@ -321,6 +266,8 @@ func resourceAliCloudVpcPeerPeerConnectionUpdate(d *schema.ResourceData, meta in if v, ok := d.GetOkExists("dry_run"); ok { request["DryRun"] = v } + 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 = client.RpcPost("VpcPeer", "2022-01-01", action, query, request, true) @@ -331,9 +278,9 @@ func resourceAliCloudVpcPeerPeerConnectionUpdate(d *schema.ResourceData, meta in } 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) } @@ -354,6 +301,8 @@ func resourceAliCloudVpcPeerPeerConnectionUpdate(d *schema.ResourceData, meta in if v, ok := d.GetOkExists("dry_run"); ok { request["DryRun"] = v } + 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 = client.RpcPost("VpcPeer", "2022-01-01", action, query, request, true) @@ -364,9 +313,9 @@ func resourceAliCloudVpcPeerPeerConnectionUpdate(d *schema.ResourceData, meta in } 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) } @@ -380,6 +329,93 @@ func resourceAliCloudVpcPeerPeerConnectionUpdate(d *schema.ResourceData, meta in } } + action := "ModifyVpcPeerConnection" + var err error + request = make(map[string]interface{}) + query = make(map[string]interface{}) + request["InstanceId"] = d.Id() + + request["ClientToken"] = buildClientToken(action) + if !d.IsNewResource() && d.HasChange("description") { + update = true + request["Description"] = d.Get("description") + } + + if !d.IsNewResource() && d.HasChange("bandwidth") { + update = true + request["Bandwidth"] = d.Get("bandwidth") + } + + if !d.IsNewResource() && d.HasChange("peer_connection_name") { + update = true + request["Name"] = d.Get("peer_connection_name") + } + + if v, ok := d.GetOkExists("dry_run"); ok { + request["DryRun"] = v + } + if !d.IsNewResource() && d.HasChange("link_type") { + update = true + request["LinkType"] = d.Get("link_type") + } + + 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 = client.RpcPost("VpcPeer", "2022-01-01", action, query, request, true) + if err != nil { + if NeedRetry(err) { + wait() + return resource.RetryableError(err) + } + return resource.NonRetryableError(err) + } + return nil + }) + addDebug(action, response, request) + if err != nil { + return WrapErrorf(err, DefaultErrorMsg, d.Id(), action, AlibabaCloudSdkGoERROR) + } + vpcPeerServiceV2 := VpcPeerServiceV2{client} + stateConf := BuildStateConf([]string{}, []string{"Activated"}, d.Timeout(schema.TimeoutUpdate), 5*time.Second, vpcPeerServiceV2.VpcPeerPeerConnectionStateRefreshFunc(d.Id(), "Status", []string{})) + if _, err := stateConf.WaitForState(); err != nil { + return WrapErrorf(err, IdMsg, d.Id()) + } + } + update = false + action = "MoveResourceGroup" + request = make(map[string]interface{}) + query = make(map[string]interface{}) + request["ResourceId"] = d.Id() + request["RegionId"] = client.RegionId + request["ResourceType"] = "PeerConnection" + if _, ok := d.GetOk("resource_group_id"); ok && !d.IsNewResource() && d.HasChange("resource_group_id") { + update = true + } + request["NewResourceGroupId"] = d.Get("resource_group_id") + 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 = client.RpcPost("VpcPeer", "2022-01-01", action, query, request, false) + if err != nil { + if NeedRetry(err) { + wait() + return resource.RetryableError(err) + } + return resource.NonRetryableError(err) + } + return nil + }) + addDebug(action, response, request) + if err != nil { + return WrapErrorf(err, DefaultErrorMsg, d.Id(), action, AlibabaCloudSdkGoERROR) + } + } + if d.HasChange("tags") { vpcPeerServiceV2 := VpcPeerServiceV2{client} if err := vpcPeerServiceV2.SetResourceTags(d, "PeerConnection"); err != nil { @@ -409,6 +445,8 @@ func resourceAliCloudVpcPeerPeerConnectionDelete(d *schema.ResourceData, meta in if v, ok := d.GetOkExists("force_delete"); ok { request["Force"] = v } + runtime := util.RuntimeOptions{} + runtime.SetAutoretry(true) wait := incrementalWait(3*time.Second, 5*time.Second) err = resource.Retry(d.Timeout(schema.TimeoutDelete), func() *resource.RetryError { response, err = client.RpcPost("VpcPeer", "2022-01-01", action, query, request, true) @@ -421,9 +459,9 @@ func resourceAliCloudVpcPeerPeerConnectionDelete(d *schema.ResourceData, meta in } return resource.NonRetryableError(err) } - addDebug(action, response, request) return nil }) + addDebug(action, response, request) if err != nil { if IsExpectedErrors(err, []string{"ResourceNotFound.InstanceId"}) || NotFoundError(err) { diff --git a/alicloud/resource_alicloud_vpc_peer_connection_accepter.go b/alicloud/resource_alicloud_vpc_peer_connection_accepter.go index 7fc58978526b..11621318eb51 100644 --- a/alicloud/resource_alicloud_vpc_peer_connection_accepter.go +++ b/alicloud/resource_alicloud_vpc_peer_connection_accepter.go @@ -7,6 +7,7 @@ import ( "time" "github.com/PaesslerAG/jsonpath" + util "github.com/alibabacloud-go/tea-utils/service" "github.com/aliyun/terraform-provider-alicloud/alicloud/connectivity" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" @@ -67,11 +68,21 @@ func resourceAliCloudVpcPeerPeerConnectionAccepter() *schema.Resource { Required: true, ForceNew: true, }, + "link_type": { + Type: schema.TypeString, + Optional: true, + Computed: true, + ValidateFunc: StringInSlice([]string{"Platinum", "Gold", "Silver"}, false), + }, "peer_connection_accepter_name": { Type: schema.TypeString, Optional: true, Computed: true, }, + "region_id": { + Type: schema.TypeString, + Computed: true, + }, "resource_group_id": { Type: schema.TypeString, Optional: true, @@ -122,9 +133,9 @@ func resourceAliCloudVpcPeerPeerConnectionAccepterCreate(d *schema.ResourceData, } return resource.NonRetryableError(err) } - addDebug(action, response, request) return nil }) + addDebug(action, response, request) if err != nil { if !IsExpectedErrors(err, []string{"IncorrectStatus.VpcPeer"}) { @@ -172,9 +183,15 @@ func resourceAliCloudVpcPeerPeerConnectionAccepterRead(d *schema.ResourceData, m if objectRaw["Description"] != nil { d.Set("description", objectRaw["Description"]) } + if objectRaw["LinkType"] != nil { + d.Set("link_type", objectRaw["LinkType"]) + } if objectRaw["Name"] != nil { d.Set("peer_connection_accepter_name", objectRaw["Name"]) } + if objectRaw["RegionId"] != nil { + d.Set("region_id", objectRaw["RegionId"]) + } if objectRaw["ResourceGroupId"] != nil { d.Set("resource_group_id", objectRaw["ResourceGroupId"]) } @@ -215,6 +232,7 @@ func resourceAliCloudVpcPeerPeerConnectionAccepterUpdate(d *schema.ResourceData, var query map[string]interface{} update := false d.Partial(true) + action := "ModifyVpcPeerConnection" var err error request = make(map[string]interface{}) @@ -240,7 +258,14 @@ func resourceAliCloudVpcPeerPeerConnectionAccepterUpdate(d *schema.ResourceData, if v, ok := d.GetOkExists("dry_run"); ok { request["DryRun"] = v } + if d.HasChange("link_type") { + update = true + request["LinkType"] = d.Get("link_type") + } + 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 = client.RpcPost("VpcPeer", "2022-01-01", action, query, request, true) @@ -251,9 +276,9 @@ func resourceAliCloudVpcPeerPeerConnectionAccepterUpdate(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) } @@ -267,14 +292,16 @@ func resourceAliCloudVpcPeerPeerConnectionAccepterUpdate(d *schema.ResourceData, action = "MoveResourceGroup" request = make(map[string]interface{}) query = make(map[string]interface{}) - query["ResourceId"] = d.Id() - query["RegionId"] = client.RegionId + request["ResourceId"] = d.Id() + request["RegionId"] = client.RegionId if _, ok := d.GetOk("resource_group_id"); ok && !d.IsNewResource() && d.HasChange("resource_group_id") { update = true } request["NewResourceGroupId"] = d.Get("resource_group_id") request["ResourceType"] = "PeerConnection" 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 = client.RpcPost("VpcPeer", "2022-01-01", action, query, request, false) @@ -285,9 +312,9 @@ func resourceAliCloudVpcPeerPeerConnectionAccepterUpdate(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) } @@ -316,6 +343,8 @@ func resourceAliCloudVpcPeerPeerConnectionAccepterDelete(d *schema.ResourceData, if v, ok := d.GetOkExists("force_delete"); ok { request["Force"] = v } + runtime := util.RuntimeOptions{} + runtime.SetAutoretry(true) wait := incrementalWait(3*time.Second, 5*time.Second) err = resource.Retry(d.Timeout(schema.TimeoutDelete), func() *resource.RetryError { response, err = client.RpcPost("VpcPeer", "2022-01-01", action, query, request, true) @@ -328,9 +357,9 @@ func resourceAliCloudVpcPeerPeerConnectionAccepterDelete(d *schema.ResourceData, } return resource.NonRetryableError(err) } - addDebug(action, response, request) return nil }) + addDebug(action, response, request) if err != nil { if NotFoundError(err) { diff --git a/alicloud/resource_alicloud_vpc_peer_connection_accepter_test.go b/alicloud/resource_alicloud_vpc_peer_connection_accepter_test.go index 8f10a50f04a2..193e8765330b 100644 --- a/alicloud/resource_alicloud_vpc_peer_connection_accepter_test.go +++ b/alicloud/resource_alicloud_vpc_peer_connection_accepter_test.go @@ -40,20 +40,24 @@ func TestAccAliCloudVpcPeerConnectionAccepter_basic2(t *testing.T) { { Config: testAccConfig(map[string]interface{}{ "instance_id": "${alicloud_vpc_peer_connection.default.id}", + "link_type": "Gold", }), Check: resource.ComposeTestCheckFunc( testAccCheck(map[string]string{ "instance_id": CHECKSET, + "link_type": "Gold", }), ), }, { Config: testAccConfig(map[string]interface{}{ "description": name, + "link_type": "Platinum", }), Check: resource.ComposeTestCheckFunc( testAccCheck(map[string]string{ "description": name, + "link_type": "Platinum", }), ), }, diff --git a/alicloud/resource_alicloud_vpc_peer_connection_test.go b/alicloud/resource_alicloud_vpc_peer_connection_test.go index 3fb0255ecd9c..d815c3b6aee6 100644 --- a/alicloud/resource_alicloud_vpc_peer_connection_test.go +++ b/alicloud/resource_alicloud_vpc_peer_connection_test.go @@ -136,6 +136,7 @@ func TestAccAliCloudVPCPeerConnection_basic0(t *testing.T) { "accepting_vpc_id": "${alicloud_vpc.accepting.id}", "accepting_region_id": "${data.alicloud_regions.default.regions.0.id}", "accepting_ali_uid": "${data.alicloud_account.default.id}", + //"link_type": "Gold", }), Check: resource.ComposeTestCheckFunc( testAccCheck(map[string]string{ @@ -143,16 +144,19 @@ func TestAccAliCloudVPCPeerConnection_basic0(t *testing.T) { "accepting_vpc_id": CHECKSET, "accepting_region_id": CHECKSET, "accepting_ali_uid": CHECKSET, + //"link_type": "Gold", }), ), }, { Config: testAccConfig(map[string]interface{}{ "resource_group_id": "${data.alicloud_resource_manager_resource_groups.default.groups.0.id}", + //"link_type": "Silver", }), Check: resource.ComposeTestCheckFunc( testAccCheck(map[string]string{ "resource_group_id": CHECKSET, + //"link_type": "Silver", }), ), }, @@ -912,3 +916,139 @@ func TestUnitAccAliCloudVpcPeerConnection(t *testing.T) { } } } + +// Test VpcPeer PeerConnection. >>> Resource test cases, automatically generated. +// Case 接入TF 7960 +func TestAccAliCloudVpcPeerPeerConnection_basic7960(t *testing.T) { + var v map[string]interface{} + resourceId := "alicloud_vpc_peer_connection.default" + ra := resourceAttrInit(resourceId, AlicloudVpcPeerPeerConnectionMap7960) + rc := resourceCheckInitWithDescribeMethod(resourceId, &v, func() interface{} { + return &VpcPeerServiceV2{testAccProvider.Meta().(*connectivity.AliyunClient)} + }, "DescribeVpcPeerPeerConnection") + rac := resourceAttrCheckInit(rc, ra) + testAccCheck := rac.resourceAttrMapUpdateSet() + rand := acctest.RandIntRange(10000, 99999) + name := fmt.Sprintf("tf-testacc%svpcpeerpeerconnection%d", defaultRegionToTest, rand) + testAccConfig := resourceTestAccConfigFunc(resourceId, name, AlicloudVpcPeerPeerConnectionBasicDependence7960) + resource.Test(t, resource.TestCase{ + PreCheck: func() { + testAccPreCheckWithRegions(t, true, []connectivity.Region{"cn-beijing"}) + testAccPreCheck(t) + }, + IDRefreshName: resourceId, + Providers: testAccProviders, + CheckDestroy: rac.checkResourceDestroy(), + Steps: []resource.TestStep{ + { + Config: testAccConfig(map[string]interface{}{ + "accepting_vpc_id": "${alicloud_vpc.defaultPcQrL1.id}", + "description": "tf-testacc-28", + "vpc_id": "${alicloud_vpc.defaultQka2zR.id}", + "resource_group_id": "${data.alicloud_resource_manager_resource_groups.default.ids.0}", + "accepting_region_id": defaultRegionToTest, + "accepting_ali_uid": "1511928242963727", + "peer_connection_name": name, + }), + Check: resource.ComposeTestCheckFunc( + testAccCheck(map[string]string{ + "accepting_vpc_id": CHECKSET, + "description": CHECKSET, + "vpc_id": CHECKSET, + "resource_group_id": CHECKSET, + "accepting_region_id": CHECKSET, + "accepting_ali_uid": "1511928242963727", + "peer_connection_name": name, + }), + ), + }, + { + Config: testAccConfig(map[string]interface{}{ + "description": "tf-testacc-808", + }), + Check: resource.ComposeTestCheckFunc( + testAccCheck(map[string]string{ + "description": CHECKSET, + }), + ), + }, + { + Config: testAccConfig(map[string]interface{}{ + "tags": map[string]string{ + "Created": "TF", + "For": "Test", + }, + }), + Check: resource.ComposeTestCheckFunc( + testAccCheck(map[string]string{ + "tags.%": "2", + "tags.Created": "TF", + "tags.For": "Test", + }), + ), + }, + { + Config: testAccConfig(map[string]interface{}{ + "tags": map[string]string{ + "Created": "TF-update", + "For": "Test-update", + }, + }), + Check: resource.ComposeTestCheckFunc( + testAccCheck(map[string]string{ + "tags.%": "2", + "tags.Created": "TF-update", + "tags.For": "Test-update", + }), + ), + }, + { + Config: testAccConfig(map[string]interface{}{ + "tags": REMOVEKEY, + }), + Check: resource.ComposeTestCheckFunc( + testAccCheck(map[string]string{ + "tags.%": "0", + "tags.Created": REMOVEKEY, + "tags.For": REMOVEKEY, + }), + ), + }, + { + ResourceName: resourceId, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"dry_run"}, + }, + }, + }) +} + +var AlicloudVpcPeerPeerConnectionMap7960 = map[string]string{ + "create_time": CHECKSET, + "region_id": CHECKSET, +} + +func AlicloudVpcPeerPeerConnectionBasicDependence7960(name string) string { + return fmt.Sprintf(` +variable "name" { + default = "%s" +} + +data "alicloud_resource_manager_resource_groups" "default" {} + +resource "alicloud_vpc" "defaultQka2zR" { + cidr_block = "172.16.0.0/12" + vpc_name = var.name +} + +resource "alicloud_vpc" "defaultPcQrL1" { + cidr_block = "172.16.0.0/12" + vpc_name = format("%%s1", var.name) +} + + +`, name) +} + +// Test VpcPeer PeerConnection. <<< Resource test cases, automatically generated. diff --git a/alicloud/service_alicloud_vpc_peer_v2.go b/alicloud/service_alicloud_vpc_peer_v2.go index 6feaad90b7d1..1848d90db9e8 100644 --- a/alicloud/service_alicloud_vpc_peer_v2.go +++ b/alicloud/service_alicloud_vpc_peer_v2.go @@ -2,6 +2,7 @@ package alicloud import ( "fmt" + "strings" "time" "github.com/PaesslerAG/jsonpath" @@ -37,14 +38,13 @@ func (s *VpcPeerServiceV2) DescribeVpcPeerPeerConnection(id string) (object map[ } return resource.NonRetryableError(err) } - addDebug(action, response, request) return nil }) + addDebug(action, response, request) if err != nil { if IsExpectedErrors(err, []string{"ResourceNotFound.InstanceId"}) { return object, WrapErrorf(Error(GetNotFoundMessage("PeerConnection", id)), NotFoundMsg, response) } - addDebug(action, response, request) return object, WrapErrorf(err, DefaultErrorMsg, id, action, AlibabaCloudSdkGoERROR) } @@ -64,6 +64,13 @@ func (s *VpcPeerServiceV2) VpcPeerPeerConnectionStateRefreshFunc(id string, fiel v, err := jsonpath.Get(field, object) currentStatus := fmt.Sprint(v) + if strings.HasPrefix(field, "#") { + v, _ := jsonpath.Get(strings.TrimPrefix(field, "#"), object) + if v != nil { + currentStatus = "#CHECKSET" + } + } + for _, failState := range failStates { if currentStatus == failState { return object, currentStatus, WrapError(Error(FailedToReachTargetStatus, currentStatus)) @@ -97,7 +104,7 @@ func (s *VpcPeerServiceV2) SetResourceTags(d *schema.ResourceData, resourceType request = make(map[string]interface{}) query = make(map[string]interface{}) request["ResourceId.1"] = d.Id() - query["RegionId"] = client.RegionId + request["RegionId"] = client.RegionId request["ClientToken"] = buildClientToken(action) for i, key := range removedTagKeys { request[fmt.Sprintf("TagKey.%d", i+1)] = key @@ -114,9 +121,9 @@ func (s *VpcPeerServiceV2) SetResourceTags(d *schema.ResourceData, resourceType } 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) } @@ -129,7 +136,7 @@ func (s *VpcPeerServiceV2) SetResourceTags(d *schema.ResourceData, resourceType request = make(map[string]interface{}) query = make(map[string]interface{}) request["ResourceId.1"] = d.Id() - query["RegionId"] = client.RegionId + request["RegionId"] = client.RegionId request["ClientToken"] = buildClientToken(action) count := 1 for key, value := range added { @@ -149,9 +156,9 @@ func (s *VpcPeerServiceV2) SetResourceTags(d *schema.ResourceData, resourceType } 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) } @@ -187,14 +194,13 @@ func (s *VpcPeerServiceV2) DescribeVpcPeerPeerConnectionAccepter(id string) (obj } return resource.NonRetryableError(err) } - addDebug(action, response, request) return nil }) + addDebug(action, response, request) if err != nil { if IsExpectedErrors(err, []string{"ResourceNotFound.InstanceId"}) { return object, WrapErrorf(Error(GetNotFoundMessage("PeerConnectionAccepter", id)), NotFoundMsg, response) } - addDebug(action, response, request) return object, WrapErrorf(err, DefaultErrorMsg, id, action, AlibabaCloudSdkGoERROR) } @@ -214,6 +220,13 @@ func (s *VpcPeerServiceV2) VpcPeerPeerConnectionAccepterStateRefreshFunc(id stri v, err := jsonpath.Get(field, object) currentStatus := fmt.Sprint(v) + if strings.HasPrefix(field, "#") { + v, _ := jsonpath.Get(strings.TrimPrefix(field, "#"), object) + if v != nil { + currentStatus = "#CHECKSET" + } + } + for _, failState := range failStates { if currentStatus == failState { return object, currentStatus, WrapError(Error(FailedToReachTargetStatus, currentStatus)) diff --git a/website/docs/r/vpc_peer_connection.html.markdown b/website/docs/r/vpc_peer_connection.html.markdown index 1479a43a0966..7d39e9c8811e 100644 --- a/website/docs/r/vpc_peer_connection.html.markdown +++ b/website/docs/r/vpc_peer_connection.html.markdown @@ -3,14 +3,16 @@ subcategory: "VPC" layout: "alicloud" page_title: "Alicloud: alicloud_vpc_peer_connection" description: |- - Provides a Alicloud Vpc Peer Connection resource. + Provides a Alicloud Vpc Peer Peer Connection resource. --- # alicloud_vpc_peer_connection -Provides a Vpc Peer Connection resource. +Provides a Vpc Peer Peer Connection resource. -For information about VPC Peer Connection and how to use it, see [What is Peer Connection](https://www.alibabacloud.com/help/en/virtual-private-cloud/latest/createvpcpeer). +Vpc peer connection. + +For information about Vpc Peer Peer Connection and how to use it, see [What is Peer Connection](https://www.alibabacloud.com/help/en/virtual-private-cloud/latest/createvpcpeer). -> **NOTE:** Available since v1.186.0. @@ -18,12 +20,6 @@ For information about VPC Peer Connection and how to use it, see [What is Peer C Basic Usage -
- ```terraform data "alicloud_account" "default" {} @@ -66,37 +62,46 @@ resource "alicloud_vpc_peer_connection" "default" { ## Argument Reference The following arguments are supported: -* `accepting_ali_uid` - (Optional, ForceNew, Int) The ID of the Alibaba Cloud account (primary account) of the receiving end of the VPC peering connection to be created. - - Enter the ID of your Alibaba Cloud account to create a peer-to-peer connection to the VPC account. - - Enter the ID of another Alibaba Cloud account to create a cross-account VPC peer-to-peer connection. - --> **NOTE:** If the recipient account is a RAM user (sub-account), enter the ID of the Alibaba Cloud account corresponding to the RAM user. - -* `accepting_region_id` - (Required, ForceNew) The region ID of the recipient of the VPC peering connection to be created. - - When creating a VPC peer-to-peer connection in the same region, enter the same region ID as the region ID of the initiator. - - When creating a cross-region VPC peer-to-peer connection, enter a region ID that is different from the region ID of the initiator. -* `accepting_vpc_id` - (Required, ForceNew) The VPC ID of the receiving end of the VPC peer connection. -* `bandwidth` - (Optional, Int) The bandwidth of the VPC peering connection to be modified. Unit: Mbps. The value range is an integer greater than 0. -* `description` - (Optional) The description of the VPC peer connection to be created. - - It must be 2 to 256 characters in length and must start with a letter or Chinese, but cannot start with http:// or https. -* `dry_run` - (Optional) Whether to PreCheck only this request. Value: - - `true`: The check request is sent without creating a VPC peer-to-peer connection. Check items include whether required parameters, request format, and business restrictions are filled in. If the check does not pass, the corresponding error is returned. If the check passes, the error code 'DryRunOperation' is returned '. - - `false` (default): A normal request is sent. After checking, the HTTP 2xx status code is returned and the operation is performed directly. -* `force_delete` - (Optional, Available since v1.231.0) Whether to forcibly delete the VPC peering connection. Value: - - `false` (default): Does not forcibly delete the VPC peering connection. - - `true`: forcibly deletes the VPC peering connection. During the forced deletion, the system deletes the route entries in the VPC routing table that point to the VPC peering connection. -* `peer_connection_name` - (Optional) The name of the resource. -* `resource_group_id` - (Optional, Computed) The ID of resource group. -* `status` - (Optional, Computed) The status of the resource. -* `tags` - (Optional, Map) The tags of the resource. -* `vpc_id` - (Required, ForceNew) You must create a VPC ID on the initiator of a VPC peer connection. +* `accepting_ali_uid` - (Optional, ForceNew, Int) The ID of the Alibaba Cloud account to which the accepter VPC belongs. + - To create a VPC peering connection within your Alibaba Cloud account, enter the ID of your Alibaba Cloud account. + - To create a VPC peering connection between your Alibaba Cloud account and another Alibaba Cloud account, enter the ID of the peer Alibaba Cloud account. + +-> **NOTE:** If the accepter is a RAM user, set `AcceptingAliUid` to the ID of the Alibaba Cloud account that created the RAM user. + +* `accepting_region_id` - (Required, ForceNew) The region ID of the accepter VPC of the VPC peering connection that you want to create. + - To create an intra-region VPC peering connection, enter a region ID that is the same as that of the requester VPC. + - To create an inter-region VPC peering connection, enter a region ID that is different from that of the requester VPC. +* `accepting_vpc_id` - (Required, ForceNew) The ID of the accepter VPC. +* `bandwidth` - (Optional, Computed, Int) The bandwidth of the VPC peering connection. Unit: Mbit/s. The value must be an integer greater than 0. Before you specify this parameter, make sure that you create an inter-region VPC peering connection. +* `description` - (Optional, Computed) The description of the VPC peering connection. + + The description must be 2 to 256 characters in length. The description must start with a letter but cannot start with `http://` or `https://`. +* `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. + - `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. +* `force_delete` - (Optional, Available since v1.231.0) Specifies whether to forcefully delete the VPC peering connection. Valid values: + - `false` (default): no. + - `true`: yes. If you forcefully delete the VPC peering connection, the system deletes the routes that point to the VPC peering connection from the VPC route table. +* `link_type` - (Optional, Available since v1.240.0) LinkType. Valid values: `Platinum`, `Gold`, `Silver`. +* `peer_connection_name` - (Optional, Computed) The name of the VPC peering connection. + + The name must be 2 to 128 characters in length, and can contain digits, underscores (\_), and hyphens (-). It must start with a letter. +* `resource_group_id` - (Optional, Computed) The ID of the new resource group. + +-> **NOTE:** You can use resource groups to manage resources within your Alibaba Cloud account by group. This helps you resolve issues such as resource grouping and permission management for your Alibaba Cloud account. For more information, see [What is resource management?](https://www.alibabacloud.com/help/en/doc-detail/94475.html) + +* `status` - (Optional, Computed) The status of the resource +* `tags` - (Optional, Map) The tags of PrefixList. +* `vpc_id` - (Required, ForceNew) The ID of the requester VPC or accepter VPC of the VPC peering connection that you want to query. ## Attributes Reference The following attributes are exported: * `id` - The ID of the resource supplied above. * `create_time` - The creation time of the VPC peer connection. Use UTC time in the format' YYYY-MM-DDThh:mm:ssZ '. +* `region_id` - The region ID of the resource to which you want to create and add tags. + + You can call the [DescribeRegions](https://www.alibabacloud.com/help/en/doc-detail/36063.html) operation to query the most recent region list. ## Timeouts @@ -107,7 +112,7 @@ The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/d ## Import -Vpc Peer Connection can be imported using the id, e.g. +Vpc Peer Peer Connection can be imported using the id, e.g. ```shell $ terraform import alicloud_vpc_peer_connection.example diff --git a/website/docs/r/vpc_peer_connection_accepter.html.markdown b/website/docs/r/vpc_peer_connection_accepter.html.markdown index c17bfc12e73e..e9f82b484385 100644 --- a/website/docs/r/vpc_peer_connection_accepter.html.markdown +++ b/website/docs/r/vpc_peer_connection_accepter.html.markdown @@ -3,14 +3,16 @@ subcategory: "VPC" layout: "alicloud" page_title: "Alicloud: alicloud_vpc_peer_connection_accepter" description: |- - Provides a Alicloud Vpc Peer Connection Accepter resource. + Provides a Alicloud Vpc Peer Peer Connection Accepter resource. --- # alicloud_vpc_peer_connection_accepter -Provides a Vpc Peer Connection Accepter resource. +Provides a Vpc Peer Peer Connection Accepter resource. -For information about Vpc Peer Connection Accepter and how to use it, see [What is Peer Connection Accepter](https://www.alibabacloud.com/help/en/vpc/developer-reference/api-vpcpeer-2022-01-01-acceptvpcpeerconnection). +Vpc peer connection receiver. + +For information about Vpc Peer Peer Connection Accepter and how to use it, see [What is Peer Connection Accepter](https://www.alibabacloud.com/help/en/vpc/developer-reference/api-vpcpeer-2022-01-01-acceptvpcpeerconnection). -> **NOTE:** Available since v1.196.0. @@ -18,12 +20,6 @@ For information about Vpc Peer Connection Accepter and how to use it, see [What Basic Usage -
- ```terraform variable "name" { default = "tf-example" @@ -103,10 +99,11 @@ The following arguments are supported: - `false` (default): no. - `true`: yes. If you forcefully delete the VPC peering connection, the system deletes the routes that point to the VPC peering connection from the VPC route table. * `instance_id` - (Required, ForceNew) The ID of the VPC peering connection whose name or description you want to modify. +* `link_type` - (Optional, Computed, Available since v1.240.0) Link Type. Valid values: `Platinum`, `Gold`, `Silver`. * `peer_connection_accepter_name` - (Optional, Computed, Available since v1.231.0) The new name of the VPC peering connection. The name must be 1 to 128 characters in length, and cannot start with `http://` or `https://`. -* `resource_group_id` - (Optional, Computed, Available since v1.231.0) The ID of the new resource group. +* `resource_group_id` - (Optional, Computed) The ID of the new resource group. -> **NOTE:** You can use resource groups to manage resources within your Alibaba Cloud account by group. This helps you resolve issues such as resource grouping and permission management for your Alibaba Cloud account. For more information, see [What is resource management?](https://www.alibabacloud.com/help/en/doc-detail/94475.html) @@ -122,6 +119,9 @@ The following attributes are exported: * `accepting_region_id` - The region ID of the recipient of the VPC peering connection to be created.-to-peer connection in the same region, enter the same region ID as the region ID of the initiator.-region VPC peer-to-peer connection, enter a region ID that is different from the region ID of the initiator. * `accepting_vpc_id` - The VPC ID of the receiving end of the VPC peer connection. * `create_time` - The creation time of the VPC peer connection. Use UTC time in the format' YYYY-MM-DDThh:mm:ssZ '. +* `region_id` - The ID of the region where you want to query VPC peering connections. + + You can call the [DescribeRegions](https://www.alibabacloud.com/help/en/doc-detail/36063.html) operation to query the most recent region list. * `status` - The status of the resource * `vpc_id` - The VPC ID of the initiator of the VPC peering connection. @@ -134,7 +134,7 @@ The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/d ## Import -Vpc Peer Connection Accepter can be imported using the id, e.g. +Vpc Peer Peer Connection Accepter can be imported using the id, e.g. ```shell $ terraform import alicloud_vpc_peer_connection_accepter.example