Skip to content

Commit 27ad81e

Browse files
committed
fix/clb_projectId
1 parent a8c49cb commit 27ad81e

File tree

2 files changed

+37
-6
lines changed

2 files changed

+37
-6
lines changed

tencentcloud/services/clb/resource_tc_clb_instance.go

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ func ResourceTencentCloudClbInstance() *schema.Resource {
5252
"project_id": {
5353
Type: schema.TypeInt,
5454
Optional: true,
55-
ForceNew: true,
5655
Default: 0,
5756
Description: "ID of the project within the CLB instance, `0` - Default Project.",
5857
},
@@ -280,7 +279,7 @@ func resourceTencentCloudClbInstanceCreate(d *schema.ResourceData, meta interfac
280279
request.VpcId = helper.String(v.(string))
281280
}
282281

283-
if v, ok := d.GetOk("project_id"); ok {
282+
if v, ok := d.GetOkExists("project_id"); ok {
284283
projectId := int64(v.(int))
285284
request.ProjectId = &projectId
286285
}
@@ -317,7 +316,7 @@ func resourceTencentCloudClbInstanceCreate(d *schema.ResourceData, meta interfac
317316
request.AddressIPVersion = helper.String(v.(string))
318317
}
319318

320-
if v, ok := d.GetOk("snat_pro"); ok {
319+
if v, ok := d.GetOkExists("snat_pro"); ok {
321320
request.SnatPro = helper.Bool(v.(bool))
322321
}
323322

@@ -391,7 +390,7 @@ func resourceTencentCloudClbInstanceCreate(d *schema.ResourceData, meta interfac
391390
request.SlaveZoneId = helper.String(v.(string))
392391
}
393392

394-
if v, ok := d.GetOk("load_balancer_pass_to_target"); ok {
393+
if v, ok := d.GetOkExists("load_balancer_pass_to_target"); ok {
395394
request.LoadBalancerPassToTarget = helper.Bool(v.(bool))
396395
}
397396

@@ -688,7 +687,7 @@ func resourceTencentCloudClbInstanceUpdate(d *schema.ResourceData, meta interfac
688687
clbId = d.Id()
689688
)
690689

691-
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"}
690+
immutableArgs := []string{"snat_ips", "dynamic_vip", "master_zone_id", "slave_zone_id", "vpc_id", "subnet_id", "address_ip_version", "bandwidth_package_id", "zone_id"}
692691

693692
for _, v := range immutableArgs {
694693
if d.HasChange(v) {
@@ -894,6 +893,38 @@ func resourceTencentCloudClbInstanceUpdate(d *schema.ResourceData, meta interfac
894893
}
895894
}
896895

896+
if d.HasChange("project_id") {
897+
var projectId int
898+
if v, ok := d.GetOkExists("project_id"); ok {
899+
projectId = v.(int)
900+
}
901+
902+
pRequest := clb.NewModifyLoadBalancersProjectRequest()
903+
pRequest.LoadBalancerIds = []*string{&clbId}
904+
pRequest.ProjectId = helper.IntUint64(projectId)
905+
err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError {
906+
pResponse, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseClbClient().ModifyLoadBalancersProject(pRequest)
907+
if e != nil {
908+
return tccommon.RetryError(e)
909+
} else {
910+
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n",
911+
logId, pRequest.GetAction(), pRequest.ToJsonString(), pResponse.ToJsonString())
912+
requestId := *pResponse.Response.RequestId
913+
retryErr := waitForTaskFinish(requestId, meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseClbClient())
914+
if retryErr != nil {
915+
return tccommon.RetryError(errors.WithStack(retryErr))
916+
}
917+
}
918+
919+
return nil
920+
})
921+
922+
if err != nil {
923+
log.Printf("[CRITAL]%s update CLB instance project_id failed, reason:%+v", logId, err)
924+
return err
925+
}
926+
}
927+
897928
if d.HasChange("tags") {
898929
oldValue, newValue := d.GetChange("tags")
899930
replaceTags, deleteTags := svctag.DiffTags(oldValue.(map[string]interface{}), newValue.(map[string]interface{}))

website/docs/r/clb_instance.html.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ The following arguments are supported:
348348
* `log_set_id` - (Optional, String) The id of log set.
349349
* `log_topic_id` - (Optional, String) The id of log topic.
350350
* `master_zone_id` - (Optional, String) Setting master zone id of cross available zone disaster recovery, only applicable to open CLB.
351-
* `project_id` - (Optional, Int, ForceNew) ID of the project within the CLB instance, `0` - Default Project.
351+
* `project_id` - (Optional, Int) ID of the project within the CLB instance, `0` - Default Project.
352352
* `security_groups` - (Optional, List: [`String`]) Security groups of the CLB instance. Supports both `OPEN` and `INTERNAL` CLBs.
353353
* `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).
354354
* `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.

0 commit comments

Comments
 (0)