Skip to content

Commit af9b033

Browse files
authored
fix(clb): [116078526]Support four-layer lb (#2489)
* fix: foceNew * fix: foceNew * feat: doc * feat: forceNew * fix(all): support four-layer lb * fix(all): support four-layer lb * fix(all): support four-layer lb * fix(clb): supporting four-layer LB
1 parent eda6dd6 commit af9b033

File tree

8 files changed

+76
-26
lines changed

8 files changed

+76
-26
lines changed

.changelog/2489.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:bug
2+
resource/tencentcloud_clb_target_group_attachments: Fixed the problem of not supporting four-layer LB
3+
```

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.748
46-
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb v1.0.847
46+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb v1.0.860
4747
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cloudaudit v1.0.544
4848
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls v1.0.711
49-
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.859
49+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.860
5050
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.624
5151
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cwp v1.0.762
5252
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cynosdb v1.0.692

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -868,6 +868,8 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb v1.0.693 h1:3eI2Ciq
868868
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb v1.0.693/go.mod h1:WhFqrn14QuRHB01xA5Q9sC+xw73BpqSE5+ZnqEznCW8=
869869
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb v1.0.847 h1:VfUval30/CDPnvS5KpvTpM6v7HcErCgwPTsyN9VDqpM=
870870
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb v1.0.847/go.mod h1:zR4WM8Cg+v4daLgPLfmmzFrXCQFrQYIn+7DqBL60uRc=
871+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb v1.0.860 h1:P2TPFCB1oyJ6yOTgFDBdKByepog3iMg2fIUN/VHo9EM=
872+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb v1.0.860/go.mod h1:eTGN2Qz4NxaYl+CwMpcj4vNImNOr74NC8WTCLSJN8Ks=
871873
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cloudaudit v1.0.544 h1:ApY6rS7I9otgujOdAFy0+Epno1PNVCQmsOoWQxx724Y=
872874
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cloudaudit v1.0.544/go.mod h1:c37rIdL3LrJXYwrfp9c8L4MabTqKIZUe1xvnWhN75oc=
873875
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls v1.0.711 h1:v6ffPkv3kmT6bC0d3JLVVJsh61zdvaLJZ5RHwmKNBHk=
@@ -961,6 +963,8 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.856 h1:4Paa
961963
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.856/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
962964
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.859 h1:XXpytsYJilIk/koSWmpEcDZBILNqeEUprU9L5gqbA00=
963965
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.859/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
966+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.860 h1:d5/YwGX6b5YgFU/0thsbs5aBp4aJJXBi7JyU1JHAaw0=
967+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.860/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
964968
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.624 h1:nEZqsoqt1pEoaP9JjkHQy3/H00suCfzlHW1qOm2nYD8=
965969
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.624/go.mod h1:+TXSVyeKwt1IhZRqKPbTREteBcP+K07Q846/ilNzLWA=
966970
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cwp v1.0.762 h1:2egy69SP/wPsmnfozcQVZ6tUY6F6N/TpEe/7xtXrc/8=

tencentcloud/services/clb/resource_tc_clb_target_group_attachments.go

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ func ResourceTencentCloudClbTargetGroupAttachments() *schema.Resource {
2121
return &schema.Resource{
2222
Create: resourceTencentCloudClbTargetGroupAttachmentsCreate,
2323
Read: resourceTencentCloudClbTargetGroupAttachmentsRead,
24-
Update: resourceTencentCloudClbTargetGroupAttachmentsUpdate,
2524
Delete: resourceTencentCloudClbTargetGroupAttachmentsDelete,
2625
Importer: &schema.ResourceImporter{
2726
State: schema.ImportStatePassthrough,
@@ -31,15 +30,18 @@ func ResourceTencentCloudClbTargetGroupAttachments() *schema.Resource {
3130
"load_balancer_id": {
3231
Type: schema.TypeString,
3332
Optional: true,
33+
ForceNew: true,
3434
Description: "CLB instance ID, (load_balancer_id and target_group_id require at least one).",
3535
},
3636
"target_group_id": {
3737
Type: schema.TypeString,
3838
Optional: true,
39+
ForceNew: true,
3940
Description: "Target group ID, (load_balancer_id and target_group_id require at least one).",
4041
},
4142
"associations": {
4243
Required: true,
44+
ForceNew: true,
4345
Type: schema.TypeSet,
4446
MaxItems: 20,
4547
Description: "Association array, the combination cannot exceed 20.",
@@ -48,20 +50,24 @@ func ResourceTencentCloudClbTargetGroupAttachments() *schema.Resource {
4850
"load_balancer_id": {
4951
Type: schema.TypeString,
5052
Optional: true,
53+
ForceNew: true,
5154
Description: "CLB instance ID, when the binding target is target group, load_balancer_id in associations is required.",
5255
},
5356
"target_group_id": {
5457
Type: schema.TypeString,
5558
Optional: true,
59+
ForceNew: true,
5660
Description: "Target group ID, when the binding target is clb, the target_group_id in associations is required.",
5761
},
5862
"listener_id": {
5963
Type: schema.TypeString,
64+
ForceNew: true,
6065
Optional: true,
6166
Description: "Listener ID.",
6267
},
6368
"location_id": {
6469
Type: schema.TypeString,
70+
ForceNew: true,
6571
Optional: true,
6672
Description: "Forwarding rule ID.",
6773
},
@@ -203,10 +209,12 @@ func resourceTencentCloudClbTargetGroupAttachmentsRead(d *schema.ResourceData, m
203209
_ = d.Set("target_group_id", info[1])
204210
associationsMap["load_balancer_id"] = info[0]
205211
}
206-
207-
associationsMap["listener_id"] = info[2]
208-
associationsMap["location_id"] = info[3]
209-
212+
if info[2] != "" && info[2] != "null" {
213+
associationsMap["listener_id"] = info[2]
214+
}
215+
if info[3] != "" && info[3] != "null" {
216+
associationsMap["location_id"] = info[3]
217+
}
210218
associationsList = append(associationsList, associationsMap)
211219
}
212220

@@ -215,13 +223,6 @@ func resourceTencentCloudClbTargetGroupAttachmentsRead(d *schema.ResourceData, m
215223
return nil
216224
}
217225

218-
func resourceTencentCloudClbTargetGroupAttachmentsUpdate(d *schema.ResourceData, meta interface{}) error {
219-
defer tccommon.LogElapsed("resource.tencentcloud_clb_target_group_attachments.update")()
220-
defer tccommon.InconsistentCheck(d, meta)()
221-
222-
return resourceTencentCloudClbTargetGroupAttachmentsRead(d, meta)
223-
}
224-
225226
func resourceTencentCloudClbTargetGroupAttachmentsDelete(d *schema.ResourceData, meta interface{}) error {
226227
defer tccommon.LogElapsed("resource.tencentcloud_clb_target_group_attachments.delete")()
227228
defer tccommon.InconsistentCheck(d, meta)()
@@ -268,7 +269,9 @@ func parseParamToRequest(d *schema.ResourceData, param string, id string) (assoc
268269
targetGroupAssociation := clb.TargetGroupAssociation{}
269270
dMap[param] = id
270271
for name := range dMap {
271-
setString(name, dMap[name].(string), &targetGroupAssociation)
272+
if dMap[name] != nil && dMap[name].(string) != "" {
273+
setString(name, dMap[name].(string), &targetGroupAssociation)
274+
}
272275
}
273276
associations = append(associations, &targetGroupAssociation)
274277
}
@@ -331,7 +334,7 @@ func processIds(id string, dMap map[string]interface{}, key string, clbFlag bool
331334
} else if !clbFlag && key == "target_group_id" {
332335
*ids = append(*ids, id)
333336
} else {
334-
if v, ok := dMap[key]; ok {
337+
if v, ok := dMap[key]; ok && v.(string) != "" {
335338
*ids = append(*ids, v.(string))
336339
} else {
337340
*ids = append(*ids, "null")

tencentcloud/services/clb/resource_tc_clb_target_group_attachments_test.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,25 @@ func TestAccTencentCloudClbTargetGroupAttachmentsResource_sync(t *testing.T) {
6767
})
6868
}
6969

70+
func TestAccTencentCloudClbTargetGroupAttachmentsResource_tcp(t *testing.T) {
71+
t.Parallel()
72+
resource.Test(t, resource.TestCase{
73+
PreCheck: func() {
74+
tcacctest.AccPreCheck(t)
75+
},
76+
Providers: tcacctest.AccProviders,
77+
Steps: []resource.TestStep{
78+
{
79+
Config: testAccClbTargetGroupAttachmentsTCP,
80+
Check: resource.ComposeTestCheckFunc(resource.TestCheckResourceAttrSet("tencentcloud_clb_target_group_attachments.target_group_attachments", "id"),
81+
resource.TestCheckResourceAttrSet("tencentcloud_clb_target_group_attachments.target_group_attachments", "target_group_id"),
82+
resource.TestCheckResourceAttrSet("tencentcloud_clb_target_group_attachments.target_group_attachments", "associations.#"),
83+
),
84+
},
85+
},
86+
})
87+
}
88+
7089
const testAccClbTargetGroupAttachments = `
7190
7291
resource "tencentcloud_clb_instance" "clb_basic" {
@@ -353,3 +372,24 @@ resource "tencentcloud_clb_target_group_attachments" "target_group_attachments1"
353372
}
354373
}
355374
`
375+
const testAccClbTargetGroupAttachmentsTCP = `
376+
resource "tencentcloud_clb_instance" "clb_basic" {
377+
network_type = "OPEN"
378+
clb_name = "tf_test_clb_attach_1"
379+
vpc_id = "vpc-efc9vddt"
380+
}
381+
resource "tencentcloud_clb_listener" "public_listeners" {
382+
clb_id = tencentcloud_clb_instance.clb_basic.id
383+
protocol = "TCP"
384+
port = "8090"
385+
listener_name = "iac-test-attach"
386+
target_type = "TARGETGROUP"
387+
}
388+
resource "tencentcloud_clb_target_group_attachments" "target_group_attachments" {
389+
target_group_id = "lbtg-nxd0dmcm"
390+
associations {
391+
load_balancer_id = tencentcloud_clb_instance.clb_basic.id
392+
listener_id = tencentcloud_clb_listener.public_listeners.listener_id
393+
}
394+
}
395+
`

vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/http/request.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/modules.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1148,7 +1148,7 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ciam/v20220331
11481148
# github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ckafka v1.0.748
11491149
## explicit; go 1.14
11501150
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ckafka/v20190819
1151-
# github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb v1.0.847
1151+
# github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb v1.0.860
11521152
## explicit; go 1.14
11531153
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb/v20180317
11541154
# github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cloudaudit v1.0.544
@@ -1157,7 +1157,7 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cloudaudit/v20190319
11571157
# github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls v1.0.711
11581158
## explicit; go 1.14
11591159
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls/v20201016
1160-
# github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.859
1160+
# github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.860
11611161
## explicit; go 1.11
11621162
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common
11631163
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/errors

website/docs/r/clb_target_group_attachments.html.markdown

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,16 @@ resource "tencentcloud_clb_target_group_attachments" "target_group_attachments"
4545

4646
The following arguments are supported:
4747

48-
* `associations` - (Required, Set) Association array, the combination cannot exceed 20.
49-
* `load_balancer_id` - (Optional, String) CLB instance ID, (load_balancer_id and target_group_id require at least one).
50-
* `target_group_id` - (Optional, String) Target group ID, (load_balancer_id and target_group_id require at least one).
48+
* `associations` - (Required, Set, ForceNew) Association array, the combination cannot exceed 20.
49+
* `load_balancer_id` - (Optional, String, ForceNew) CLB instance ID, (load_balancer_id and target_group_id require at least one).
50+
* `target_group_id` - (Optional, String, ForceNew) Target group ID, (load_balancer_id and target_group_id require at least one).
5151

5252
The `associations` object supports the following:
5353

54-
* `listener_id` - (Optional, String) Listener ID.
55-
* `load_balancer_id` - (Optional, String) CLB instance ID, when the binding target is target group, load_balancer_id in associations is required.
56-
* `location_id` - (Optional, String) Forwarding rule ID.
57-
* `target_group_id` - (Optional, String) Target group ID, when the binding target is clb, the target_group_id in associations is required.
54+
* `listener_id` - (Optional, String, ForceNew) Listener ID.
55+
* `load_balancer_id` - (Optional, String, ForceNew) CLB instance ID, when the binding target is target group, load_balancer_id in associations is required.
56+
* `location_id` - (Optional, String, ForceNew) Forwarding rule ID.
57+
* `target_group_id` - (Optional, String, ForceNew) Target group ID, when the binding target is clb, the target_group_id in associations is required.
5858

5959
## Attributes Reference
6060

0 commit comments

Comments
 (0)