Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(clb): [116078526]Support four-layer lb #2489

Merged
merged 8 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/2489.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/tencentcloud_clb_target_group_attachments: Fixed the problem of not supporting four-layer LB
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

四层 LB 好像在下面的代码中没体现出来?

```
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ require (
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/chdfs v1.0.600
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ciam v1.0.695
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ckafka v1.0.748
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb v1.0.847
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb v1.0.860
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cloudaudit v1.0.544
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls v1.0.711
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.859
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.860
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.624
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cwp v1.0.762
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cynosdb v1.0.692
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -868,6 +868,8 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb v1.0.693 h1:3eI2Ciq
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb v1.0.693/go.mod h1:WhFqrn14QuRHB01xA5Q9sC+xw73BpqSE5+ZnqEznCW8=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb v1.0.847 h1:VfUval30/CDPnvS5KpvTpM6v7HcErCgwPTsyN9VDqpM=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb v1.0.847/go.mod h1:zR4WM8Cg+v4daLgPLfmmzFrXCQFrQYIn+7DqBL60uRc=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb v1.0.860 h1:P2TPFCB1oyJ6yOTgFDBdKByepog3iMg2fIUN/VHo9EM=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb v1.0.860/go.mod h1:eTGN2Qz4NxaYl+CwMpcj4vNImNOr74NC8WTCLSJN8Ks=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cloudaudit v1.0.544 h1:ApY6rS7I9otgujOdAFy0+Epno1PNVCQmsOoWQxx724Y=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cloudaudit v1.0.544/go.mod h1:c37rIdL3LrJXYwrfp9c8L4MabTqKIZUe1xvnWhN75oc=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls v1.0.711 h1:v6ffPkv3kmT6bC0d3JLVVJsh61zdvaLJZ5RHwmKNBHk=
Expand Down Expand Up @@ -961,6 +963,8 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.856 h1:4Paa
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.856/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.859 h1:XXpytsYJilIk/koSWmpEcDZBILNqeEUprU9L5gqbA00=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.859/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.860 h1:d5/YwGX6b5YgFU/0thsbs5aBp4aJJXBi7JyU1JHAaw0=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.860/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.624 h1:nEZqsoqt1pEoaP9JjkHQy3/H00suCfzlHW1qOm2nYD8=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.624/go.mod h1:+TXSVyeKwt1IhZRqKPbTREteBcP+K07Q846/ilNzLWA=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cwp v1.0.762 h1:2egy69SP/wPsmnfozcQVZ6tUY6F6N/TpEe/7xtXrc/8=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ func ResourceTencentCloudClbTargetGroupAttachments() *schema.Resource {
return &schema.Resource{
Create: resourceTencentCloudClbTargetGroupAttachmentsCreate,
Read: resourceTencentCloudClbTargetGroupAttachmentsRead,
Update: resourceTencentCloudClbTargetGroupAttachmentsUpdate,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里去掉 Update 是不兼容的变更?

Delete: resourceTencentCloudClbTargetGroupAttachmentsDelete,
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
Expand All @@ -31,15 +30,18 @@ func ResourceTencentCloudClbTargetGroupAttachments() *schema.Resource {
"load_balancer_id": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里加 ForceNew 是不兼容的变更?

Description: "CLB instance ID, (load_balancer_id and target_group_id require at least one).",
},
"target_group_id": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Description: "Target group ID, (load_balancer_id and target_group_id require at least one).",
},
"associations": {
Required: true,
ForceNew: true,
Type: schema.TypeSet,
MaxItems: 20,
Description: "Association array, the combination cannot exceed 20.",
Expand All @@ -48,20 +50,24 @@ func ResourceTencentCloudClbTargetGroupAttachments() *schema.Resource {
"load_balancer_id": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Description: "CLB instance ID, when the binding target is target group, load_balancer_id in associations is required.",
},
"target_group_id": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Description: "Target group ID, when the binding target is clb, the target_group_id in associations is required.",
},
"listener_id": {
Type: schema.TypeString,
ForceNew: true,
Optional: true,
Description: "Listener ID.",
},
"location_id": {
Type: schema.TypeString,
ForceNew: true,
Optional: true,
Description: "Forwarding rule ID.",
},
Expand Down Expand Up @@ -203,10 +209,12 @@ func resourceTencentCloudClbTargetGroupAttachmentsRead(d *schema.ResourceData, m
_ = d.Set("target_group_id", info[1])
associationsMap["load_balancer_id"] = info[0]
}

associationsMap["listener_id"] = info[2]
associationsMap["location_id"] = info[3]

if info[2] != "" && info[2] != "null" {
associationsMap["listener_id"] = info[2]
}
if info[3] != "" && info[3] != "null" {
associationsMap["location_id"] = info[3]
}
associationsList = append(associationsList, associationsMap)
}

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

func resourceTencentCloudClbTargetGroupAttachmentsUpdate(d *schema.ResourceData, meta interface{}) error {
defer tccommon.LogElapsed("resource.tencentcloud_clb_target_group_attachments.update")()
defer tccommon.InconsistentCheck(d, meta)()

return resourceTencentCloudClbTargetGroupAttachmentsRead(d, meta)
}

func resourceTencentCloudClbTargetGroupAttachmentsDelete(d *schema.ResourceData, meta interface{}) error {
defer tccommon.LogElapsed("resource.tencentcloud_clb_target_group_attachments.delete")()
defer tccommon.InconsistentCheck(d, meta)()
Expand Down Expand Up @@ -268,7 +269,9 @@ func parseParamToRequest(d *schema.ResourceData, param string, id string) (assoc
targetGroupAssociation := clb.TargetGroupAssociation{}
dMap[param] = id
for name := range dMap {
setString(name, dMap[name].(string), &targetGroupAssociation)
if dMap[name] != nil && dMap[name].(string) != "" {
setString(name, dMap[name].(string), &targetGroupAssociation)
}
}
associations = append(associations, &targetGroupAssociation)
}
Expand Down Expand Up @@ -331,7 +334,7 @@ func processIds(id string, dMap map[string]interface{}, key string, clbFlag bool
} else if !clbFlag && key == "target_group_id" {
*ids = append(*ids, id)
} else {
if v, ok := dMap[key]; ok {
if v, ok := dMap[key]; ok && v.(string) != "" {
*ids = append(*ids, v.(string))
} else {
*ids = append(*ids, "null")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,25 @@ func TestAccTencentCloudClbTargetGroupAttachmentsResource_sync(t *testing.T) {
})
}

func TestAccTencentCloudClbTargetGroupAttachmentsResource_tcp(t *testing.T) {
t.Parallel()
resource.Test(t, resource.TestCase{
PreCheck: func() {
tcacctest.AccPreCheck(t)
},
Providers: tcacctest.AccProviders,
Steps: []resource.TestStep{
{
Config: testAccClbTargetGroupAttachmentsTCP,
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" {
Expand Down Expand Up @@ -353,3 +372,24 @@ resource "tencentcloud_clb_target_group_attachments" "target_group_attachments1"
}
}
`
const testAccClbTargetGroupAttachmentsTCP = `
resource "tencentcloud_clb_instance" "clb_basic" {
network_type = "OPEN"
clb_name = "tf_test_clb_attach_1"
vpc_id = "vpc-efc9vddt"
}
resource "tencentcloud_clb_listener" "public_listeners" {
clb_id = tencentcloud_clb_instance.clb_basic.id
protocol = "TCP"
port = "8090"
listener_name = "iac-test-attach"
target_type = "TARGETGROUP"
}
resource "tencentcloud_clb_target_group_attachments" "target_group_attachments" {
target_group_id = "lbtg-nxd0dmcm"
associations {
load_balancer_id = tencentcloud_clb_instance.clb_basic.id
listener_id = tencentcloud_clb_listener.public_listeners.listener_id
}
}
`

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1148,7 +1148,7 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ciam/v20220331
# github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ckafka v1.0.748
## explicit; go 1.14
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ckafka/v20190819
# github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb v1.0.847
# github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb v1.0.860
## explicit; go 1.14
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb/v20180317
# github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cloudaudit v1.0.544
Expand All @@ -1157,7 +1157,7 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cloudaudit/v20190319
# github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls v1.0.711
## explicit; go 1.14
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls/v20201016
# github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.859
# github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.860
## explicit; go 1.11
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/errors
Expand Down
14 changes: 7 additions & 7 deletions website/docs/r/clb_target_group_attachments.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,16 @@ resource "tencentcloud_clb_target_group_attachments" "target_group_attachments"

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).
* `associations` - (Required, Set, ForceNew) Association array, the combination cannot exceed 20.
* `load_balancer_id` - (Optional, String, ForceNew) CLB instance ID, (load_balancer_id and target_group_id require at least one).
* `target_group_id` - (Optional, String, ForceNew) 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 target group, load_balancer_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 clb, the target_group_id in associations is required.
* `listener_id` - (Optional, String, ForceNew) Listener ID.
* `load_balancer_id` - (Optional, String, ForceNew) CLB instance ID, when the binding target is target group, load_balancer_id in associations is required.
* `location_id` - (Optional, String, ForceNew) Forwarding rule ID.
* `target_group_id` - (Optional, String, ForceNew) Target group ID, when the binding target is clb, the target_group_id in associations is required.

## Attributes Reference

Expand Down
Loading