Skip to content

Commit 4f957e2

Browse files
author
“guojunchu”
committed
add tcp/udp listener target group attachment
1 parent 8ad5a00 commit 4f957e2

File tree

4 files changed

+42
-10
lines changed

4 files changed

+42
-10
lines changed

tencentcloud/resource_tc_clb_listener.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,8 +268,9 @@ func resourceTencentCloudClbListenerCreate(d *schema.ResourceData, meta interfac
268268
if v, ok := d.GetOk("target_type"); ok {
269269
targetType := v.(string)
270270
request.TargetType = &targetType
271-
} else if protocol == CLB_LISTENER_PROTOCOL_TCP || protocol == CLB_LISTENER_PROTOCOL_UDP {
272-
return fmt.Errorf("[TECENT_TERRAFORM_CHECK][CLB listener][Create] check: protocol TCP/UDP must set target_type")
271+
} else if protocol == CLB_LISTENER_PROTOCOL_TCP || protocol == CLB_LISTENER_PROTOCOL_UDP || protocol == CLB_LISTENER_PROTOCOL_TCPSSL {
272+
targetType := CLB_TARGET_TYPE_NODE
273+
request.TargetType = &targetType
273274
}
274275

275276
if v, ok := d.GetOk("session_expire_time"); ok {

tencentcloud/resource_tc_clb_target_group_attachment.go

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ func resourceTencentCloudClbTargetGroupAttachment() *schema.Resource {
6565
return &schema.Resource{
6666
Create: resourceTencentCloudClbTargetGroupAttachmentCreate,
6767
Read: resourceTencentCloudClbTargetGroupAttachmentRead,
68+
Update: resourceTencentCloudClbTargetGroupAttachmentUpdate,
6869
Delete: resourceTencentCloudClbTargetGroupAttachmentDelete,
6970
Importer: &schema.ResourceImporter{
7071
State: schema.ImportStatePassthrough,
@@ -84,15 +85,14 @@ func resourceTencentCloudClbTargetGroupAttachment() *schema.Resource {
8485
},
8586
"targrt_group_id": {
8687
Type: schema.TypeString,
87-
ForceNew: true,
8888
Optional: true,
8989
Description: "ID of the CLB target group.",
9090
Deprecated: "It has been deprecated from version 1.47.1. Use `target_group_id` instead.",
9191
},
9292
"target_group_id": {
9393
Type: schema.TypeString,
9494
ForceNew: true,
95-
Required: true,
95+
Optional: true,
9696
Description: "ID of the CLB target group.",
9797
},
9898
"rule_id": {
@@ -116,7 +116,7 @@ func resourceTencentCloudClbTargetGroupAttachmentCreate(d *schema.ResourceData,
116116
locationId string
117117
listenerId = d.Get("listener_id").(string)
118118
clbId = d.Get("clb_id").(string)
119-
targetGroupId = d.Get("target_group_id").(string)
119+
targetGroupId string
120120

121121
targetInfos []*clb.TargetGroupInfo
122122
instance *clb.LoadBalancer
@@ -127,6 +127,20 @@ func resourceTencentCloudClbTargetGroupAttachmentCreate(d *schema.ResourceData,
127127
if v, ok := d.GetOk("rule_id"); ok {
128128
locationId = v.(string)
129129
}
130+
vTarget, eHas := d.GetOk("target_group_id")
131+
vTargrt, rHas := d.GetOk("targrt_group_id")
132+
133+
if eHas || rHas {
134+
if rHas {
135+
targetGroupId = vTargrt.(string)
136+
}
137+
if eHas {
138+
targetGroupId = vTarget.(string)
139+
}
140+
} else {
141+
return fmt.Errorf("'target_group_id' or 'targrt_group_id' at least one")
142+
}
143+
130144
//check listenerId
131145
checkErr := ListenerIdCheck(listenerId)
132146
if checkErr != nil {
@@ -221,6 +235,13 @@ func resourceTencentCloudClbTargetGroupAttachmentRead(d *schema.ResourceData, me
221235
return nil
222236
}
223237

238+
func resourceTencentCloudClbTargetGroupAttachmentUpdate(d *schema.ResourceData, meta interface{}) error {
239+
defer logElapsed("resource.tencentcloud_clb_redirection.update")()
240+
defer inconsistentCheck(d, meta)()
241+
// this nil update method works for the only filed `delete_all_auto_rewrite`
242+
return resourceTencentCloudClbRedirectionRead(d, meta)
243+
}
244+
224245
func resourceTencentCloudClbTargetGroupAttachmentDelete(d *schema.ResourceData, meta interface{}) error {
225246
defer logElapsed("resource.tencentcloud_clb_target_group_attachment.delete")()
226247

@@ -259,12 +280,18 @@ func resourceTencentCloudClbTargetGroupAttachmentDelete(d *schema.ResourceData,
259280
if rule.LocationId != nil {
260281
originLocationId = *rule.LocationId
261282
}
262-
263-
if originListenerId == ids[1] && originClbId == ids[2] || originLocationId == ids[3] {
283+
if *rule.Protocol == CLB_LISTENER_PROTOCOL_TCP || *rule.Protocol == CLB_LISTENER_PROTOCOL_UDP || *rule.Protocol == CLB_LISTENER_PROTOCOL_TCPSSL {
284+
if originListenerId == ids[1] && originClbId == ids[2] {
285+
return resource.RetryableError(
286+
fmt.Errorf("rule association target group instance still exist. [targetGroupId=%s, listenerId=%s, cldId=%s]",
287+
ids[0], ids[1], ids[2]))
288+
}
289+
} else if originListenerId == ids[1] && originClbId == ids[2] && originLocationId == ids[3] {
264290
return resource.RetryableError(
265291
fmt.Errorf("rule association target group instance still exist. [targetGroupId=%s, listenerId=%s, cldId=%s, ruleId=%s]",
266292
ids[0], ids[1], ids[2], ids[3]))
267293
}
294+
268295
}
269296
}
270297
return nil

tencentcloud/service_tencentcloud_clb.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1220,7 +1220,11 @@ func (me *ClbService) DescribeAssociateTargetGroups(ctx context.Context, ids []s
12201220
originLocationId = *rule.LocationId
12211221
}
12221222

1223-
if originListenerId == ids[1] && originClbId == ids[2] || originLocationId == ids[3] {
1223+
if *rule.Protocol == CLB_LISTENER_PROTOCOL_TCP || *rule.Protocol == CLB_LISTENER_PROTOCOL_UDP || *rule.Protocol == CLB_LISTENER_PROTOCOL_TCPSSL {
1224+
if originListenerId == ids[1] && originClbId == ids[2] {
1225+
return true, nil
1226+
}
1227+
} else if originListenerId == ids[1] && originClbId == ids[2] && originLocationId == ids[3] {
12241228
return true, nil
12251229
}
12261230
}

website/docs/r/clb_target_group_attachment.html.markdown

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ The following arguments are supported:
5656

5757
* `clb_id` - (Required, ForceNew) ID of the CLB.
5858
* `listener_id` - (Required, ForceNew) ID of the CLB listener.
59-
* `target_group_id` - (Required, ForceNew) ID of the CLB target group.
6059
* `rule_id` - (Optional, ForceNew) ID of the CLB listener rule.
61-
* `targrt_group_id` - (Optional, ForceNew, **Deprecated**) It has been deprecated from version 1.47.1. Use `target_group_id` instead. ID of the CLB target group.
60+
* `target_group_id` - (Optional, ForceNew) ID of the CLB target group.
61+
* `targrt_group_id` - (Optional, **Deprecated**) It has been deprecated from version 1.47.1. Use `target_group_id` instead. ID of the CLB target group.
6262

6363
## Attributes Reference
6464

0 commit comments

Comments
 (0)