From 97a051aefac154727d9ce335cc0b007fce23d696 Mon Sep 17 00:00:00 2001 From: Wmxs <54929266+WeiMengXS@users.noreply.github.com> Date: Wed, 3 Jan 2024 20:47:07 +0800 Subject: [PATCH 1/5] feat: support target attach clb --- tencentcloud/provider.md | 1 + ...esource_tc_clb_target_group_attachments.go | 260 ++++++++++++------ ...esource_tc_clb_target_group_attachments.md | 1 - ...ce_tc_clb_target_group_attachments_test.go | 174 +++++++++++- .../services/clb/service_tencentcloud_clb.go | 5 +- ...clb_target_group_attachments.html.markdown | 49 ++++ website/tencentcloud.erb | 3 + 7 files changed, 402 insertions(+), 91 deletions(-) create mode 100644 website/docs/r/clb_target_group_attachments.html.markdown diff --git a/tencentcloud/provider.md b/tencentcloud/provider.md index 7fe5483ce1..4fbbd1d90f 100644 --- a/tencentcloud/provider.md +++ b/tencentcloud/provider.md @@ -383,6 +383,7 @@ Cloud Load Balancer(CLB) tencentcloud_clb_target_group tencentcloud_clb_target_group_instance_attachment tencentcloud_clb_target_group_attachment + tencentcloud_clb_target_group_attachments tencentcloud_clb_log_set tencentcloud_clb_log_topic tencentcloud_clb_customized_config diff --git a/tencentcloud/services/clb/resource_tc_clb_target_group_attachments.go b/tencentcloud/services/clb/resource_tc_clb_target_group_attachments.go index 77eda5098e..deecfc3793 100644 --- a/tencentcloud/services/clb/resource_tc_clb_target_group_attachments.go +++ b/tencentcloud/services/clb/resource_tc_clb_target_group_attachments.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "log" + "regexp" "strings" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" @@ -25,34 +26,44 @@ func ResourceTencentCloudClbTargetGroupAttachments() *schema.Resource { Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, }, + Schema: map[string]*schema.Schema{ "load_balancer_id": { Type: schema.TypeString, - Required: true, - Description: "CLB instance ID", + Optional: true, + Description: "CLB instance ID, (load_balancer_id and target_group_id require at least one).", + }, + "target_group_id": { + Type: schema.TypeString, + Optional: true, + Description: "Target group ID, (load_balancer_id and target_group_id require at least one).", }, "associations": { Required: true, Type: schema.TypeSet, MaxItems: 20, - Description: "Association array, the combination cannot exceed 20", + Description: "Association array, the combination cannot exceed 20.", Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - - "listener_id": { + "load_balancer_id": { Type: schema.TypeString, Optional: true, - Description: "Listener ID", + Description: "CLB instance ID, when the binding target is clb, the target_group_id in associations is required.", }, "target_group_id": { Type: schema.TypeString, - Required: true, - Description: "Target group ID", + Optional: true, + Description: "Target group ID, when the binding target is target group, load_balancer_id in associations is required.", + }, + "listener_id": { + Type: schema.TypeString, + Optional: true, + Description: "Listener ID.", }, "location_id": { Type: schema.TypeString, Optional: true, - Description: "Forwarding rule ID", + Description: "Forwarding rule ID.", }, }, }, @@ -61,36 +72,73 @@ func ResourceTencentCloudClbTargetGroupAttachments() *schema.Resource { } } -func resourceTencentCloudClbTargetGroupAttachmentsCreate(d *schema.ResourceData, meta interface{}) error { - defer tccommon.LogElapsed("resource.tencentcloud_clb_target_group_attachments.create")() - defer tccommon.InconsistentCheck(d, meta)() +const ResourcePrefixFromClb = "lb" - logId := tccommon.GetLogId(tccommon.ContextNil) +func checkParam(d *schema.ResourceData) error { + _, clbIdExists := d.GetOk("load_balancer_id") + _, groupIdExists := d.GetOk("target_group_id") - var ( - request = clb.NewAssociateTargetGroupsRequest() - loadBalancerId string - ) - if v, ok := d.GetOk("load_balancer_id"); ok { - loadBalancerId = v.(string) + if !clbIdExists && !groupIdExists { + return fmt.Errorf("one of load_balancer_id and target_group_id must be specified as the binding target") } + + if clbIdExists && groupIdExists { + return fmt.Errorf("load_balancer_id and target_group_id cannot be used as binding targets at the same time") + } + if v, ok := d.GetOk("associations"); ok { for _, item := range v.(*schema.Set).List() { dMap := item.(map[string]interface{}) - targetGroupAssociation := clb.TargetGroupAssociation{} - targetGroupAssociation.LoadBalancerId = helper.String(loadBalancerId) - if v, ok := dMap["listener_id"]; ok { - targetGroupAssociation.ListenerId = helper.String(v.(string)) + associationsClbExists := false + associationsGroupExists := false + + if v, ok := dMap["load_balancer_id"]; ok && v.(string) != "" { + associationsClbExists = true + } + if v, ok := dMap["target_group_id"]; ok && v.(string) != "" { + associationsGroupExists = true } - if v, ok := dMap["target_group_id"]; ok { - targetGroupAssociation.TargetGroupId = helper.String(v.(string)) + + if !associationsClbExists && !associationsGroupExists { + return fmt.Errorf("then in associations, load_balancer_id and target_group_id must be filled in one") + } + + if clbIdExists && associationsClbExists { + return fmt.Errorf("if the binding target is clb, then in associations, it is expected that " + + "target_group_id exists and load_balancer_id does not exist") } - if v, ok := dMap["location_id"]; ok { - targetGroupAssociation.LocationId = helper.String(v.(string)) + + if groupIdExists && associationsGroupExists { + return fmt.Errorf("if the binding target is targetGroup, then in associations, it is expected that " + + "load_balancer_id exists and target_group_id does not exist") } - request.Associations = append(request.Associations, &targetGroupAssociation) } } + return nil +} +func resourceTencentCloudClbTargetGroupAttachmentsCreate(d *schema.ResourceData, meta interface{}) error { + defer tccommon.LogElapsed("resource.tencentcloud_clb_target_group_attachments.create")() + defer tccommon.InconsistentCheck(d, meta)() + + logId := tccommon.GetLogId(tccommon.ContextNil) + if err := checkParam(d); err != nil { + return err + } + var ( + request = clb.NewAssociateTargetGroupsRequest() + resourceId string + ) + if v, ok := d.GetOk("load_balancer_id"); ok && v.(string) != "" { + resourceId = v.(string) + request.Associations = parseParamToRequest(d, "load_balancer_id", resourceId) + } + + if v, ok := d.GetOk("target_group_id"); ok && v.(string) != "" { + resourceId = v.(string) + request.Associations = parseParamToRequest(d, "target_group_id", resourceId) + } + fmt.Println(1222222) + fmt.Println(resourceId) err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError { result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseClbClient().AssociateTargetGroups(request) @@ -112,7 +160,7 @@ func resourceTencentCloudClbTargetGroupAttachmentsCreate(d *schema.ResourceData, return err } - d.SetId(loadBalancerId) + d.SetId(resourceId) return resourceTencentCloudClbTargetGroupAttachmentsRead(d, meta) } @@ -127,42 +175,17 @@ func resourceTencentCloudClbTargetGroupAttachmentsRead(d *schema.ResourceData, m service := ClbService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()} - loadBalancerId := d.Id() - associationsSet := make(map[string]struct{}, 0) - targetGroupList := make([]string, 0) - if v, ok := d.GetOk("associations"); ok { - for _, item := range v.(*schema.Set).List() { - dMap := item.(map[string]interface{}) - ids := make([]string, 0) - - ids = append(ids, loadBalancerId) - if v, ok := dMap["listener_id"]; ok { - ids = append(ids, v.(string)) - } else { - ids = append(ids, "null") - } - - if v, ok := dMap["target_group_id"]; ok { - ids = append(ids, v.(string)) - targetGroupList = append(targetGroupList, v.(string)) - } else { - ids = append(ids, "null") - } - - if v, ok := dMap["location_id"]; ok { - ids = append(ids, v.(string)) - } else { - ids = append(ids, "null") - } - - associationsSet[strings.Join(ids, tccommon.FILED_SP)] = struct{}{} - } - } - + targetGroupList, associationsSet := margeReadRequest(d) targetGroupAttachments, err := service.DescribeClbTargetGroupAttachmentsById(ctx, targetGroupList, associationsSet) if err != nil { return err } + fmt.Println(111111111) + fmt.Println(111111111) + + fmt.Println(targetGroupList) + fmt.Println(associationsSet) + fmt.Println(targetGroupAttachments) if len(targetGroupAttachments) < 1 { d.SetId("") @@ -177,12 +200,16 @@ func resourceTencentCloudClbTargetGroupAttachmentsRead(d *schema.ResourceData, m return fmt.Errorf("id is broken,%s", info) } associationsMap := map[string]interface{}{} - _ = d.Set("load_balancer_id", info[0]) - - associationsMap["listener_id"] = info[1] + if isBindFromClb(d.Id()) { + _ = d.Set("load_balancer_id", info[0]) + associationsMap["target_group_id"] = info[1] - associationsMap["target_group_id"] = info[2] + } else { + _ = d.Set("target_group_id", info[1]) + associationsMap["load_balancer_id"] = info[0] + } + associationsMap["listener_id"] = info[2] associationsMap["location_id"] = info[3] associationsList = append(associationsList, associationsMap) @@ -206,24 +233,11 @@ func resourceTencentCloudClbTargetGroupAttachmentsDelete(d *schema.ResourceData, logId := tccommon.GetLogId(tccommon.ContextNil) request := clb.NewDisassociateTargetGroupsRequest() - - loadBalancerId := d.Id() - if v, ok := d.GetOk("associations"); ok { - for _, item := range v.(*schema.Set).List() { - dMap := item.(map[string]interface{}) - targetGroupAssociation := clb.TargetGroupAssociation{} - targetGroupAssociation.LoadBalancerId = helper.String(loadBalancerId) - if v, ok := dMap["listener_id"]; ok { - targetGroupAssociation.ListenerId = helper.String(v.(string)) - } - if v, ok := dMap["target_group_id"]; ok { - targetGroupAssociation.TargetGroupId = helper.String(v.(string)) - } - if v, ok := dMap["location_id"]; ok { - targetGroupAssociation.LocationId = helper.String(v.(string)) - } - request.Associations = append(request.Associations, &targetGroupAssociation) - } + id := d.Id() + if isBindFromClb(id) { + request.Associations = parseParamToRequest(d, "load_balancer_id", id) + } else { + request.Associations = parseParamToRequest(d, "target_group_id", id) } err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError { ratelimit.Check(request.GetAction()) @@ -248,3 +262,83 @@ func resourceTencentCloudClbTargetGroupAttachmentsDelete(d *schema.ResourceData, return nil } +func parseParamToRequest(d *schema.ResourceData, param string, id string) (associations []*clb.TargetGroupAssociation) { + + if v, ok := d.GetOk("associations"); ok { + for _, item := range v.(*schema.Set).List() { + dMap := item.(map[string]interface{}) + targetGroupAssociation := clb.TargetGroupAssociation{} + dMap[param] = id + for name := range dMap { + setString(name, dMap[name].(string), &targetGroupAssociation) + } + associations = append(associations, &targetGroupAssociation) + } + } + return associations +} +func setString(fieldName string, value string, request *clb.TargetGroupAssociation) { + switch fieldName { + case "load_balancer_id": + request.LoadBalancerId = helper.String(value) + case "target_group_id": + request.TargetGroupId = helper.String(value) + case "listener_id": + request.ListenerId = helper.String(value) + case "location_id": + request.LocationId = helper.String(value) + default: + fmt.Printf("Invalid field name: %s\n", fieldName) + } +} +func isBindFromClb(id string) bool { + re := regexp.MustCompile(`^(.*?)-`) + match := re.FindStringSubmatch(id) + + if len(match) > 1 { + return match[1] == ResourcePrefixFromClb + } + return false +} +func margeReadRequest(d *schema.ResourceData) ([]string, map[string]struct{}) { + resourceId := d.Id() + + associationsSet := make(map[string]struct{}) + targetGroupList := make([]string, 0) + if v, ok := d.GetOk("associations"); ok { + for _, item := range v.(*schema.Set).List() { + dMap := item.(map[string]interface{}) + ids := make([]string, 0) + + processIds(resourceId, dMap, "load_balancer_id", isBindFromClb(resourceId), &ids) + processIds(resourceId, dMap, "target_group_id", isBindFromClb(resourceId), &ids) + processIds(resourceId, dMap, "listener_id", isBindFromClb(resourceId), &ids) + processIds(resourceId, dMap, "location_id", isBindFromClb(resourceId), &ids) + + if groupId, ok := dMap["target_group_id"]; ok && groupId.(string) != "" { + targetGroupList = append(targetGroupList, groupId.(string)) + } + + associationsSet[strings.Join(ids, tccommon.FILED_SP)] = struct{}{} + } + } + if len(targetGroupList) < 1 && !isBindFromClb(resourceId) { + targetGroupList = append(targetGroupList, resourceId) + } + return targetGroupList, associationsSet +} +func processIds(id string, dMap map[string]interface{}, key string, clbFlag bool, ids *[]string) { + if clbFlag && key == "load_balancer_id" { + *ids = append(*ids, id) + } else if !clbFlag && key == "target_group_id" { + *ids = append(*ids, id) + } else { + if v, ok := dMap[key]; ok { + *ids = append(*ids, v.(string)) + } else { + *ids = append(*ids, "null") + } + + } + fmt.Println(clbFlag, key, ids) +} diff --git a/tencentcloud/services/clb/resource_tc_clb_target_group_attachments.md b/tencentcloud/services/clb/resource_tc_clb_target_group_attachments.md index ff5b57d3e4..11e673f23b 100644 --- a/tencentcloud/services/clb/resource_tc_clb_target_group_attachments.md +++ b/tencentcloud/services/clb/resource_tc_clb_target_group_attachments.md @@ -9,7 +9,6 @@ resource "tencentcloud_clb_target_group_attachments" "target_group_attachments" listener_id = "lbl-m2q6sp9m" target_group_id = "lbtg-5xunivs0" location_id = "loc-jjqr0ric" - } } ``` diff --git a/tencentcloud/services/clb/resource_tc_clb_target_group_attachments_test.go b/tencentcloud/services/clb/resource_tc_clb_target_group_attachments_test.go index 52008e8983..2008a8e83f 100644 --- a/tencentcloud/services/clb/resource_tc_clb_target_group_attachments_test.go +++ b/tencentcloud/services/clb/resource_tc_clb_target_group_attachments_test.go @@ -27,11 +27,30 @@ func TestAccTencentCloudClbTargetGroupAttachmentsResource_basic(t *testing.T) { }) } +func TestAccTencentCloudClbTargetGroupAttachmentsResource_target(t *testing.T) { + t.Parallel() + resource.Test(t, resource.TestCase{ + PreCheck: func() { + tcacctest.AccPreCheck(t) + }, + Providers: tcacctest.AccProviders, + Steps: []resource.TestStep{ + { + Config: testAccClbTargetGroupAttachmentsTarget, + Check: resource.ComposeTestCheckFunc(resource.TestCheckResourceAttrSet("tencentcloud_clb_target_group_attachments.target_group_attachments", "id"), + resource.TestCheckResourceAttrSet("tencentcloud_clb_target_group_attachments.target_group_attachments", "target_group_id"), + resource.TestCheckResourceAttrSet("tencentcloud_clb_target_group_attachments.target_group_attachments", "associations.#"), + ), + }, + }, + }) +} + const testAccClbTargetGroupAttachments = ` resource "tencentcloud_clb_instance" "clb_basic" { network_type = "OPEN" - clb_name = "tf_test_clb_attach" + clb_name = "tf_test_clb_attach_example" vpc_id = "vpc-5kwngvex" } @@ -84,22 +103,22 @@ resource "tencentcloud_clb_target_group_attachments" "target_group_attachments" load_balancer_id = tencentcloud_clb_instance.clb_basic.id associations { listener_id = tencentcloud_clb_listener.public_listeners.listener_id - target_group_id = "lbtg-ln4gk8me" + target_group_id = "lbtg-88ace9ra" location_id = tencentcloud_clb_listener_rule.rule_basic.rule_id } associations { listener_id = tencentcloud_clb_listener.public_listeners.listener_id - target_group_id = "lbtg-iv3mdrfy" + target_group_id = "lbtg-ldkb0xxg" location_id = tencentcloud_clb_listener_rule.rule_basic2.rule_id } associations { listener_id = tencentcloud_clb_listener.public_listeners.listener_id - target_group_id = "lbtg-ctz951k0" + target_group_id = "lbtg-7sgej5ey" location_id = tencentcloud_clb_listener_rule.rule_basic3.rule_id } associations { listener_id = tencentcloud_clb_listener.public_listeners.listener_id - target_group_id = "lbtg-kukb1j9c" + target_group_id = "lbtg-og25rlfk" location_id = tencentcloud_clb_listener_rule.rule_basic4.rule_id } depends_on = [tencentcloud_clb_listener.public_listeners, @@ -110,3 +129,148 @@ resource "tencentcloud_clb_target_group_attachments" "target_group_attachments" } ` +const testAccClbTargetGroupAttachmentsTarget = ` + +resource "tencentcloud_clb_instance" "clb_basic" { + network_type = "OPEN" + clb_name = "tf_test_clb_attach_1" + vpc_id = "vpc-5kwngvex" +} +resource "tencentcloud_clb_instance" "clb_basic2" { + network_type = "OPEN" + clb_name = "tf_test_clb_attach_2" + vpc_id = "vpc-5kwngvex" +} +resource "tencentcloud_clb_instance" "clb_basic3" { + network_type = "OPEN" + clb_name = "tf_test_clb_attach_3" + vpc_id = "vpc-5kwngvex" +} +resource "tencentcloud_clb_instance" "clb_basic4" { + network_type = "OPEN" + clb_name = "tf_test_clb_attach_4" + vpc_id = "vpc-5kwngvex" +} +resource "tencentcloud_clb_instance" "clb_basic5" { + network_type = "OPEN" + clb_name = "tf_test_clb_attach_5" + vpc_id = "vpc-5kwngvex" +} + + +resource "tencentcloud_clb_listener" "public_listeners" { + clb_id = tencentcloud_clb_instance.clb_basic.id + protocol = "HTTP" + port = "8090" + listener_name = "iac-test-attach-2" +} +resource "tencentcloud_clb_listener" "public_listeners2" { + clb_id = tencentcloud_clb_instance.clb_basic2.id + protocol = "HTTP" + port = "8090" + listener_name = "iac-test-attach-3" +} +resource "tencentcloud_clb_listener" "public_listeners3" { + clb_id = tencentcloud_clb_instance.clb_basic3.id + protocol = "HTTP" + port = "8090" + listener_name = "iac-test-attach-4" +} +resource "tencentcloud_clb_listener" "public_listeners4" { + clb_id = tencentcloud_clb_instance.clb_basic4.id + protocol = "HTTP" + port = "8090" + listener_name = "iac-test-attach-5" +} +resource "tencentcloud_clb_listener" "public_listeners5" { + clb_id = tencentcloud_clb_instance.clb_basic5.id + protocol = "HTTP" + port = "8090" + listener_name = "iac-test-attach-6" +} +resource "tencentcloud_clb_listener_rule" "rule_basic" { + clb_id = tencentcloud_clb_instance.clb_basic.id + listener_id = tencentcloud_clb_listener.public_listeners.listener_id + domain = "abc.com" + url = "/" + session_expire_time = 30 + scheduler = "WRR" + target_type = "TARGETGROUP" +} +resource "tencentcloud_clb_listener_rule" "rule_basic2" { + clb_id = tencentcloud_clb_instance.clb_basic2.id + listener_id = tencentcloud_clb_listener.public_listeners2.listener_id + domain = "baidu.com" + url = "/" + session_expire_time = 30 + scheduler = "WRR" + target_type = "TARGETGROUP" +} +resource "tencentcloud_clb_listener_rule" "rule_basic3" { + clb_id = tencentcloud_clb_instance.clb_basic3.id + listener_id = tencentcloud_clb_listener.public_listeners3.listener_id + domain = "tencent.com" + url = "/" + session_expire_time = 30 + scheduler = "WRR" + target_type = "TARGETGROUP" +} +resource "tencentcloud_clb_listener_rule" "rule_basic4" { + clb_id = tencentcloud_clb_instance.clb_basic4.id + listener_id = tencentcloud_clb_listener.public_listeners4.listener_id + domain = "aws.com" + url = "/" + session_expire_time = 30 + scheduler = "WRR" + target_type = "TARGETGROUP" +} +resource "tencentcloud_clb_listener_rule" "rule_basic5" { + clb_id = tencentcloud_clb_instance.clb_basic5.id + listener_id = tencentcloud_clb_listener.public_listeners5.listener_id + domain = "aws2.com" + url = "/" + session_expire_time = 30 + scheduler = "WRR" + target_type = "TARGETGROUP" +} +resource "tencentcloud_clb_target_group_attachments" "target_group_attachments" { + target_group_id = "lbtg-dajxvv8q" + associations { + listener_id = tencentcloud_clb_listener.public_listeners.listener_id + load_balancer_id = tencentcloud_clb_instance.clb_basic.id + location_id = tencentcloud_clb_listener_rule.rule_basic.rule_id + } + associations { + listener_id = tencentcloud_clb_listener.public_listeners2.listener_id + load_balancer_id = tencentcloud_clb_instance.clb_basic2.id + location_id = tencentcloud_clb_listener_rule.rule_basic2.rule_id + } + associations { + listener_id = tencentcloud_clb_listener.public_listeners3.listener_id + load_balancer_id = tencentcloud_clb_instance.clb_basic3.id + + location_id = tencentcloud_clb_listener_rule.rule_basic3.rule_id + } + associations { + listener_id = tencentcloud_clb_listener.public_listeners4.listener_id + load_balancer_id = tencentcloud_clb_instance.clb_basic4.id + location_id = tencentcloud_clb_listener_rule.rule_basic4.rule_id + } + associations { + listener_id = tencentcloud_clb_listener.public_listeners5.listener_id + load_balancer_id = tencentcloud_clb_instance.clb_basic5.id + location_id = tencentcloud_clb_listener_rule.rule_basic5.rule_id + } + depends_on = [ + tencentcloud_clb_listener.public_listeners, + tencentcloud_clb_listener.public_listeners2, + tencentcloud_clb_listener.public_listeners3, + tencentcloud_clb_listener.public_listeners4, + tencentcloud_clb_listener.public_listeners5, + tencentcloud_clb_listener_rule.rule_basic5, + tencentcloud_clb_listener_rule.rule_basic4, + tencentcloud_clb_listener_rule.rule_basic3, + tencentcloud_clb_listener_rule.rule_basic2, + tencentcloud_clb_listener_rule.rule_basic] +} +` diff --git a/tencentcloud/services/clb/service_tencentcloud_clb.go b/tencentcloud/services/clb/service_tencentcloud_clb.go index 02c1ebbe50..0b24e1c64e 100644 --- a/tencentcloud/services/clb/service_tencentcloud_clb.go +++ b/tencentcloud/services/clb/service_tencentcloud_clb.go @@ -2304,14 +2304,14 @@ func (me *ClbService) DescribeClbTargetGroupAttachmentsById(ctx context.Context, info = append(info, "null") } + info = append(info, groupId) + if associations.ListenerId != nil { info = append(info, *associations.ListenerId) } else { info = append(info, "null") } - info = append(info, groupId) - if associations.LocationId != nil { info = append(info, *associations.LocationId) } else { @@ -2319,6 +2319,7 @@ func (me *ClbService) DescribeClbTargetGroupAttachmentsById(ctx context.Context, } key := strings.Join(info, tccommon.FILED_SP) + fmt.Println(key) if _, ok := associationsSet[key]; ok { result = append(result, key) } diff --git a/website/docs/r/clb_target_group_attachments.html.markdown b/website/docs/r/clb_target_group_attachments.html.markdown new file mode 100644 index 0000000000..0dcbfe993b --- /dev/null +++ b/website/docs/r/clb_target_group_attachments.html.markdown @@ -0,0 +1,49 @@ +--- +subcategory: "Cloud Load Balancer(CLB)" +layout: "tencentcloud" +page_title: "TencentCloud: tencentcloud_clb_target_group_attachments" +sidebar_current: "docs-tencentcloud-resource-clb_target_group_attachments" +description: |- + Provides a resource to create a clb target_group_attachments +--- + +# tencentcloud_clb_target_group_attachments + +Provides a resource to create a clb target_group_attachments + +## Example Usage + +```hcl +resource "tencentcloud_clb_target_group_attachments" "target_group_attachments" { + load_balancer_id = "lb-phbx2420" + associations { + listener_id = "lbl-m2q6sp9m" + target_group_id = "lbtg-5xunivs0" + location_id = "loc-jjqr0ric" + } +} +``` + +## Argument Reference + +The following arguments are supported: + +* `associations` - (Required, Set) Association array, the combination cannot exceed 20. +* `load_balancer_id` - (Optional, String) CLB instance ID, (load_balancer_id and target_group_id require at least one). +* `target_group_id` - (Optional, String) Target group ID, (load_balancer_id and target_group_id require at least one). + +The `associations` object supports the following: + +* `listener_id` - (Optional, String) Listener ID. +* `load_balancer_id` - (Optional, String) CLB instance ID, when the binding target is clb, the target_group_id in associations is required. +* `location_id` - (Optional, String) Forwarding rule ID. +* `target_group_id` - (Optional, String) Target group ID, when the binding target is target group, load_balancer_id in associations is required. + +## Attributes Reference + +In addition to all arguments above, the following attributes are exported: + +* `id` - ID of the resource. + + + diff --git a/website/tencentcloud.erb b/website/tencentcloud.erb index f0dec8cb3b..7fa6834777 100644 --- a/website/tencentcloud.erb +++ b/website/tencentcloud.erb @@ -1351,6 +1351,9 @@