Skip to content

Commit 9189ff3

Browse files
committed
add
1 parent ac8d3ee commit 9189ff3

27 files changed

+1357
-662
lines changed

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ require (
4343
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/chdfs v1.0.600
4444
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ciam v1.0.695
4545
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ckafka v1.0.1073
46-
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb v1.0.1132
46+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb v1.0.1188
4747
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cloudaudit v1.0.1033
4848
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls v1.0.1078
49-
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.1132
49+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.1188
5050
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.1128
5151
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cwp v1.0.762
5252
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cynosdb v1.0.1111

go.sum

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -862,6 +862,10 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb v1.0.1107 h1:sUiyGf
862862
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb v1.0.1107/go.mod h1:L1r6mc7XjFlyLlOVqRvPEhjXneHywnyjyv9EoiGBRvM=
863863
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb v1.0.1132 h1:dXKq4d4zTZYV0q1uyf7AJM+u00dd5ndL7lqGfjkmQW0=
864864
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb v1.0.1132/go.mod h1:nwCB78ZVNC6VC+rd31yxhUeff/Ve7z4+yrL3A2B+/dg=
865+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb v1.0.1184 h1:FXG6AtnA+jSUZ4GquFlRhso6SNSTyksQozT97IfH0Ds=
866+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb v1.0.1184/go.mod h1:CtYhxx30ljC4PyxMfG8dWe6a0hse5kkQIcHSXLrgb0g=
867+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb v1.0.1188 h1:zzaIE12soTfyAgRvBYhb5bYxFXRCelvYXDEfvtkT5Y4=
868+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb v1.0.1188/go.mod h1:qIWFhWbmMuUaWCCKVSkdJ1BzKEOqkMeo+uKYS6jJimQ=
865869
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cloudaudit v1.0.1033 h1:dIr+MVsZeUBiKZELfJh5HRJdI+BI6lCp5pv/2oXekuk=
866870
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cloudaudit v1.0.1033/go.mod h1:7oFlNimGSTHFy6JV7W/IZKuJWr+NUjCnGLTvb9MWNrY=
867871
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls v1.0.1078 h1:6yf63sgR2q1ikVedWTXldtrArDHXG01yIdcWSSI5e5Y=
@@ -937,6 +941,10 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.1130 h1:pjt
937941
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.1130/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
938942
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.1132 h1:ecdDh9up1kMKSZtEpvRHGF6BsIlfBtdCSBZm3SK5/Xk=
939943
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.1132/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
944+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.1184 h1:HYVyUfze24rRgaB8hOZeAJ+XNsPO/jhxYTpGmR0xwNQ=
945+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.1184/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
946+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.1188 h1:cU9Phfaym7taAUgGrEQ/0Y+w3r5+kWwGROhaL3hIYnY=
947+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.1188/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
940948
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/controlcenter v1.0.993 h1:WlPgXldQCxt7qi5Xrc6j6zTrsXWzN5BcOGs7Irq7fwQ=
941949
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/controlcenter v1.0.993/go.mod h1:Z9U8zNtyuyKhjS0698wqsrG/kLx1TQ5CEixXBwVe7xY=
942950
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/csip v1.0.860 h1:F3esKBIT3HW9+7Gt8cVgf8X06VdGIczpgLBUECzSEzU=

tencentcloud/provider.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1299,6 +1299,7 @@ func Provider() *schema.Provider {
12991299
"tencentcloud_clb_target_group": clb.ResourceTencentCloudClbTargetGroup(),
13001300
"tencentcloud_clb_target_group_instance_attachment": clb.ResourceTencentCloudClbTGAttachmentInstance(),
13011301
"tencentcloud_clb_target_group_attachment": clb.ResourceTencentCloudClbTargetGroupAttachment(),
1302+
"tencentcloud_clb_target_group_attachments": clb.ResourceTencentCloudClbTargetGroupAttachments(),
13021303
"tencentcloud_clb_log_set": clb.ResourceTencentCloudClbLogSet(),
13031304
"tencentcloud_clb_log_topic": clb.ResourceTencentCloudClbLogTopic(),
13041305
"tencentcloud_clb_customized_config": clb.ResourceTencentCloudClbCustomizedConfig(),
@@ -2233,7 +2234,6 @@ func Provider() *schema.Provider {
22332234
"tencentcloud_cdwpg_userhba": cdwpg.ResourceTencentCloudCdwpgUserhba(),
22342235
"tencentcloud_clickhouse_keyval_config": cdwch.ResourceTencentCloudClickhouseKeyvalConfig(),
22352236
"tencentcloud_clickhouse_xml_config": cdwch.ResourceTencentCloudClickhouseXmlConfig(),
2236-
"tencentcloud_clb_target_group_attachments": clb.ResourceTencentCloudClbTargetGroupAttachments(),
22372237
"tencentcloud_vpc_peer_connect_manager": vpc.ResourceTencentCloudVpcPeerConnectManager(),
22382238
"tencentcloud_vpc_peer_connect_accept_operation": vpc.ResourceTencentCloudVpcPeerConnectAcceptOperation(),
22392239
"tencentcloud_vpc_peer_connect_reject_operation": vpc.ResourceTencentCloudVpcPeerConnectRejectOperation(),

tencentcloud/services/clb/resource_tc_clb_listener.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ func ResourceTencentCloudClbListener() *schema.Resource {
284284
"full_end_ports": {
285285
Type: schema.TypeList,
286286
Optional: true,
287+
ForceNew: true,
287288
Description: "End port of the full port segment listener.",
288289
Elem: &schema.Schema{Type: schema.TypeInt},
289290
},

tencentcloud/services/clb/resource_tc_clb_target_group.go

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@ func ResourceTencentCloudClbTargetGroup() *schema.Resource {
4646
Type: schema.TypeList,
4747
Optional: true,
4848
Description: "The backend server of target group bind.",
49-
Deprecated: "It has been deprecated from version 1.77.3. " +
50-
"please use `tencentcloud_clb_target_group_instance_attachment` instead.",
49+
Deprecated: "It has been deprecated from version 1.77.3. Please use `tencentcloud_clb_target_group_instance_attachment` instead.",
5150
Elem: &schema.Resource{
5251
Schema: map[string]*schema.Schema{
5352
"bind_ip": {
@@ -202,9 +201,7 @@ func resourceTencentCloudClbTargetCreate(d *schema.ResourceData, meta interface{
202201
}
203202

204203
d.SetId(*response.Response.TargetGroupId)
205-
206204
return resourceTencentCloudClbTargetRead(d, meta)
207-
208205
}
209206

210207
func resourceTencentCloudClbTargetRead(d *schema.ResourceData, meta interface{}) error {
@@ -334,10 +331,5 @@ func resourceTencentCloudClbTargetDelete(d *schema.ResourceData, meta interface{
334331
targetGroupId = d.Id()
335332
)
336333

337-
err := clbService.DeleteTarget(ctx, targetGroupId)
338-
if err != nil {
339-
return err
340-
}
341-
342-
return nil
334+
return clbService.DeleteTarget(ctx, targetGroupId)
343335
}

tencentcloud/services/clb/resource_tc_clb_target_group_attachment.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,13 @@ resource "tencentcloud_clb_listener_rule" "example" {
5353
resource "tencentcloud_clb_target_group" "example" {
5454
target_group_name = "tf-example"
5555
vpc_id = tencentcloud_vpc.vpc.id
56+
port = 8090
57+
type = "v1"
58+
59+
tags {
60+
tag_key = "tagKey"
61+
tag_value = "tagValue"
62+
}
5663
}
5764
5865
// create clb target group attachment
@@ -61,6 +68,7 @@ resource "tencentcloud_clb_target_group_attachment" "example" {
6168
target_group_id = tencentcloud_clb_target_group.example.id
6269
listener_id = tencentcloud_clb_listener.example.listener_id
6370
rule_id = tencentcloud_clb_listener_rule.example.rule_id
71+
weight = 10
6472
}
6573
```
6674

tencentcloud/services/clb/resource_tc_clb_target_group_attachments.go

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"log"
77
"regexp"
8+
"strconv"
89
"strings"
910

1011
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
@@ -72,11 +73,11 @@ func ResourceTencentCloudClbTargetGroupAttachments() *schema.Resource {
7273
Description: "Forwarding rule ID.",
7374
},
7475
"weight": {
75-
Type: schema.TypeInt,
76-
Optional: true,
77-
ForceNew: true,
78-
ValidateFunc: tccommon.ValidateIntegerInRange(0, 100),
79-
Description: "Target group weight, range [0, 100]. It only takes effect when binding to the v2 target group. If it does not exist, it defaults to 10.",
76+
// why int to string? (fix map int zero value)
77+
Type: schema.TypeString,
78+
Optional: true,
79+
ForceNew: true,
80+
Description: "Target group weight, range ['0', '100']. It only takes effect when binding to the v2 target group.",
8081
},
8182
},
8283
},
@@ -196,15 +197,15 @@ func resourceTencentCloudClbTargetGroupAttachmentsRead(d *schema.ResourceData, m
196197
}
197198

198199
if len(targetGroupAttachments) < 1 {
199-
d.SetId("")
200200
log.Printf("[WARN]%s resource `ClbTargetGroupAttachments` [%s] not found, please check if it has been deleted.\n", logId, d.Id())
201+
d.SetId("")
201202
return nil
202203
}
203204
var associationsList []interface{}
204205

205206
for _, attachment := range targetGroupAttachments {
206207
info := strings.Split(attachment, tccommon.FILED_SP)
207-
if len(info) != 4 {
208+
if len(info) != 5 {
208209
return fmt.Errorf("id is broken,%s", info)
209210
}
210211
associationsMap := map[string]interface{}{}
@@ -222,6 +223,9 @@ func resourceTencentCloudClbTargetGroupAttachmentsRead(d *schema.ResourceData, m
222223
if info[3] != "" && info[3] != "null" {
223224
associationsMap["location_id"] = info[3]
224225
}
226+
if info[4] != "" && info[4] != "null" {
227+
associationsMap["weight"] = info[4]
228+
}
225229
associationsList = append(associationsList, associationsMap)
226230
}
227231

@@ -280,10 +284,6 @@ func parseParamToRequest(d *schema.ResourceData, param string, id string) (assoc
280284
if v, ok := dMap[name].(string); ok && v != "" {
281285
setString(name, v, &targetGroupAssociation)
282286
}
283-
284-
if v, ok := dMap[name].(int); ok {
285-
setInt(name, v, &targetGroupAssociation)
286-
}
287287
}
288288
}
289289
associations = append(associations, &targetGroupAssociation)
@@ -301,6 +301,9 @@ func setString(fieldName string, value string, request *clb.TargetGroupAssociati
301301
request.ListenerId = helper.String(value)
302302
case "location_id":
303303
request.LocationId = helper.String(value)
304+
case "weight":
305+
valueInt, _ := strconv.Atoi(value)
306+
request.Weight = helper.IntInt64(valueInt)
304307
default:
305308
log.Printf("Invalid field name: %s\n", fieldName)
306309
}
@@ -337,9 +340,10 @@ func margeReadRequest(d *schema.ResourceData) ([]string, map[string]struct{}) {
337340
processIds(resourceId, dMap, "target_group_id", isBindFromClb(resourceId), &ids)
338341
processIds(resourceId, dMap, "listener_id", isBindFromClb(resourceId), &ids)
339342
processIds(resourceId, dMap, "location_id", isBindFromClb(resourceId), &ids)
343+
processIds(resourceId, dMap, "weight", isBindFromClb(resourceId), &ids)
340344

341-
if groupId, ok := dMap["target_group_id"]; ok && groupId.(string) != "" {
342-
targetGroupList = append(targetGroupList, groupId.(string))
345+
if groupId, ok := dMap["target_group_id"].(string); ok && groupId != "" {
346+
targetGroupList = append(targetGroupList, groupId)
343347
}
344348

345349
associationsSet[strings.Join(ids, tccommon.FILED_SP)] = struct{}{}
@@ -356,11 +360,10 @@ func processIds(id string, dMap map[string]interface{}, key string, clbFlag bool
356360
} else if !clbFlag && key == "target_group_id" {
357361
*ids = append(*ids, id)
358362
} else {
359-
if v, ok := dMap[key]; ok && v.(string) != "" {
360-
*ids = append(*ids, v.(string))
363+
if v, ok := dMap[key].(string); ok && v != "" {
364+
*ids = append(*ids, v)
361365
} else {
362366
*ids = append(*ids, "null")
363367
}
364-
365368
}
366369
}
Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,33 @@
1-
Provides a resource to create a clb target_group_attachments
1+
Provides a resource to create a CLB target group attachments
22

3-
This resource supports bidirectional binding (target group binding to the load balancer, load balancer binding to the target group). When choosing either the load balancer or the target group as the binding target, up to 20 combinations can be bound at most.
3+
~> **NOTE:** This resource supports bidirectional binding (target group binding to the load balancer, load balancer binding to the target group). When choosing either the load balancer or the target group as the binding target, up to 20 combinations can be bound at most.
44

55
Example Usage
66

77
Load balancer binding to the target group
88

99
```hcl
10-
resource "tencentcloud_clb_target_group_attachments" "target_group_attachments" {
11-
load_balancer_id = "lb-phbx2420"
10+
resource "tencentcloud_clb_target_group_attachments" "example" {
11+
load_balancer_id = "lb-lmgp1eis"
1212
associations {
13-
listener_id = "lbl-m2q6sp9m"
14-
target_group_id = "lbtg-5xunivs0"
15-
location_id = "loc-jjqr0ric"
13+
listener_id = "lbl-jbdfcswy"
14+
target_group_id = "lbtg-bjosq37w"
15+
location_id = "loc-bjl41tpc"
16+
weight = "10"
1617
}
1718
}
18-
1919
```
20+
2021
Target group binding to the load balancer
22+
2123
```hcl
22-
resource "tencentcloud_clb_target_group_attachments" "target_group_attachments" {
23-
target_group_id = "lbtg-5xunivs0"
24-
associations {
25-
listener_id = "lbl-m2q6sp9m"
24+
resource "tencentcloud_clb_target_group_attachments" "example" {
25+
load_balancer_id = "lb-lmgp1eis"
26+
associations {
27+
listener_id = "lbl-jbdfcswy"
2628
load_balancer_id = "lb-phbx2420"
27-
location_id = "loc-jjqr0ric"
29+
location_id = "loc-bjl41tpc"
30+
weight = "10"
2831
}
2932
}
30-
31-
```
33+
```

tencentcloud/services/clb/resource_tc_clb_target_group_instance_attachment.go

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,14 @@ func ResourceTencentCloudClbTGAttachmentInstance() *schema.Resource {
4343
},
4444
"port": {
4545
Type: schema.TypeInt,
46-
Optional: true,
46+
Required: true,
4747
ForceNew: true,
4848
Description: "The port of the target group instance, fully listening to the target group does not support passing this field.",
4949
},
5050
"weight": {
5151
Type: schema.TypeInt,
52-
Optional: true,
53-
Description: "The weight of the target group instance.",
52+
Required: true,
53+
Description: "The weight of the target group instance. Value range: 0-100.",
5454
},
5555
},
5656
}
@@ -115,7 +115,6 @@ func resourceTencentCloudClbTGAttachmentInstanceCreate(d *schema.ResourceData, m
115115
}
116116

117117
d.SetId(strings.Join([]string{targetGroupId, bindIp, strconv.Itoa(port)}, tccommon.FILED_SP))
118-
119118
return resourceTencentCloudClbTGAttachmentInstanceRead(d, meta)
120119
}
121120

@@ -233,10 +232,5 @@ func resourceTencentCloudClbTGAttachmentInstanceDelete(d *schema.ResourceData, m
233232
return err
234233
}
235234

236-
err = clbService.DeregisterTargetInstances(ctx, targetGroupId, bindIp, port)
237-
if err != nil {
238-
return err
239-
}
240-
241-
return nil
235+
return clbService.DeregisterTargetInstances(ctx, targetGroupId, bindIp, port)
242236
}

tencentcloud/services/clb/resource_tc_clb_target_group_instance_attachment.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,18 @@ data "tencentcloud_instances" "instances" {
6262
resource "tencentcloud_clb_target_group" "example" {
6363
target_group_name = "tf-example"
6464
vpc_id = tencentcloud_vpc.vpc.id
65+
port = 8090
66+
type = "v1"
67+
68+
tags {
69+
tag_key = "tagKey"
70+
tag_value = "tagValue"
71+
}
6572
}
6673
6774
resource "tencentcloud_clb_target_group_instance_attachment" "example" {
6875
target_group_id = tencentcloud_clb_target_group.example.id
69-
bind_ip = data.tencentcloud_instances.instances.instance_list[0].private_ip
76+
bind_ip = tencentcloud_instance.example.private_ip
7077
port = 8080
7178
weight = 10
7279
}
@@ -77,5 +84,5 @@ Import
7784
CLB target group instance attachment can be imported using the id, e.g.
7885

7986
```
80-
$ terraform import tencentcloud_clb_target_group_instance_attachment.example lbtg-3k3io0i0#172.16.48.18#8080
87+
$ terraform import tencentcloud_clb_target_group_instance_attachment.example lbtg-3k3io0i0#10.0.30.25#8080
8188
```

0 commit comments

Comments
 (0)