diff --git a/alicloud/resource_alicloud_vpc.go b/alicloud/resource_alicloud_vpc.go index bbc9083822a7..98ddf8698f8f 100644 --- a/alicloud/resource_alicloud_vpc.go +++ b/alicloud/resource_alicloud_vpc.go @@ -1,4 +1,3 @@ -// Package alicloud. This file is generated automatically. Please do not modify it manually, thank you! package alicloud import ( @@ -45,6 +44,12 @@ func resourceAliCloudVpcVpc() *schema.Resource { Type: schema.TypeString, Optional: true, }, + "dns_hostname_status": { + Type: schema.TypeString, + Optional: true, + Computed: true, + ValidateFunc: StringInSlice([]string{"ENABLED", "DISABLED", "MODIFYING"}, false), + }, "dry_run": { Type: schema.TypeBool, Optional: true, @@ -53,6 +58,10 @@ func resourceAliCloudVpcVpc() *schema.Resource { Type: schema.TypeBool, Optional: true, }, + "ipv4_cidr_mask": { + Type: schema.TypeInt, + Optional: true, + }, "ipv4_ipam_pool_id": { Type: schema.TypeString, Optional: true, @@ -83,6 +92,10 @@ func resourceAliCloudVpcVpc() *schema.Resource { Type: schema.TypeString, Optional: true, }, + "region_id": { + Type: schema.TypeString, + Computed: true, + }, "resource_group_id": { Type: schema.TypeString, Optional: true, @@ -90,8 +103,9 @@ func resourceAliCloudVpcVpc() *schema.Resource { }, "route_table_id": { Type: schema.TypeString, - Computed: true, + Optional: true, ConflictsWith: []string{"router_table_id"}, + Computed: true, }, "router_id": { Type: schema.TypeString, @@ -104,6 +118,10 @@ func resourceAliCloudVpcVpc() *schema.Resource { Deprecated: "Field 'secondary_cidr_blocks' has been deprecated from provider version 1.185.0. Field 'secondary_cidr_blocks' has been deprecated from provider version 1.185.0 and it will be removed in the future version. Please use the new resource 'alicloud_vpc_ipv4_cidr_block'. `secondary_cidr_blocks` attributes and `alicloud_vpc_ipv4_cidr_block` resource cannot be used at the same time.", Elem: &schema.Schema{Type: schema.TypeString}, }, + "secondary_cidr_mask": { + Type: schema.TypeInt, + Optional: true, + }, "status": { Type: schema.TypeString, Computed: true, @@ -131,8 +149,8 @@ func resourceAliCloudVpcVpc() *schema.Resource { "vpc_name": { Type: schema.TypeString, Optional: true, - Computed: true, ConflictsWith: []string{"name"}, + Computed: true, }, "name": { Type: schema.TypeString, @@ -142,6 +160,7 @@ func resourceAliCloudVpcVpc() *schema.Resource { }, "router_table_id": { Type: schema.TypeString, + Optional: true, Computed: true, Deprecated: "Field 'router_table_id' has been deprecated since provider version 1.221.0. New field 'route_table_id' instead.", }, @@ -160,7 +179,7 @@ func resourceAliCloudVpcVpcCreate(d *schema.ResourceData, meta interface{}) erro var err error query := make(map[string]interface{}) request = make(map[string]interface{}) - query["RegionId"] = client.RegionId + request["RegionId"] = client.RegionId request["ClientToken"] = buildClientToken(action) if v, ok := d.GetOk("cidr_block"); ok { @@ -202,6 +221,14 @@ func resourceAliCloudVpcVpcCreate(d *schema.ResourceData, meta interface{}) erro if v, ok := d.GetOkExists("dry_run"); ok { request["DryRun"] = v } + if v, ok := d.GetOk("dns_hostname_status"); ok { + request["EnableDnsHostname"] = convertVpcVpcEnableDnsHostnameRequest(v.(string)) + } + if v, ok := d.GetOkExists("ipv4_cidr_mask"); ok { + request["Ipv4CidrMask"] = 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("vpc", "2016-04-28", action, query, request, true) @@ -212,9 +239,9 @@ func resourceAliCloudVpcVpcCreate(d *schema.ResourceData, meta interface{}) erro } return resource.NonRetryableError(err) } - addDebug(action, response, request) return nil }) + addDebug(action, response, request) if err != nil { return WrapErrorf(err, DefaultErrorMsg, "alicloud_vpc", action, AlibabaCloudSdkGoERROR) @@ -238,7 +265,7 @@ func resourceAliCloudVpcVpcCreate(d *schema.ResourceData, meta interface{}) erro var err error query := make(map[string]interface{}) request = make(map[string]interface{}) - query["RegionId"] = client.RegionId + request["RegionId"] = client.RegionId request["ClientToken"] = buildClientToken(action) if v, ok := d.GetOk("ipv6_cidr_block"); ok { @@ -262,9 +289,9 @@ func resourceAliCloudVpcVpcCreate(d *schema.ResourceData, meta interface{}) erro } return resource.NonRetryableError(err) } - addDebug(action, response, request) return nil }) + addDebug(action, response, request) if err != nil { return WrapErrorf(err, DefaultErrorMsg, "alicloud_vpc", action, AlibabaCloudSdkGoERROR) @@ -294,21 +321,25 @@ func resourceAliCloudVpcVpcRead(d *schema.ResourceData, meta interface{}) error if objectRaw["CidrBlock"] != nil { d.Set("cidr_block", objectRaw["CidrBlock"]) } - if objectRaw["ClassicLinkEnabled"] != nil { - d.Set("classic_link_enabled", objectRaw["ClassicLinkEnabled"]) - } + d.Set("classic_link_enabled", objectRaw["ClassicLinkEnabled"]) if objectRaw["CreationTime"] != nil { d.Set("create_time", objectRaw["CreationTime"]) } if objectRaw["Description"] != nil { d.Set("description", objectRaw["Description"]) } + if objectRaw["DnsHostnameStatus"] != nil { + d.Set("dns_hostname_status", objectRaw["DnsHostnameStatus"]) + } if objectRaw["EnabledIpv6"] != nil { d.Set("enable_ipv6", objectRaw["EnabledIpv6"]) } if objectRaw["Ipv6CidrBlock"] != nil { d.Set("ipv6_cidr_block", objectRaw["Ipv6CidrBlock"]) } + if objectRaw["RegionId"] != nil { + d.Set("region_id", objectRaw["RegionId"]) + } if objectRaw["ResourceGroupId"] != nil { d.Set("resource_group_id", objectRaw["ResourceGroupId"]) } @@ -342,8 +373,8 @@ func resourceAliCloudVpcVpcRead(d *schema.ResourceData, meta interface{}) error userCidr1Raw, _ := jsonpath.Get("$.UserCidrs.UserCidr", objectRaw) d.Set("user_cidrs", userCidr1Raw) - objectRaw, err = vpcServiceV2.DescribeDescribeRouteTableList(d.Id()) - if err != nil { + objectRaw, err = vpcServiceV2.DescribeVpcDescribeRouteTableList(d.Id()) + if err != nil && !NotFoundError(err) { return WrapError(err) } @@ -375,6 +406,81 @@ func resourceAliCloudVpcVpcUpdate(d *schema.ResourceData, meta interface{}) erro var query map[string]interface{} update := false d.Partial(true) + + if d.HasChange("classic_link_enabled") { + vpcServiceV2 := VpcServiceV2{client} + object, err := vpcServiceV2.DescribeVpcVpc(d.Id()) + if err != nil { + return WrapError(err) + } + + target := d.Get("classic_link_enabled").(bool) + if _, ok := object["ClassicLinkEnabled"]; ok && object["ClassicLinkEnabled"].(bool) != target { + if target == true { + action := "EnableVpcClassicLink" + conn, err := client.NewVpcClient() + if err != nil { + return WrapError(err) + } + request = make(map[string]interface{}) + query = make(map[string]interface{}) + request["VpcId"] = d.Id() + request["RegionId"] = client.RegionId + request["ClientToken"] = buildClientToken(action) + 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("2016-04-28"), StringPointer("AK"), query, request, &runtime) + if err != nil { + if IsExpectedErrors(err, []string{"IncorrectVpcStatus"}) || 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 target == false { + action := "DisableVpcClassicLink" + conn, err := client.NewVpcClient() + if err != nil { + return WrapError(err) + } + request = make(map[string]interface{}) + query = make(map[string]interface{}) + request["VpcId"] = d.Id() + request["RegionId"] = client.RegionId + request["ClientToken"] = buildClientToken(action) + 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("2016-04-28"), StringPointer("AK"), query, request, &runtime) + if err != nil { + if IsExpectedErrors(err, []string{"InternalError", "IncorrectVpcStatus"}) || 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) + } + + } + } + } + action := "ModifyVpcAttribute" conn, err := client.NewVpcClient() if err != nil { @@ -382,8 +488,8 @@ func resourceAliCloudVpcVpcUpdate(d *schema.ResourceData, meta interface{}) erro } request = make(map[string]interface{}) query = make(map[string]interface{}) - query["VpcId"] = d.Id() - query["RegionId"] = client.RegionId + request["VpcId"] = d.Id() + request["RegionId"] = client.RegionId if !d.IsNewResource() && d.HasChange("description") { update = true request["Description"] = d.Get("description") @@ -412,6 +518,11 @@ func resourceAliCloudVpcVpcUpdate(d *schema.ResourceData, meta interface{}) erro if v, ok := d.GetOk("ipv6_isp"); ok { request["Ipv6Isp"] = v } + if !d.IsNewResource() && d.HasChange("dns_hostname_status") { + update = true + request["EnableDnsHostname"] = convertVpcVpcEnableDnsHostnameRequest(d.Get("dns_hostname_status").(string)) + } + if update { runtime := util.RuntimeOptions{} runtime.SetAutoretry(true) @@ -425,9 +536,9 @@ func resourceAliCloudVpcVpcUpdate(d *schema.ResourceData, meta interface{}) erro } 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) } @@ -445,13 +556,12 @@ func resourceAliCloudVpcVpcUpdate(d *schema.ResourceData, meta interface{}) erro } 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["NewResourceGroupId"] = d.Get("resource_group_id") request["ResourceType"] = "VPC" if update { runtime := util.RuntimeOptions{} @@ -466,9 +576,9 @@ func resourceAliCloudVpcVpcUpdate(d *schema.ResourceData, meta interface{}) erro } 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) } @@ -484,7 +594,7 @@ func resourceAliCloudVpcVpcUpdate(d *schema.ResourceData, meta interface{}) erro query["RegionId"] = client.RegionId vpcServiceV2 := VpcServiceV2{client} - objectRaw, err := vpcServiceV2.DescribeDescribeRouteTableList(d.Id()) + objectRaw, err := vpcServiceV2.DescribeVpcDescribeRouteTableList(d.Id()) if err != nil { return WrapError(err) } @@ -525,89 +635,14 @@ func resourceAliCloudVpcVpcUpdate(d *schema.ResourceData, meta interface{}) erro } 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) } } - if d.HasChange("classic_link_enabled") { - client := meta.(*connectivity.AliyunClient) - vpcServiceV2 := VpcServiceV2{client} - object, err := vpcServiceV2.DescribeVpcVpc(d.Id()) - if err != nil { - return WrapError(err) - } - - target := d.Get("classic_link_enabled").(bool) - if object["ClassicLinkEnabled"].(bool) != target { - if target == true { - action = "EnableVpcClassicLink" - conn, err = client.NewVpcClient() - if err != nil { - return WrapError(err) - } - request = make(map[string]interface{}) - query = make(map[string]interface{}) - query["VpcId"] = d.Id() - query["RegionId"] = client.RegionId - request["ClientToken"] = buildClientToken(action) - 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("2016-04-28"), StringPointer("AK"), query, request, &runtime) - if err != nil { - if IsExpectedErrors(err, []string{"IncorrectVpcStatus"}) || 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 target == false { - action = "DisableVpcClassicLink" - conn, err = client.NewVpcClient() - if err != nil { - return WrapError(err) - } - request = make(map[string]interface{}) - query = make(map[string]interface{}) - query["VpcId"] = d.Id() - query["RegionId"] = client.RegionId - request["ClientToken"] = buildClientToken(action) - 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("2016-04-28"), StringPointer("AK"), query, request, &runtime) - if err != nil { - if IsExpectedErrors(err, []string{"InternalError", "IncorrectVpcStatus"}) || 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("secondary_cidr_blocks") { oldEntry, newEntry := d.GetChange("secondary_cidr_blocks") removed := oldEntry @@ -624,8 +659,8 @@ func resourceAliCloudVpcVpcUpdate(d *schema.ResourceData, meta interface{}) erro } request = make(map[string]interface{}) query = make(map[string]interface{}) - query["VpcId"] = d.Id() - query["RegionId"] = client.RegionId + request["VpcId"] = d.Id() + request["RegionId"] = client.RegionId if v, ok := item.(string); ok { jsonPathResult, err := jsonpath.Get("$", v) if err != nil { @@ -645,9 +680,9 @@ func resourceAliCloudVpcVpcUpdate(d *schema.ResourceData, meta interface{}) erro } 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) } @@ -671,8 +706,8 @@ func resourceAliCloudVpcVpcUpdate(d *schema.ResourceData, meta interface{}) erro } request = make(map[string]interface{}) query = make(map[string]interface{}) - query["VpcId"] = d.Id() - query["RegionId"] = client.RegionId + request["VpcId"] = d.Id() + request["RegionId"] = client.RegionId if v, ok := item.(string); ok { jsonPathResult, err := jsonpath.Get("$", v) if err != nil { @@ -685,6 +720,9 @@ func resourceAliCloudVpcVpcUpdate(d *schema.ResourceData, meta interface{}) erro _request := make(map[string]interface{}) _request["IpamPoolId"] = v } + if v, ok := d.GetOkExists("secondary_cidr_mask"); ok { + request["SecondaryCidrMask"] = v + } runtime := util.RuntimeOptions{} runtime.SetAutoretry(true) wait := incrementalWait(3*time.Second, 5*time.Second) @@ -697,9 +735,9 @@ func resourceAliCloudVpcVpcUpdate(d *schema.ResourceData, meta interface{}) erro } 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) } @@ -734,8 +772,9 @@ func resourceAliCloudVpcVpcDelete(d *schema.ResourceData, meta interface{}) erro return WrapError(err) } request = make(map[string]interface{}) - query["VpcId"] = d.Id() - query["RegionId"] = client.RegionId + request["VpcId"] = d.Id() + request["RegionId"] = client.RegionId + request["ClientToken"] = buildClientToken(action) if v, ok := d.GetOkExists("dry_run"); ok { request["DryRun"] = v @@ -747,18 +786,18 @@ func resourceAliCloudVpcVpcDelete(d *schema.ResourceData, meta interface{}) erro response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2016-04-28"), StringPointer("AK"), query, request, &runtime) if err != nil { - if NeedRetry(err) || IsExpectedErrors(err, []string{"DependencyViolation.VSwitch", "DependencyViolation.SecurityGroup", "IncorrectVpcStatus"}) { + if IsExpectedErrors(err, []string{"DependencyViolation.VSwitch", "DependencyViolation.SecurityGroup", "IncorrectVpcStatus"}) || 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{"InvalidResource.NotFound"}) { + if IsExpectedErrors(err, []string{"InvalidResource.NotFound"}) || NotFoundError(err) { return nil } return WrapErrorf(err, DefaultErrorMsg, d.Id(), action, AlibabaCloudSdkGoERROR) @@ -772,3 +811,14 @@ func resourceAliCloudVpcVpcDelete(d *schema.ResourceData, meta interface{}) erro return nil } + +func convertVpcVpcEnableDnsHostnameRequest(source interface{}) interface{} { + source = fmt.Sprint(source) + switch source { + case "ENABLED": + return "true" + case "DISABLED": + return "false" + } + return source +} diff --git a/alicloud/resource_alicloud_vpc_test.go b/alicloud/resource_alicloud_vpc_test.go index a16df379977f..25d7db376e3f 100644 --- a/alicloud/resource_alicloud_vpc_test.go +++ b/alicloud/resource_alicloud_vpc_test.go @@ -1145,8 +1145,6 @@ func TestUnitAlicloudVPCdsafa(t *testing.T) { }) } -// Test Vpc Vpc. >>> Resource test cases, automatically generated. -// Case 3113 func TestAccAliCloudVpcVpc_basic3113(t *testing.T) { var v map[string]interface{} resourceId := "alicloud_vpc.default" @@ -1395,4 +1393,134 @@ func TestAccAliCloudVpcVpc_basic3113_twin(t *testing.T) { }) } +// Test Vpc Vpc. >>> Resource test cases, automatically generated. +// Case 从IPAM地址池创建VPC及添加附加网段 9656 +func TestAccAliCloudVpcVpc_basic9656(t *testing.T) { + var v map[string]interface{} + resourceId := "alicloud_vpc.default" + ra := resourceAttrInit(resourceId, AlicloudVpcVpcMap9656) + rc := resourceCheckInitWithDescribeMethod(resourceId, &v, func() interface{} { + return &VpcServiceV2{testAccProvider.Meta().(*connectivity.AliyunClient)} + }, "DescribeVpcVpc") + rac := resourceAttrCheckInit(rc, ra) + testAccCheck := rac.resourceAttrMapUpdateSet() + rand := acctest.RandIntRange(10000, 99999) + name := fmt.Sprintf("tf-testacc%svpcvpc%d", defaultRegionToTest, rand) + testAccConfig := resourceTestAccConfigFunc(resourceId, name, AlicloudVpcVpcBasicDependence9656) + resource.Test(t, resource.TestCase{ + PreCheck: func() { + testAccPreCheckWithRegions(t, true, []connectivity.Region{"cn-hangzhou"}) + testAccPreCheck(t) + }, + IDRefreshName: resourceId, + Providers: testAccProviders, + CheckDestroy: rac.checkResourceDestroy(), + Steps: []resource.TestStep{ + { + Config: testAccConfig(map[string]interface{}{ + "ipv4_cidr_mask": "24", + "ipv4_ipam_pool_id": "${alicloud_vpc_ipam_ipam_pool.defaultIpamPool.id}", + }), + Check: resource.ComposeTestCheckFunc( + testAccCheck(map[string]string{ + "ipv4_cidr_mask": "24", + "ipv4_ipam_pool_id": CHECKSET, + }), + ), + }, + { + Config: testAccConfig(map[string]interface{}{ + "secondary_cidr_mask": "24", + "description": "desc", + }), + Check: resource.ComposeTestCheckFunc( + testAccCheck(map[string]string{ + "secondary_cidr_mask": "24", + "description": "desc", + }), + ), + }, + { + 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", "ipv4_cidr_mask", "ipv4_ipam_pool_id", "ipv6_isp", "secondary_cidr_mask"}, + }, + }, + }) +} + +var AlicloudVpcVpcMap9656 = map[string]string{ + "router_id": CHECKSET, + "status": CHECKSET, + "create_time": CHECKSET, + "region_id": CHECKSET, +} + +func AlicloudVpcVpcBasicDependence9656(name string) string { + return fmt.Sprintf(` +variable "name" { + default = "%s" +} + +resource "alicloud_vpc_ipam_ipam" "defaultIpam" { + operating_region_list = ["cn-hangzhou"] +} + +resource "alicloud_vpc_ipam_ipam_pool" "defaultIpamPool" { + ipam_scope_id = alicloud_vpc_ipam_ipam.defaultIpam.private_default_scope_id + pool_region_id = alicloud_vpc_ipam_ipam.defaultIpam.region_id +} + +resource "alicloud_vpc_ipam_ipam_pool_cidr" "defaultIpamPoolCidr" { + cidr = "10.0.0.0/8" + ipam_pool_id = alicloud_vpc_ipam_ipam_pool.defaultIpamPool.id +} + + +`, name) +} + // Test Vpc Vpc. <<< Resource test cases, automatically generated. diff --git a/alicloud/service_alicloud_vpc_v2.go b/alicloud/service_alicloud_vpc_v2.go index f3fcfc4c2766..249e8d2ac21c 100644 --- a/alicloud/service_alicloud_vpc_v2.go +++ b/alicloud/service_alicloud_vpc_v2.go @@ -120,12 +120,12 @@ func (s *VpcServiceV2) SetResourceTags(d *schema.ResourceData, resourceType stri request = make(map[string]interface{}) query = make(map[string]interface{}) request["ResourceId.1"] = d.Id() - query["RegionId"] = client.RegionId + request["RegionId"] = client.RegionId + request["ResourceType"] = resourceType for i, key := range removedTagKeys { request[fmt.Sprintf("TagKey.%d", i+1)] = key } - request["ResourceType"] = resourceType runtime := util.RuntimeOptions{} runtime.SetAutoretry(true) wait := incrementalWait(3*time.Second, 5*time.Second) @@ -138,9 +138,9 @@ func (s *VpcServiceV2) SetResourceTags(d *schema.ResourceData, resourceType stri } 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) } @@ -156,7 +156,8 @@ func (s *VpcServiceV2) SetResourceTags(d *schema.ResourceData, resourceType stri request = make(map[string]interface{}) query = make(map[string]interface{}) request["ResourceId.1"] = d.Id() - query["RegionId"] = client.RegionId + request["RegionId"] = client.RegionId + request["ResourceType"] = resourceType count := 1 for key, value := range added { request[fmt.Sprintf("Tag.%d.Key", count)] = key @@ -164,7 +165,6 @@ func (s *VpcServiceV2) SetResourceTags(d *schema.ResourceData, resourceType stri count++ } - request["ResourceType"] = resourceType runtime := util.RuntimeOptions{} runtime.SetAutoretry(true) wait := incrementalWait(3*time.Second, 5*time.Second) @@ -177,9 +177,9 @@ func (s *VpcServiceV2) SetResourceTags(d *schema.ResourceData, resourceType stri } 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) } @@ -890,11 +890,10 @@ func (s *VpcServiceV2) DescribeVpcVpc(id string) (object map[string]interface{}, } return resource.NonRetryableError(err) } - addDebug(action, response, request) return nil }) + addDebug(action, response, request) if err != nil { - addDebug(action, response, request) return object, WrapErrorf(err, DefaultErrorMsg, id, action, AlibabaCloudSdkGoERROR) } @@ -905,7 +904,7 @@ func (s *VpcServiceV2) DescribeVpcVpc(id string) (object map[string]interface{}, return response, nil } -func (s *VpcServiceV2) DescribeDescribeRouteTableList(id string) (object map[string]interface{}, err error) { +func (s *VpcServiceV2) DescribeVpcDescribeRouteTableList(id string) (object map[string]interface{}, err error) { client := s.client var request map[string]interface{} var response map[string]interface{} @@ -926,11 +925,10 @@ func (s *VpcServiceV2) DescribeDescribeRouteTableList(id string) (object map[str } return resource.NonRetryableError(err) } - addDebug(action, response, request) return nil }) + addDebug(action, response, request) if err != nil { - addDebug(action, response, request) return object, WrapErrorf(err, DefaultErrorMsg, id, action, AlibabaCloudSdkGoERROR) } @@ -946,57 +944,15 @@ func (s *VpcServiceV2) DescribeDescribeRouteTableList(id string) (object map[str result, _ := v.([]interface{}) for _, v := range result { item := v.(map[string]interface{}) - if item["RouteTableType"] != "System" { + if fmt.Sprint(item["RouteTableType"]) != "System" { continue } - if item["VpcId"] != id { + if fmt.Sprint(item["VpcId"]) != id { continue } return item, nil } - - return v.([]interface{})[0].(map[string]interface{}), nil -} -func (s *VpcServiceV2) DescribeListTagResources(id string) (object map[string]interface{}, err error) { - - client := s.client - var request map[string]interface{} - var response map[string]interface{} - var query map[string]interface{} - action := "ListTagResources" - conn, err := client.NewVpcClient() - if err != nil { - return object, WrapError(err) - } - request = make(map[string]interface{}) - query = make(map[string]interface{}) - - request["ResourceId.1"] = id - request["RegionId"] = client.RegionId - - request["ResourceType"] = "VPC" - wait := incrementalWait(3*time.Second, 5*time.Second) - err = resource.Retry(1*time.Minute, func() *resource.RetryError { - response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2016-04-28"), StringPointer("AK"), query, request, &util.RuntimeOptions{}) - - if err != nil { - if NeedRetry(err) { - wait() - return resource.RetryableError(err) - } - return resource.NonRetryableError(err) - } - addDebug(action, response, request) - return nil - }) - if err != nil { - if IsExpectedErrors(err, []string{}) { - return object, WrapErrorf(Error(GetNotFoundMessage("Vpc", id)), NotFoundMsg, ProviderERROR, fmt.Sprint(response["RequestId"])) - } - return object, WrapErrorf(err, DefaultErrorMsg, id, action, AlibabaCloudSdkGoERROR) - } - - return response, nil + return object, WrapErrorf(Error(GetNotFoundMessage("Vpc", id)), NotFoundMsg, response) } func (s *VpcServiceV2) VpcVpcStateRefreshFunc(id string, field string, failStates []string) resource.StateRefreshFunc { @@ -1012,6 +968,13 @@ func (s *VpcServiceV2) VpcVpcStateRefreshFunc(id string, field string, failState 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.html.markdown b/website/docs/r/vpc.html.markdown index 9800dd9a2b7d..82bc72c6bedc 100644 --- a/website/docs/r/vpc.html.markdown +++ b/website/docs/r/vpc.html.markdown @@ -3,12 +3,12 @@ subcategory: "VPC" layout: "alicloud" page_title: "Alicloud: alicloud_vpc" description: |- - Provides a Alicloud VPC Vpc resource. + Provides a Alicloud VPC VPC resource. --- # alicloud_vpc -Provides a VPC Vpc resource. +Provides a VPC VPC resource. A VPC instance creates a VPC. You can fully control your own VPC, such as selecting IP address ranges, configuring routing tables, and gateways. You can use Alibaba cloud resources such as cloud servers, apsaradb for RDS, and load balancer in your own VPC. @@ -27,12 +27,6 @@ For information about VPC Vpc and how to use it, see [What is Vpc](https://www.a Basic Usage -