From a8c49cb2bed7e3a6e5f2c4776855144c0ee00a44 Mon Sep 17 00:00:00 2001 From: SevenEarth <391613297@qq.com> Date: Thu, 4 Jul 2024 15:29:33 +0800 Subject: [PATCH 1/4] fix/clb_projectId --- .../services/clb/resource_tc_clb_instance.go | 165 ++++++---- .../services/clb/resource_tc_clb_instance.md | 281 +++++++++++------- website/docs/r/clb_instance.html.markdown | 263 +++++++++------- 3 files changed, 445 insertions(+), 264 deletions(-) diff --git a/tencentcloud/services/clb/resource_tc_clb_instance.go b/tencentcloud/services/clb/resource_tc_clb_instance.go index 4afed2ac63..7f38549f44 100644 --- a/tencentcloud/services/clb/resource_tc_clb_instance.go +++ b/tencentcloud/services/clb/resource_tc_clb_instance.go @@ -29,7 +29,6 @@ func ResourceTencentCloudClbInstance() *schema.Resource { Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, }, - Schema: map[string]*schema.Schema{ "network_type": { Type: schema.TypeString, @@ -182,18 +181,23 @@ func ResourceTencentCloudClbInstance() *schema.Resource { Description: "Whether the target allow flow come from clb. If value is true, only check security group of clb, or check both clb and backend instance security group.", }, "master_zone_id": { - Type: schema.TypeString, - Optional: true, - Description: "Setting master zone id of cross available zone disaster recovery, only applicable to open CLB.", + Type: schema.TypeString, + Optional: true, + Computed: true, + ConflictsWith: []string{"zone_id"}, + Description: "Setting master zone id of cross available zone disaster recovery, only applicable to open CLB.", }, "zone_id": { - Type: schema.TypeString, - Optional: true, - Description: "Available zone id, only applicable to open CLB.", + Type: schema.TypeString, + Optional: true, + Computed: true, + ConflictsWith: []string{"master_zone_id"}, + Description: "Available zone id, only applicable to open CLB.", }, "slave_zone_id": { Type: schema.TypeString, Optional: true, + Computed: true, Description: "Setting slave zone id of cross available zone disaster recovery, only applicable to open CLB. this zone will undertake traffic when the master is down.", }, "log_set_id": { @@ -244,9 +248,11 @@ func resourceTencentCloudClbInstanceCreate(d *schema.ResourceData, meta interfac if e != nil { return e } + if flag { return fmt.Errorf("[CHECK][CLB instance][Create] check: Same CLB name %s exists!", clbName) } + targetRegionInfoRegion := "" targetRegionInfoVpcId := "" if v, ok := d.GetOk("target_region_info_region"); ok { @@ -255,12 +261,14 @@ func resourceTencentCloudClbInstanceCreate(d *schema.ResourceData, meta interfac return fmt.Errorf("[CHECK][CLB instance][Create] check: INTERNAL network_type do not support this operation with target_region_info") } } + if v, ok := d.GetOk("target_region_info_vpc_id"); ok { targetRegionInfoVpcId = v.(string) if networkType == CLB_NETWORK_TYPE_INTERNAL { return fmt.Errorf("[CHECK][CLB instance][Create] check: INTERNAL network_type do not support this operation with target_region_info") } } + if (targetRegionInfoRegion != "" && targetRegionInfoVpcId == "") || (targetRegionInfoRegion == "" && targetRegionInfoVpcId != "") { return fmt.Errorf("[CHECK][CLB instance][Create] check: region and vpc_id must be set at same time") } @@ -271,10 +279,12 @@ func resourceTencentCloudClbInstanceCreate(d *schema.ResourceData, meta interfac if v, ok := d.GetOk("vpc_id"); ok { request.VpcId = helper.String(v.(string)) } + if v, ok := d.GetOk("project_id"); ok { projectId := int64(v.(int)) request.ProjectId = &projectId } + if v, ok := d.GetOk("subnet_id"); ok { request.SubnetId = helper.String(v.(string)) } @@ -284,6 +294,7 @@ func resourceTencentCloudClbInstanceCreate(d *schema.ResourceData, meta interfac if networkType == CLB_NETWORK_TYPE_INTERNAL { return fmt.Errorf("[CHECK][CLB instance][Create] check: INTERNAL network_type do not support vip ISP setting") } + request.VipIsp = helper.String(v.(string)) } @@ -302,6 +313,7 @@ func resourceTencentCloudClbInstanceCreate(d *schema.ResourceData, meta interfac if networkType == CLB_NETWORK_TYPE_INTERNAL { return fmt.Errorf("[CHECK][CLB instance][Create] check: INTERNAL network_type do not support IP version setting") } + request.AddressIPVersion = helper.String(v.(string)) } @@ -316,9 +328,11 @@ func resourceTencentCloudClbInstanceCreate(d *schema.ResourceData, meta interfac snatIp := &clb.SnatIp{ SubnetId: &subnetId, } + if v, ok := item["ip"].(string); ok && v != "" { snatIp.Ip = &v } + request.SnatIps = append(request.SnatIps, snatIp) } } @@ -334,17 +348,21 @@ func resourceTencentCloudClbInstanceCreate(d *schema.ResourceData, meta interfac if networkType == CLB_NETWORK_TYPE_INTERNAL { return fmt.Errorf("[CHECK][CLB instance][Create] check: INTERNAL network_type do not support internet charge type setting") } + request.InternetAccessible = &clb.InternetAccessible{} if ok { request.InternetAccessible.InternetChargeType = helper.String(chargeType) } + if bok { request.InternetAccessible.InternetMaxBandwidthOut = helper.IntInt64(bv.(int)) } + if pok { if chargeType != svcas.INTERNET_CHARGE_TYPE_BANDWIDTH_PACKAGE { return fmt.Errorf("[CHECK][CLB instance][Create] check: internet_charge_type must `BANDWIDTH_PACKAGE` when bandwidth_package_id was set") } + request.BandwidthPackageId = helper.String(pv.(string)) } } @@ -353,6 +371,7 @@ func resourceTencentCloudClbInstanceCreate(d *schema.ResourceData, meta interfac if networkType == CLB_NETWORK_TYPE_INTERNAL { return fmt.Errorf("[CHECK][CLB instance][Create] check: INTERNAL network_type do not support master zone id setting") } + request.MasterZoneId = helper.String(v.(string)) } @@ -360,6 +379,7 @@ func resourceTencentCloudClbInstanceCreate(d *schema.ResourceData, meta interfac if networkType == CLB_NETWORK_TYPE_INTERNAL { return fmt.Errorf("[CHECK][CLB instance][Create] check: INTERNAL network_type do not support zone id setting") } + request.ZoneId = helper.String(v.(string)) } @@ -367,6 +387,7 @@ func resourceTencentCloudClbInstanceCreate(d *schema.ResourceData, meta interfac if networkType == CLB_NETWORK_TYPE_INTERNAL { return fmt.Errorf("[CHECK][CLB instance][Create] check: INTERNAL network_type do not support slave zone id setting") } + request.SlaveZoneId = helper.String(v.(string)) } @@ -404,16 +425,20 @@ func resourceTencentCloudClbInstanceCreate(d *schema.ResourceData, meta interfac return tccommon.RetryError(errors.WithStack(retryErr)) } } + response = result return nil }) + if err != nil { log.Printf("[CRITAL]%s create CLB instance failed, reason:%+v", logId, err) return err } + if len(response.Response.LoadBalancerIds) < 1 { return fmt.Errorf("[CHECK][CLB instance][Create] check: response error, load balancer id is nil") } + d.SetId(*response.Response.LoadBalancerIds[0]) clbId = *response.Response.LoadBalancerIds[0] @@ -428,6 +453,7 @@ func resourceTencentCloudClbInstanceCreate(d *schema.ResourceData, meta interfac sgRequest.SecurityGroups = append(sgRequest.SecurityGroups, &securityGroup) } } + err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError { sgResponse, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseClbClient().SetLoadBalancerSecurityGroups(sgRequest) if e != nil { @@ -442,8 +468,10 @@ func resourceTencentCloudClbInstanceCreate(d *schema.ResourceData, meta interfac return tccommon.RetryError(errors.WithStack(retryErr)) } } + return nil }) + if err != nil { log.Printf("[CRITAL]%s create CLB instance security_groups failed, reason:%+v", logId, err) return err @@ -470,8 +498,10 @@ func resourceTencentCloudClbInstanceCreate(d *schema.ResourceData, meta interfac return tccommon.RetryError(errors.WithStack(retryErr)) } } + return nil }) + if err != nil { log.Printf("[CRITAL]%s set CLB instance log failed, reason:%+v", logId, err) return err @@ -505,13 +535,16 @@ func resourceTencentCloudClbInstanceCreate(d *schema.ResourceData, meta interfac return tccommon.RetryError(errors.WithStack(retryErr)) } } + return nil }) + if err != nil { log.Printf("[CRITAL]%s create CLB instance failed, reason:%+v", logId, err) return err } } + if v, ok := d.GetOkExists("delete_protect"); ok { isDeleteProect := v.(bool) if isDeleteProect { @@ -531,14 +564,17 @@ func resourceTencentCloudClbInstanceCreate(d *schema.ResourceData, meta interfac return tccommon.RetryError(errors.WithStack(retryErr)) } } + return nil }) + if err != nil { log.Printf("[CRITAL]%s create CLB instance failed, reason:%+v", logId, err) return err } } } + return resourceTencentCloudClbInstanceRead(d, meta) } @@ -546,22 +582,24 @@ func resourceTencentCloudClbInstanceRead(d *schema.ResourceData, meta interface{ defer tccommon.LogElapsed("resource.tencentcloud_clb_instance.read")() defer tccommon.InconsistentCheck(d, meta)() - logId := tccommon.GetLogId(tccommon.ContextNil) - ctx := context.WithValue(context.TODO(), tccommon.LogIdKey, logId) + var ( + logId = tccommon.GetLogId(tccommon.ContextNil) + ctx = context.WithValue(context.TODO(), tccommon.LogIdKey, logId) + clbService = ClbService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()} + instance *clb.LoadBalancer + clbId = d.Id() + ) - clbId := d.Id() - clbService := ClbService{ - client: meta.(tccommon.ProviderMeta).GetAPIV3Conn(), - } - var instance *clb.LoadBalancer err := resource.Retry(tccommon.ReadRetryTimeout, func() *resource.RetryError { result, e := clbService.DescribeLoadBalancerById(ctx, clbId) if e != nil { return tccommon.RetryError(e) } + instance = result return nil }) + if err != nil { log.Printf("[CRITAL]%s read CLB instance failed, reason:%+v", logId, err) return err @@ -588,6 +626,7 @@ func resourceTencentCloudClbInstanceRead(d *schema.ResourceData, meta interface{ if instance.SlaType != nil { _ = d.Set("sla_type", instance.SlaType) } + if instance.VipIsp != nil { _ = d.Set("vip_isp", instance.VipIsp) } @@ -602,17 +641,23 @@ func resourceTencentCloudClbInstanceRead(d *schema.ResourceData, meta interface{ } else { _ = d.Set("address_ip_version", instance.AddressIPVersion) } - } + if instance.NetworkAttributes != nil { _ = d.Set("internet_bandwidth_max_out", instance.NetworkAttributes.InternetMaxBandwidthOut) _ = d.Set("internet_charge_type", instance.NetworkAttributes.InternetChargeType) } + if instance.MasterZone != nil { + _ = d.Set("master_zone_id", instance.MasterZone.Zone) + _ = d.Set("zone_id", instance.MasterZone.Zone) + } + + if instance.BackupZoneSet != nil && len(instance.BackupZoneSet) > 0 { + _ = d.Set("slave_zone_id", instance.BackupZoneSet[0].Zone) + } + _ = d.Set("load_balancer_pass_to_target", instance.LoadBalancerPassToTarget) - //_ = d.Set("master_zone_id", instance.MasterZone.ZoneId) - //_ = d.Set("zone_id", instance.Zones) - //_ = d.Set("slave_zone_id", instance.MasterZone) _ = d.Set("log_set_id", instance.LogSetId) _ = d.Set("log_topic_id", instance.LogTopicId) @@ -637,12 +682,22 @@ func resourceTencentCloudClbInstanceUpdate(d *schema.ResourceData, meta interfac clbActionMu.Lock() defer clbActionMu.Unlock() - logId := tccommon.GetLogId(tccommon.ContextNil) - ctx := context.WithValue(context.TODO(), tccommon.LogIdKey, logId) + var ( + logId = tccommon.GetLogId(tccommon.ContextNil) + ctx = context.WithValue(context.TODO(), tccommon.LogIdKey, logId) + clbId = d.Id() + ) + + immutableArgs := []string{"snat_ips", "dynamic_vip", "master_zone_id", "slave_zone_id", "project_id", "vpc_id", "subnet_id", "address_ip_version", "bandwidth_package_id", "zone_id"} + + for _, v := range immutableArgs { + if d.HasChange(v) { + return fmt.Errorf("argument `%s` cannot be changed", v) + } + } d.Partial(true) - clbId := d.Id() request := clb.NewModifyLoadBalancerAttributesRequest() request.LoadBalancerId = helper.String(clbId) clbName := "" @@ -660,9 +715,11 @@ func resourceTencentCloudClbInstanceUpdate(d *schema.ResourceData, meta interfac if err != nil { return err } + if flag { return fmt.Errorf("[CHECK][CLB instance][Update] check: Same CLB name %s exists!", clbName) } + request.LoadBalancerName = helper.String(clbName) } @@ -670,6 +727,7 @@ func resourceTencentCloudClbInstanceUpdate(d *schema.ResourceData, meta interfac if d.Get("network_type") == CLB_NETWORK_TYPE_INTERNAL { return fmt.Errorf("[CHECK][CLB instance %s][Update] check: INTERNAL network_type do not support this operation with target_region_info", clbId) } + changed = true region := d.Get("target_region_info_region").(string) vpcId := d.Get("target_region_info_vpc_id").(string) @@ -684,15 +742,18 @@ func resourceTencentCloudClbInstanceUpdate(d *schema.ResourceData, meta interfac if d.Get("network_type") == CLB_NETWORK_TYPE_INTERNAL { return fmt.Errorf("[CHECK][CLB instance %s][Update] check: INTERNAL network_type do not support this operation with internet setting", clbId) } + changed = true chargeType := d.Get("internet_charge_type").(string) bandwidth := d.Get("internet_bandwidth_max_out").(int) if chargeType != "" { internet.InternetChargeType = &chargeType } + if bandwidth > 0 { internet.InternetMaxBandwidthOut = helper.IntInt64(bandwidth) } + request.InternetChargeInfo = &internet } @@ -706,20 +767,13 @@ func resourceTencentCloudClbInstanceUpdate(d *schema.ResourceData, meta interfac changed = true request.SnatPro = &snatPro } + if d.HasChange("delete_protect") { changed = true isDeleteProtect = d.Get("delete_protect").(bool) request.DeleteProtect = &isDeleteProtect } - immutableArgs := []string{"snat_ips", "dynamic_vip", "master_zone_id", "slave_zone_id", "project_id", "vpc_id", "subnet_id", "address_ip_version", "bandwidth_package_id", "zone_id"} - - for _, v := range immutableArgs { - if d.HasChange(v) { - return fmt.Errorf("argument `%s` cannot be changed", v) - } - } - if changed { err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError { response, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseClbClient().ModifyLoadBalancerAttributes(request) @@ -734,8 +788,10 @@ func resourceTencentCloudClbInstanceUpdate(d *schema.ResourceData, meta interfac return tccommon.RetryError(retryErr) } } + return nil }) + if err != nil { log.Printf("[CRITAL]%s update CLB instance failed, reason:%+v", logId, err) return err @@ -747,7 +803,6 @@ func resourceTencentCloudClbInstanceUpdate(d *schema.ResourceData, meta interfac param := clb.SlaUpdateParam{} param.LoadBalancerId = &clbId param.SlaType = helper.String(d.Get("sla_type").(string)) - slaRequest.LoadBalancerSla = []*clb.SlaUpdateParam{¶m} var taskId string @@ -758,9 +813,11 @@ func resourceTencentCloudClbInstanceUpdate(d *schema.ResourceData, meta interfac } else { log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), result.ToJsonString()) } + taskId = *result.Response.RequestId return nil }) + if err != nil { log.Printf("[CRITAL]%s update clb instanceSlaConfig failed, reason:%+v", logId, err) return err @@ -773,7 +830,6 @@ func resourceTencentCloudClbInstanceUpdate(d *schema.ResourceData, meta interfac } if d.HasChange("security_groups") { - sgRequest := clb.NewSetLoadBalancerSecurityGroupsRequest() sgRequest.LoadBalancerId = helper.String(clbId) securityGroups := d.Get("security_groups").([]interface{}) @@ -782,6 +838,7 @@ func resourceTencentCloudClbInstanceUpdate(d *schema.ResourceData, meta interfac securityGroup := securityGroups[i].(string) sgRequest.SecurityGroups = append(sgRequest.SecurityGroups, &securityGroup) } + err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError { sgResponse, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseClbClient().SetLoadBalancerSecurityGroups(sgRequest) if e != nil { @@ -795,8 +852,10 @@ func resourceTencentCloudClbInstanceUpdate(d *schema.ResourceData, meta interfac return tccommon.RetryError(errors.WithStack(retryErr)) } } + return nil }) + if err != nil { log.Printf("[CRITAL]%s update CLB instance security_group failed, reason:%+v", logId, err) return err @@ -825,8 +884,10 @@ func resourceTencentCloudClbInstanceUpdate(d *schema.ResourceData, meta interfac return tccommon.RetryError(errors.WithStack(retryErr)) } } + return nil }) + if err != nil { log.Printf("[CRITAL]%s set CLB instance log failed, reason:%+v", logId, err) return err @@ -834,10 +895,8 @@ func resourceTencentCloudClbInstanceUpdate(d *schema.ResourceData, meta interfac } if d.HasChange("tags") { - oldValue, newValue := d.GetChange("tags") replaceTags, deleteTags := svctag.DiffTags(oldValue.(map[string]interface{}), newValue.(map[string]interface{})) - tcClient := meta.(tccommon.ProviderMeta).GetAPIV3Conn() tagService := svctag.NewTagService(tcClient) resourceName := tccommon.BuildTagResourceName("clb", "clb", tcClient.Region, d.Id()) @@ -845,10 +904,9 @@ func resourceTencentCloudClbInstanceUpdate(d *schema.ResourceData, meta interfac if err != nil { return err } - } - d.Partial(false) + d.Partial(false) return nil } @@ -858,21 +916,22 @@ func resourceTencentCloudClbInstanceDelete(d *schema.ResourceData, meta interfac clbActionMu.Lock() defer clbActionMu.Unlock() - logId := tccommon.GetLogId(tccommon.ContextNil) - ctx := context.WithValue(context.TODO(), tccommon.LogIdKey, logId) - - clbId := d.Id() - clbService := ClbService{ - client: meta.(tccommon.ProviderMeta).GetAPIV3Conn(), - } + var ( + logId = tccommon.GetLogId(tccommon.ContextNil) + ctx = context.WithValue(context.TODO(), tccommon.LogIdKey, logId) + clbService = ClbService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()} + clbId = d.Id() + ) err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError { e := clbService.DeleteLoadBalancerById(ctx, clbId) if e != nil { return tccommon.RetryError(e) } + return nil }) + if err != nil { log.Printf("[CRITAL]%s delete CLB instance failed, reason:%+v", logId, err) return err @@ -882,12 +941,12 @@ func resourceTencentCloudClbInstanceDelete(d *schema.ResourceData, meta interfac } func checkSameName(name string, meta interface{}) (flag bool, errRet error) { - logId := tccommon.GetLogId(tccommon.ContextNil) - ctx := context.WithValue(context.TODO(), tccommon.LogIdKey, logId) - flag = false - clbService := ClbService{ - client: meta.(tccommon.ProviderMeta).GetAPIV3Conn(), - } + var ( + logId = tccommon.GetLogId(tccommon.ContextNil) + ctx = context.WithValue(context.TODO(), tccommon.LogIdKey, logId) + clbService = ClbService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()} + ) + params := make(map[string]interface{}) params["clb_name"] = name err := resource.Retry(tccommon.ReadRetryTimeout, func() *resource.RetryError { @@ -895,21 +954,25 @@ func checkSameName(name string, meta interface{}) (flag bool, errRet error) { if e != nil { return tccommon.RetryError(e) } + if len(clbs) > 0 { - //this describe function is a fuzzy query + //this function is a fuzzy query // so take a further check - for _, clb := range clbs { - if *clb.LoadBalancerName == name { + for _, clbInfo := range clbs { + if *clbInfo.LoadBalancerName == name { flag = true return nil } } } + return nil }) + if err != nil { log.Printf("[CRITAL]%s read CLB instance failed, reason:%+v", logId, err) } + errRet = err return } diff --git a/tencentcloud/services/clb/resource_tc_clb_instance.md b/tencentcloud/services/clb/resource_tc_clb_instance.md index fcf7b4edb1..215b2477ff 100644 --- a/tencentcloud/services/clb/resource_tc_clb_instance.md +++ b/tencentcloud/services/clb/resource_tc_clb_instance.md @@ -5,15 +5,27 @@ Example Usage INTERNAL CLB ```hcl -resource "tencentcloud_clb_instance" "internal_clb" { +resource "tencentcloud_vpc" "vpc" { + cidr_block = "10.0.0.0/16" + name = "vpc" +} + +resource "tencentcloud_subnet" "subnet" { + vpc_id = tencentcloud_vpc.vpc.id + availability_zone = "ap-guangzhou-4" + name = "subnet" + cidr_block = "10.0.1.0/24" +} + +resource "tencentcloud_clb_instance" "example" { network_type = "INTERNAL" - clb_name = "myclb" + clb_name = "tf-example" project_id = 0 - vpc_id = "vpc-7007ll7q" - subnet_id = "subnet-12rastkr" + vpc_id = tencentcloud_vpc.vpc.id + subnet_id = tencentcloud_subnet.subnet.id tags = { - test = "tf" + tagKey = "tagValue" } } ``` @@ -21,16 +33,28 @@ resource "tencentcloud_clb_instance" "internal_clb" { LCU-supported CLB ```hcl -resource "tencentcloud_clb_instance" "internal_clb" { +resource "tencentcloud_vpc" "vpc" { + cidr_block = "10.0.0.0/16" + name = "vpc" +} + +resource "tencentcloud_subnet" "subnet" { + vpc_id = tencentcloud_vpc.vpc.id + availability_zone = "ap-guangzhou-4" + name = "subnet" + cidr_block = "10.0.1.0/24" +} + +resource "tencentcloud_clb_instance" "example" { network_type = "INTERNAL" - clb_name = "myclb" + clb_name = "tf-example" project_id = 0 sla_type = "clb.c3.medium" - vpc_id = "vpc-2hfyray3" - subnet_id = "subnet-o3a5nt20" + vpc_id = tencentcloud_vpc.vpc.id + subnet_id = tencentcloud_subnet.subnet.id tags = { - test = "tf" + tagKey = "tagValue" } } ``` @@ -38,40 +62,74 @@ resource "tencentcloud_clb_instance" "internal_clb" { OPEN CLB ```hcl -resource "tencentcloud_clb_instance" "open_clb" { - network_type = "OPEN" - clb_name = "myclb" - project_id = 0 - vpc_id = "vpc-da7ffa61" - security_groups = ["sg-o0ek7r93"] +resource "tencentcloud_vpc" "vpc" { + cidr_block = "10.0.0.0/16" + name = "vpc" +} + +resource "tencentcloud_security_group" "example" { + name = "tf-example" + description = "sg desc." + project_id = 0 + + tags = { + "example" = "test" + } +} + +resource "tencentcloud_clb_instance" "example" { + network_type = "OPEN" + clb_name = "tf-example" + project_id = 0 + vpc_id = tencentcloud_vpc.vpc.id + security_groups = [tencentcloud_security_group.example.id] tags = { - test = "tf" + tagKey = "tagValue" } } ``` -SUPPORT CORS +Support CORS ```hcl -resource "tencentcloud_clb_instance" "open_clb" { +resource "tencentcloud_vpc" "vpc" { + cidr_block = "10.0.0.0/16" + name = "vpc" +} + +resource "tencentcloud_security_group" "example" { + name = "tf-example" + description = "sg desc." + project_id = 0 + + tags = { + "example" = "test" + } +} + +resource "tencentcloud_clb_instance" "example" { network_type = "OPEN" - clb_name = "myclb" + clb_name = "tf-example" project_id = 0 - vpc_id = "vpc-da7ffa61" - security_groups = ["sg-o0ek7r93"] target_region_info_region = "ap-guangzhou" - target_region_info_vpc_id = "vpc-da7ffa61" + security_groups = [tencentcloud_security_group.example.id] + vpc_id = tencentcloud_vpc.vpc.id tags = { - test = "tf" + tagKey = "tagValue" } } ``` -OPNE CLB with VipIsp +OPEN CLB with VipIsp ```hcl +resource "tencentcloud_vpc" "vpc" { + cidr_block = "10.0.0.0/16" + name = "vpc" +} + resource "tencentcloud_vpc_bandwidth_package" "example" { network_type = "SINGLEISP_CMCC" charge_type = "ENHANCED95_POSTPAID_BY_MONTH" @@ -84,17 +142,17 @@ resource "tencentcloud_vpc_bandwidth_package" "example" { } } -resource "tencentcloud_clb_instance" "open_clb" { +resource "tencentcloud_clb_instance" "example" { network_type = "OPEN" - clb_name = "my-open-clb" + clb_name = "tf-example" project_id = 0 - vpc_id = "vpc-4owdpnwr" vip_isp = "CMCC" internet_charge_type = "BANDWIDTH_PACKAGE" bandwidth_package_id = tencentcloud_vpc_bandwidth_package.example.id + vpc_id = tencentcloud_vpc.vpc.id tags = { - test = "open" + tagKey = "tagValue" } } ``` @@ -102,106 +160,107 @@ resource "tencentcloud_clb_instance" "open_clb" { Dynamic Vip Instance ```hcl -resource "tencentcloud_security_group" "foo" { - name = "clb-instance-open-sg" +resource "tencentcloud_vpc" "vpc" { + cidr_block = "10.0.0.0/16" + name = "vpc" } -resource "tencentcloud_vpc" "foo" { - name = "clb-instance-open-vpc" - cidr_block = "10.0.0.0/16" +resource "tencentcloud_security_group" "example" { + name = "tf-example" + description = "sg desc." + project_id = 0 + + tags = { + "example" = "test" + } } -resource "tencentcloud_clb_instance" "clb_open" { +resource "tencentcloud_clb_instance" "example" { network_type = "OPEN" - clb_name = "clb-instance-open" + clb_name = "tf-example" project_id = 0 - vpc_id = tencentcloud_vpc.foo.id + vpc_id = tencentcloud_vpc.vpc.id + target_region_info_vpc_id = tencentcloud_vpc.vpc.id + security_groups = [tencentcloud_security_group.example.id] target_region_info_region = "ap-guangzhou" - target_region_info_vpc_id = tencentcloud_vpc.foo.id - security_groups = [tencentcloud_security_group.foo.id] - - dynamic_vip = true + dynamic_vip = true tags = { - test = "tf" + tagKey = "tagValue" } } output "domain" { - value = tencentcloud_clb_instance.clb_open.domain + value = tencentcloud_clb_instance.example.domain } ``` -Specified Vip Instance +Specified Vip Instance ```hcl -resource "tencentcloud_security_group" "foo" { - name = "clb-instance-open-sg" -} - -resource "tencentcloud_vpc" "foo" { - name = "clb-instance-open-vpc" +resource "tencentcloud_vpc" "vpc" { cidr_block = "10.0.0.0/16" + name = "vpc" } -resource "tencentcloud_clb_instance" "clb_open" { - network_type = "OPEN" - clb_name = "clb-instance-open" - project_id = 0 - vpc_id = tencentcloud_vpc.foo.id - security_groups = [tencentcloud_security_group.foo.id] +resource "tencentcloud_security_group" "example" { + name = "tf-example" + description = "sg desc." + project_id = 0 - vip = "111.230.4.204" + tags = { + "example" = "test" + } +} + +resource "tencentcloud_clb_instance" "example" { + network_type = "OPEN" + clb_name = "tf-example" + project_id = 0 + vpc_id = tencentcloud_vpc.vpc.id + security_groups = [tencentcloud_security_group.example.id] + vip = "111.230.4.204" tags = { - test = "tf" + tagKey = "tagValue" } } output "domain" { - value = tencentcloud_clb_instance.vip + value = tencentcloud_clb_instance.example } ``` Default enable ```hcl -resource "tencentcloud_subnet" "subnet" { - availability_zone = "ap-guangzhou-1" - name = "sdk-feature-test" - vpc_id = tencentcloud_vpc.foo.id - cidr_block = "10.0.20.0/28" - is_multicast = false +resource "tencentcloud_vpc" "vpc" { + cidr_block = "10.0.0.0/16" + name = "vpc" } -resource "tencentcloud_security_group" "sglab" { - name = "sg_o0ek7r93" - description = "favourite sg" +resource "tencentcloud_security_group" "example" { + name = "tf-example" + description = "sg desc." project_id = 0 -} - -resource "tencentcloud_vpc" "foo" { - name = "for-my-open-clb" - cidr_block = "10.0.0.0/16" tags = { - "test" = "mytest" + "example" = "test" } } -resource "tencentcloud_clb_instance" "open_clb" { +resource "tencentcloud_clb_instance" "example" { network_type = "OPEN" - clb_name = "my-open-clb" + clb_name = "tf-example" project_id = 0 - vpc_id = tencentcloud_vpc.foo.id load_balancer_pass_to_target = true - - security_groups = [tencentcloud_security_group.sglab.id] target_region_info_region = "ap-guangzhou" - target_region_info_vpc_id = tencentcloud_vpc.foo.id + vpc_id = tencentcloud_vpc.vpc.id + target_region_info_vpc_id = tencentcloud_vpc.vpc.id + security_groups = [tencentcloud_security_group.example.id] tags = { - test = "open" + tagKey = "tagValue" } } ``` @@ -209,57 +268,57 @@ resource "tencentcloud_clb_instance" "open_clb" { CREATE multiple instance ```hcl -resource "tencentcloud_clb_instance" "open_clb1" { - network_type = "OPEN" - clb_name = "hello" +resource "tencentcloud_clb_instance" "example" { + network_type = "OPEN" + clb_name = "tf-example" master_zone_id = "ap-guangzhou-3" } ``` -CREATE instance with log +Create instance with log + ```hcl -resource "tencentcloud_vpc" "vpc_test" { - name = "clb-test" +resource "tencentcloud_vpc" "vpc" { cidr_block = "10.0.0.0/16" + name = "vpc" } -resource "tencentcloud_route_table" "rtb_test" { - name = "clb-test" - vpc_id = "${tencentcloud_vpc.vpc_test.id}" +resource "tencentcloud_route_table" "example" { + name = "tf-example" + vpc_id = tencentcloud_vpc.vpc.id } -resource "tencentcloud_subnet" "subnet_test" { - name = "clb-test" - cidr_block = "10.0.1.0/24" - availability_zone = "ap-guangzhou-3" - vpc_id = "${tencentcloud_vpc.vpc_test.id}" - route_table_id = "${tencentcloud_route_table.rtb_test.id}" +resource "tencentcloud_subnet" "subnet" { + vpc_id = tencentcloud_vpc.vpc.id + route_table_id = tencentcloud_route_table.example.id + availability_zone = "ap-guangzhou-4" + name = "subnet" + cidr_block = "10.0.1.0/24" } -resource "tencentcloud_clb_log_set" "set" { +resource "tencentcloud_clb_log_set" "example" { period = 7 } -resource "tencentcloud_clb_log_topic" "topic" { - log_set_id = "${tencentcloud_clb_log_set.set.id}" +resource "tencentcloud_clb_log_topic" "example" { + log_set_id = tencentcloud_clb_log_set.example.id topic_name = "clb-topic" } -resource "tencentcloud_clb_instance" "internal_clb" { - network_type = "INTERNAL" - clb_name = "myclb" - project_id = 0 - vpc_id = "${tencentcloud_vpc.vpc_test.id}" - subnet_id = "${tencentcloud_subnet.subnet_test.id}" +resource "tencentcloud_clb_instance" "example" { + network_type = "INTERNAL" + clb_name = "tf-example" + project_id = 0 + vpc_id = tencentcloud_vpc.vpc.id + subnet_id = tencentcloud_subnet.subnet.id + log_set_id = tencentcloud_clb_log_set.example.id + log_topic_id = tencentcloud_clb_log_topic.example.id load_balancer_pass_to_target = true - log_set_id = "${tencentcloud_clb_log_set.set.id}" - log_topic_id = "${tencentcloud_clb_log_topic.topic.id}" tags = { - test = "tf" + tagKey = "tagValue" } } - ``` Import @@ -267,5 +326,5 @@ Import CLB instance can be imported using the id, e.g. ``` -$ terraform import tencentcloud_clb_instance.foo lb-7a0t6zqb -``` \ No newline at end of file +$ terraform import tencentcloud_clb_instance.example lb-7a0t6zqb +``` diff --git a/website/docs/r/clb_instance.html.markdown b/website/docs/r/clb_instance.html.markdown index a19dec78e9..8e34d4ed2f 100644 --- a/website/docs/r/clb_instance.html.markdown +++ b/website/docs/r/clb_instance.html.markdown @@ -16,15 +16,27 @@ Provides a resource to create a CLB instance. ### INTERNAL CLB ```hcl -resource "tencentcloud_clb_instance" "internal_clb" { +resource "tencentcloud_vpc" "vpc" { + cidr_block = "10.0.0.0/16" + name = "vpc" +} + +resource "tencentcloud_subnet" "subnet" { + vpc_id = tencentcloud_vpc.vpc.id + availability_zone = "ap-guangzhou-4" + name = "subnet" + cidr_block = "10.0.1.0/24" +} + +resource "tencentcloud_clb_instance" "example" { network_type = "INTERNAL" - clb_name = "myclb" + clb_name = "tf-example" project_id = 0 - vpc_id = "vpc-7007ll7q" - subnet_id = "subnet-12rastkr" + vpc_id = tencentcloud_vpc.vpc.id + subnet_id = tencentcloud_subnet.subnet.id tags = { - test = "tf" + tagKey = "tagValue" } } ``` @@ -32,16 +44,28 @@ resource "tencentcloud_clb_instance" "internal_clb" { ### LCU-supported CLB ```hcl -resource "tencentcloud_clb_instance" "internal_clb" { +resource "tencentcloud_vpc" "vpc" { + cidr_block = "10.0.0.0/16" + name = "vpc" +} + +resource "tencentcloud_subnet" "subnet" { + vpc_id = tencentcloud_vpc.vpc.id + availability_zone = "ap-guangzhou-4" + name = "subnet" + cidr_block = "10.0.1.0/24" +} + +resource "tencentcloud_clb_instance" "example" { network_type = "INTERNAL" - clb_name = "myclb" + clb_name = "tf-example" project_id = 0 sla_type = "clb.c3.medium" - vpc_id = "vpc-2hfyray3" - subnet_id = "subnet-o3a5nt20" + vpc_id = tencentcloud_vpc.vpc.id + subnet_id = tencentcloud_subnet.subnet.id tags = { - test = "tf" + tagKey = "tagValue" } } ``` @@ -49,40 +73,74 @@ resource "tencentcloud_clb_instance" "internal_clb" { ### OPEN CLB ```hcl -resource "tencentcloud_clb_instance" "open_clb" { +resource "tencentcloud_vpc" "vpc" { + cidr_block = "10.0.0.0/16" + name = "vpc" +} + +resource "tencentcloud_security_group" "example" { + name = "tf-example" + description = "sg desc." + project_id = 0 + + tags = { + "example" = "test" + } +} + +resource "tencentcloud_clb_instance" "example" { network_type = "OPEN" - clb_name = "myclb" + clb_name = "tf-example" project_id = 0 - vpc_id = "vpc-da7ffa61" - security_groups = ["sg-o0ek7r93"] + vpc_id = tencentcloud_vpc.vpc.id + security_groups = [tencentcloud_security_group.example.id] tags = { - test = "tf" + tagKey = "tagValue" } } ``` -### SUPPORT CORS +### Support CORS ```hcl -resource "tencentcloud_clb_instance" "open_clb" { +resource "tencentcloud_vpc" "vpc" { + cidr_block = "10.0.0.0/16" + name = "vpc" +} + +resource "tencentcloud_security_group" "example" { + name = "tf-example" + description = "sg desc." + project_id = 0 + + tags = { + "example" = "test" + } +} + +resource "tencentcloud_clb_instance" "example" { network_type = "OPEN" - clb_name = "myclb" + clb_name = "tf-example" project_id = 0 - vpc_id = "vpc-da7ffa61" - security_groups = ["sg-o0ek7r93"] target_region_info_region = "ap-guangzhou" - target_region_info_vpc_id = "vpc-da7ffa61" + security_groups = [tencentcloud_security_group.example.id] + vpc_id = tencentcloud_vpc.vpc.id tags = { - test = "tf" + tagKey = "tagValue" } } ``` -### OPNE CLB with VipIsp +### OPEN CLB with VipIsp ```hcl +resource "tencentcloud_vpc" "vpc" { + cidr_block = "10.0.0.0/16" + name = "vpc" +} + resource "tencentcloud_vpc_bandwidth_package" "example" { network_type = "SINGLEISP_CMCC" charge_type = "ENHANCED95_POSTPAID_BY_MONTH" @@ -95,17 +153,17 @@ resource "tencentcloud_vpc_bandwidth_package" "example" { } } -resource "tencentcloud_clb_instance" "open_clb" { +resource "tencentcloud_clb_instance" "example" { network_type = "OPEN" - clb_name = "my-open-clb" + clb_name = "tf-example" project_id = 0 - vpc_id = "vpc-4owdpnwr" vip_isp = "CMCC" internet_charge_type = "BANDWIDTH_PACKAGE" bandwidth_package_id = tencentcloud_vpc_bandwidth_package.example.id + vpc_id = tencentcloud_vpc.vpc.id tags = { - test = "open" + tagKey = "tagValue" } } ``` @@ -113,106 +171,107 @@ resource "tencentcloud_clb_instance" "open_clb" { ### Dynamic Vip Instance ```hcl -resource "tencentcloud_security_group" "foo" { - name = "clb-instance-open-sg" +resource "tencentcloud_vpc" "vpc" { + cidr_block = "10.0.0.0/16" + name = "vpc" } -resource "tencentcloud_vpc" "foo" { - name = "clb-instance-open-vpc" - cidr_block = "10.0.0.0/16" +resource "tencentcloud_security_group" "example" { + name = "tf-example" + description = "sg desc." + project_id = 0 + + tags = { + "example" = "test" + } } -resource "tencentcloud_clb_instance" "clb_open" { +resource "tencentcloud_clb_instance" "example" { network_type = "OPEN" - clb_name = "clb-instance-open" + clb_name = "tf-example" project_id = 0 - vpc_id = tencentcloud_vpc.foo.id + vpc_id = tencentcloud_vpc.vpc.id + target_region_info_vpc_id = tencentcloud_vpc.vpc.id + security_groups = [tencentcloud_security_group.example.id] target_region_info_region = "ap-guangzhou" - target_region_info_vpc_id = tencentcloud_vpc.foo.id - security_groups = [tencentcloud_security_group.foo.id] - - dynamic_vip = true + dynamic_vip = true tags = { - test = "tf" + tagKey = "tagValue" } } output "domain" { - value = tencentcloud_clb_instance.clb_open.domain + value = tencentcloud_clb_instance.example.domain } ``` -### Specified Vip Instance +### Specified Vip Instance ```hcl -resource "tencentcloud_security_group" "foo" { - name = "clb-instance-open-sg" +resource "tencentcloud_vpc" "vpc" { + cidr_block = "10.0.0.0/16" + name = "vpc" } -resource "tencentcloud_vpc" "foo" { - name = "clb-instance-open-vpc" - cidr_block = "10.0.0.0/16" +resource "tencentcloud_security_group" "example" { + name = "tf-example" + description = "sg desc." + project_id = 0 + + tags = { + "example" = "test" + } } -resource "tencentcloud_clb_instance" "clb_open" { +resource "tencentcloud_clb_instance" "example" { network_type = "OPEN" - clb_name = "clb-instance-open" + clb_name = "tf-example" project_id = 0 - vpc_id = tencentcloud_vpc.foo.id - security_groups = [tencentcloud_security_group.foo.id] - - vip = "111.230.4.204" + vpc_id = tencentcloud_vpc.vpc.id + security_groups = [tencentcloud_security_group.example.id] + vip = "111.230.4.204" tags = { - test = "tf" + tagKey = "tagValue" } } output "domain" { - value = tencentcloud_clb_instance.vip + value = tencentcloud_clb_instance.example } ``` ### Default enable ```hcl -resource "tencentcloud_subnet" "subnet" { - availability_zone = "ap-guangzhou-1" - name = "sdk-feature-test" - vpc_id = tencentcloud_vpc.foo.id - cidr_block = "10.0.20.0/28" - is_multicast = false +resource "tencentcloud_vpc" "vpc" { + cidr_block = "10.0.0.0/16" + name = "vpc" } -resource "tencentcloud_security_group" "sglab" { - name = "sg_o0ek7r93" - description = "favourite sg" +resource "tencentcloud_security_group" "example" { + name = "tf-example" + description = "sg desc." project_id = 0 -} - -resource "tencentcloud_vpc" "foo" { - name = "for-my-open-clb" - cidr_block = "10.0.0.0/16" tags = { - "test" = "mytest" + "example" = "test" } } -resource "tencentcloud_clb_instance" "open_clb" { +resource "tencentcloud_clb_instance" "example" { network_type = "OPEN" - clb_name = "my-open-clb" + clb_name = "tf-example" project_id = 0 - vpc_id = tencentcloud_vpc.foo.id load_balancer_pass_to_target = true - - security_groups = [tencentcloud_security_group.sglab.id] - target_region_info_region = "ap-guangzhou" - target_region_info_vpc_id = tencentcloud_vpc.foo.id + target_region_info_region = "ap-guangzhou" + vpc_id = tencentcloud_vpc.vpc.id + target_region_info_vpc_id = tencentcloud_vpc.vpc.id + security_groups = [tencentcloud_security_group.example.id] tags = { - test = "open" + tagKey = "tagValue" } } ``` @@ -220,55 +279,55 @@ resource "tencentcloud_clb_instance" "open_clb" { ### CREATE multiple instance ```hcl -resource "tencentcloud_clb_instance" "open_clb1" { +resource "tencentcloud_clb_instance" "example" { network_type = "OPEN" - clb_name = "hello" + clb_name = "tf-example" master_zone_id = "ap-guangzhou-3" } ``` -### CREATE instance with log +### Create instance with log ```hcl -resource "tencentcloud_vpc" "vpc_test" { - name = "clb-test" +resource "tencentcloud_vpc" "vpc" { cidr_block = "10.0.0.0/16" + name = "vpc" } -resource "tencentcloud_route_table" "rtb_test" { - name = "clb-test" - vpc_id = "${tencentcloud_vpc.vpc_test.id}" +resource "tencentcloud_route_table" "example" { + name = "tf-example" + vpc_id = tencentcloud_vpc.vpc.id } -resource "tencentcloud_subnet" "subnet_test" { - name = "clb-test" +resource "tencentcloud_subnet" "subnet" { + vpc_id = tencentcloud_vpc.vpc.id + route_table_id = tencentcloud_route_table.example.id + availability_zone = "ap-guangzhou-4" + name = "subnet" cidr_block = "10.0.1.0/24" - availability_zone = "ap-guangzhou-3" - vpc_id = "${tencentcloud_vpc.vpc_test.id}" - route_table_id = "${tencentcloud_route_table.rtb_test.id}" } -resource "tencentcloud_clb_log_set" "set" { +resource "tencentcloud_clb_log_set" "example" { period = 7 } -resource "tencentcloud_clb_log_topic" "topic" { - log_set_id = "${tencentcloud_clb_log_set.set.id}" +resource "tencentcloud_clb_log_topic" "example" { + log_set_id = tencentcloud_clb_log_set.example.id topic_name = "clb-topic" } -resource "tencentcloud_clb_instance" "internal_clb" { +resource "tencentcloud_clb_instance" "example" { network_type = "INTERNAL" - clb_name = "myclb" + clb_name = "tf-example" project_id = 0 - vpc_id = "${tencentcloud_vpc.vpc_test.id}" - subnet_id = "${tencentcloud_subnet.subnet_test.id}" + vpc_id = tencentcloud_vpc.vpc.id + subnet_id = tencentcloud_subnet.subnet.id + log_set_id = tencentcloud_clb_log_set.example.id + log_topic_id = tencentcloud_clb_log_topic.example.id load_balancer_pass_to_target = true - log_set_id = "${tencentcloud_clb_log_set.set.id}" - log_topic_id = "${tencentcloud_clb_log_topic.topic.id}" tags = { - test = "tf" + tagKey = "tagValue" } } ``` @@ -325,6 +384,6 @@ In addition to all arguments above, the following attributes are exported: CLB instance can be imported using the id, e.g. ``` -$ terraform import tencentcloud_clb_instance.foo lb-7a0t6zqb +$ terraform import tencentcloud_clb_instance.example lb-7a0t6zqb ``` From 27ad81e61b2d579b99c29340aa4c93654ac414b3 Mon Sep 17 00:00:00 2001 From: SevenEarth <391613297@qq.com> Date: Thu, 4 Jul 2024 16:24:12 +0800 Subject: [PATCH 2/4] fix/clb_projectId --- .../services/clb/resource_tc_clb_instance.go | 41 ++++++++++++++++--- website/docs/r/clb_instance.html.markdown | 2 +- 2 files changed, 37 insertions(+), 6 deletions(-) diff --git a/tencentcloud/services/clb/resource_tc_clb_instance.go b/tencentcloud/services/clb/resource_tc_clb_instance.go index 7f38549f44..6ea7700b4e 100644 --- a/tencentcloud/services/clb/resource_tc_clb_instance.go +++ b/tencentcloud/services/clb/resource_tc_clb_instance.go @@ -52,7 +52,6 @@ func ResourceTencentCloudClbInstance() *schema.Resource { "project_id": { Type: schema.TypeInt, Optional: true, - ForceNew: true, Default: 0, Description: "ID of the project within the CLB instance, `0` - Default Project.", }, @@ -280,7 +279,7 @@ func resourceTencentCloudClbInstanceCreate(d *schema.ResourceData, meta interfac request.VpcId = helper.String(v.(string)) } - if v, ok := d.GetOk("project_id"); ok { + if v, ok := d.GetOkExists("project_id"); ok { projectId := int64(v.(int)) request.ProjectId = &projectId } @@ -317,7 +316,7 @@ func resourceTencentCloudClbInstanceCreate(d *schema.ResourceData, meta interfac request.AddressIPVersion = helper.String(v.(string)) } - if v, ok := d.GetOk("snat_pro"); ok { + if v, ok := d.GetOkExists("snat_pro"); ok { request.SnatPro = helper.Bool(v.(bool)) } @@ -391,7 +390,7 @@ func resourceTencentCloudClbInstanceCreate(d *schema.ResourceData, meta interfac request.SlaveZoneId = helper.String(v.(string)) } - if v, ok := d.GetOk("load_balancer_pass_to_target"); ok { + if v, ok := d.GetOkExists("load_balancer_pass_to_target"); ok { request.LoadBalancerPassToTarget = helper.Bool(v.(bool)) } @@ -688,7 +687,7 @@ func resourceTencentCloudClbInstanceUpdate(d *schema.ResourceData, meta interfac clbId = d.Id() ) - immutableArgs := []string{"snat_ips", "dynamic_vip", "master_zone_id", "slave_zone_id", "project_id", "vpc_id", "subnet_id", "address_ip_version", "bandwidth_package_id", "zone_id"} + immutableArgs := []string{"snat_ips", "dynamic_vip", "master_zone_id", "slave_zone_id", "vpc_id", "subnet_id", "address_ip_version", "bandwidth_package_id", "zone_id"} for _, v := range immutableArgs { if d.HasChange(v) { @@ -894,6 +893,38 @@ func resourceTencentCloudClbInstanceUpdate(d *schema.ResourceData, meta interfac } } + if d.HasChange("project_id") { + var projectId int + if v, ok := d.GetOkExists("project_id"); ok { + projectId = v.(int) + } + + pRequest := clb.NewModifyLoadBalancersProjectRequest() + pRequest.LoadBalancerIds = []*string{&clbId} + pRequest.ProjectId = helper.IntUint64(projectId) + err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError { + pResponse, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseClbClient().ModifyLoadBalancersProject(pRequest) + if e != nil { + return tccommon.RetryError(e) + } else { + log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", + logId, pRequest.GetAction(), pRequest.ToJsonString(), pResponse.ToJsonString()) + requestId := *pResponse.Response.RequestId + retryErr := waitForTaskFinish(requestId, meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseClbClient()) + if retryErr != nil { + return tccommon.RetryError(errors.WithStack(retryErr)) + } + } + + return nil + }) + + if err != nil { + log.Printf("[CRITAL]%s update CLB instance project_id failed, reason:%+v", logId, err) + return err + } + } + if d.HasChange("tags") { oldValue, newValue := d.GetChange("tags") replaceTags, deleteTags := svctag.DiffTags(oldValue.(map[string]interface{}), newValue.(map[string]interface{})) diff --git a/website/docs/r/clb_instance.html.markdown b/website/docs/r/clb_instance.html.markdown index 8e34d4ed2f..84c89737d3 100644 --- a/website/docs/r/clb_instance.html.markdown +++ b/website/docs/r/clb_instance.html.markdown @@ -348,7 +348,7 @@ The following arguments are supported: * `log_set_id` - (Optional, String) The id of log set. * `log_topic_id` - (Optional, String) The id of log topic. * `master_zone_id` - (Optional, String) Setting master zone id of cross available zone disaster recovery, only applicable to open CLB. -* `project_id` - (Optional, Int, ForceNew) ID of the project within the CLB instance, `0` - Default Project. +* `project_id` - (Optional, Int) ID of the project within the CLB instance, `0` - Default Project. * `security_groups` - (Optional, List: [`String`]) Security groups of the CLB instance. Supports both `OPEN` and `INTERNAL` CLBs. * `sla_type` - (Optional, String) This parameter is required to create LCU-supported instances. Values:`SLA`: Super Large 4. When you have activated Super Large models, `SLA` refers to Super Large 4; `clb.c2.medium`: Standard; `clb.c3.small`: Advanced 1; `clb.c3.medium`: Advanced 1; `clb.c4.small`: Super Large 1; `clb.c4.medium`: Super Large 2; `clb.c4.large`: Super Large 3; `clb.c4.xlarge`: Super Large 4. For more details, see [Instance Specifications](https://intl.cloud.tencent.com/document/product/214/84689?from_cn_redirect=1). * `slave_zone_id` - (Optional, String) Setting slave zone id of cross available zone disaster recovery, only applicable to open CLB. this zone will undertake traffic when the master is down. From f7c3afb656f40088c3f7a7cef6e7f7b1e5b91d1a Mon Sep 17 00:00:00 2001 From: SevenEarth <391613297@qq.com> Date: Thu, 4 Jul 2024 16:26:37 +0800 Subject: [PATCH 3/4] fix/clb_projectId --- .changelog/2705.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/2705.txt diff --git a/.changelog/2705.txt b/.changelog/2705.txt new file mode 100644 index 0000000000..de8aaf4077 --- /dev/null +++ b/.changelog/2705.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +resource/tencentcloud_clb_instance: support update `project_id` params. +``` From 9b245e01952c6d63c3928f11c4d0ab2f9be56c6d Mon Sep 17 00:00:00 2001 From: SevenEarth <391613297@qq.com> Date: Fri, 5 Jul 2024 21:08:26 +0800 Subject: [PATCH 4/4] add --- .../services/clb/resource_tc_clb_instance.go | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/tencentcloud/services/clb/resource_tc_clb_instance.go b/tencentcloud/services/clb/resource_tc_clb_instance.go index 6ea7700b4e..0ce66ea550 100644 --- a/tencentcloud/services/clb/resource_tc_clb_instance.go +++ b/tencentcloud/services/clb/resource_tc_clb_instance.go @@ -180,18 +180,16 @@ func ResourceTencentCloudClbInstance() *schema.Resource { Description: "Whether the target allow flow come from clb. If value is true, only check security group of clb, or check both clb and backend instance security group.", }, "master_zone_id": { - Type: schema.TypeString, - Optional: true, - Computed: true, - ConflictsWith: []string{"zone_id"}, - Description: "Setting master zone id of cross available zone disaster recovery, only applicable to open CLB.", + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: "Setting master zone id of cross available zone disaster recovery, only applicable to open CLB.", }, "zone_id": { - Type: schema.TypeString, - Optional: true, - Computed: true, - ConflictsWith: []string{"master_zone_id"}, - Description: "Available zone id, only applicable to open CLB.", + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: "Available zone id, only applicable to open CLB.", }, "slave_zone_id": { Type: schema.TypeString,