Skip to content

Commit ac8d3ee

Browse files
committed
add
1 parent e8f7a1e commit ac8d3ee

19 files changed

+535
-141
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.1107
46+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb v1.0.1132
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.1130
49+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.1132
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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -860,6 +860,8 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ckafka v1.0.1073 h1:+nT
860860
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ckafka v1.0.1073/go.mod h1:D9xdyB3utAtgGwTExSGxHSVQMfVHEUo/bfaBTxjHkao=
861861
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb v1.0.1107 h1:sUiyGfYHzNpHKJx6DlRu1K8xBEGaWlOQT+8W5Ws0v4U=
862862
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb v1.0.1107/go.mod h1:L1r6mc7XjFlyLlOVqRvPEhjXneHywnyjyv9EoiGBRvM=
863+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb v1.0.1132 h1:dXKq4d4zTZYV0q1uyf7AJM+u00dd5ndL7lqGfjkmQW0=
864+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb v1.0.1132/go.mod h1:nwCB78ZVNC6VC+rd31yxhUeff/Ve7z4+yrL3A2B+/dg=
863865
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cloudaudit v1.0.1033 h1:dIr+MVsZeUBiKZELfJh5HRJdI+BI6lCp5pv/2oXekuk=
864866
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cloudaudit v1.0.1033/go.mod h1:7oFlNimGSTHFy6JV7W/IZKuJWr+NUjCnGLTvb9MWNrY=
865867
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls v1.0.1078 h1:6yf63sgR2q1ikVedWTXldtrArDHXG01yIdcWSSI5e5Y=
@@ -933,6 +935,8 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.1128/go.mod
933935
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.1129/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
934936
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.1130 h1:pjtrqJUaidq1fFWwPvBorq7FScq0LXiQ7pZjJZx3Jsc=
935937
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.1130/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
938+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.1132 h1:ecdDh9up1kMKSZtEpvRHGF6BsIlfBtdCSBZm3SK5/Xk=
939+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.1132/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
936940
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/controlcenter v1.0.993 h1:WlPgXldQCxt7qi5Xrc6j6zTrsXWzN5BcOGs7Irq7fwQ=
937941
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/controlcenter v1.0.993/go.mod h1:Z9U8zNtyuyKhjS0698wqsrG/kLx1TQ5CEixXBwVe7xY=
938942
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/csip v1.0.860 h1:F3esKBIT3HW9+7Gt8cVgf8X06VdGIczpgLBUECzSEzU=

tencentcloud/services/clb/resource_tc_clb_listener.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,12 @@ func ResourceTencentCloudClbListener() *schema.Resource {
281281
Optional: true,
282282
Description: "Whether to enable SNAT.",
283283
},
284+
"full_end_ports": {
285+
Type: schema.TypeList,
286+
Optional: true,
287+
Description: "End port of the full port segment listener.",
288+
Elem: &schema.Schema{Type: schema.TypeInt},
289+
},
284290
//computed
285291
"listener_id": {
286292
Type: schema.TypeString,
@@ -411,6 +417,15 @@ func resourceTencentCloudClbListenerCreate(d *schema.ResourceData, meta interfac
411417
request.SnatEnable = helper.Bool(v.(bool))
412418
}
413419

420+
if v, ok := d.GetOk("full_end_ports"); ok {
421+
fullEndPorts := v.([]interface{})
422+
request.FullEndPorts = make([]*int64, 0, len(fullEndPorts))
423+
for i := range fullEndPorts {
424+
item := fullEndPorts[i].(int)
425+
request.FullEndPorts = append(request.FullEndPorts, helper.IntInt64(item))
426+
}
427+
}
428+
414429
var response *clb.CreateListenerResponse
415430
err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError {
416431
result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseClbClient().CreateListener(request)

tencentcloud/services/clb/resource_tc_clb_target_group.go

Lines changed: 196 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@ package clb
22

33
import (
44
"context"
5+
"fmt"
6+
"log"
57

68
tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common"
9+
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
710

11+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
812
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
913
clb "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb/v20180317"
1014
)
@@ -36,7 +40,7 @@ func ResourceTencentCloudClbTargetGroup() *schema.Resource {
3640
Type: schema.TypeInt,
3741
Optional: true,
3842
ValidateFunc: tccommon.ValidatePort,
39-
Description: "The default port of target group, add server after can use it.",
43+
Description: "The default port of target group, add server after can use it. If `full_listen_switch` is true, setting this parameter is not supported.",
4044
},
4145
"target_group_instances": {
4246
Type: schema.TypeList,
@@ -72,6 +76,49 @@ func ResourceTencentCloudClbTargetGroup() *schema.Resource {
7276
},
7377
},
7478
},
79+
"type": {
80+
Type: schema.TypeString,
81+
Optional: true,
82+
Computed: true,
83+
ValidateFunc: tccommon.ValidateAllowedStringValue([]string{"v1", "v2"}),
84+
Description: "Target group type, currently supports v1 (old version target group), v2 (new version target group), defaults to v1 (old version target group).",
85+
},
86+
"protocol": {
87+
Type: schema.TypeString,
88+
Optional: true,
89+
ValidateFunc: tccommon.ValidateAllowedStringValue([]string{"TCP", "UDP"}),
90+
Description: "Target group backend forwarding protocol. This item is required for the v2 new version target group. Currently supports `TCP`, `UDP`.",
91+
},
92+
"tags": {
93+
Optional: true,
94+
Type: schema.TypeList,
95+
Description: "Label.",
96+
Elem: &schema.Resource{
97+
Schema: map[string]*schema.Schema{
98+
"tag_key": {
99+
Type: schema.TypeString,
100+
Required: true,
101+
Description: "Tag key.",
102+
},
103+
"tag_value": {
104+
Type: schema.TypeString,
105+
Required: true,
106+
Description: "Tag value.",
107+
},
108+
},
109+
},
110+
},
111+
"weight": {
112+
Type: schema.TypeInt,
113+
Optional: true,
114+
ValidateFunc: tccommon.ValidateIntegerInRange(0, 100),
115+
Description: "Default weights for backend services. Value range [0, 100]. After setting this value, when adding backend services to the target group, if the backend services do not have separate weights set, the default weights here will be used.",
116+
},
117+
"full_listen_switch": {
118+
Type: schema.TypeBool,
119+
Optional: true,
120+
Description: "Full listening target group identifier, true indicates full listening target group, false indicates not full listening target group.",
121+
},
75122
},
76123
}
77124
}
@@ -80,40 +127,81 @@ func resourceTencentCloudClbTargetCreate(d *schema.ResourceData, meta interface{
80127
defer tccommon.LogElapsed("resource.tencentcloud_clb_target_group.create")()
81128

82129
var (
83-
logId = tccommon.GetLogId(tccommon.ContextNil)
84-
ctx = context.WithValue(context.TODO(), tccommon.LogIdKey, logId)
85-
clbService = ClbService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()}
86-
vpcId = d.Get("vpc_id").(string)
87-
targetGroupName = d.Get("target_group_name").(string)
88-
port = uint64(d.Get("port").(int))
89-
insAttachments = make([]*clb.TargetGroupInstance, 0)
90-
targetGroupId string
91-
err error
130+
logId = tccommon.GetLogId(tccommon.ContextNil)
131+
request = clb.NewCreateTargetGroupRequest()
132+
response = clb.NewCreateTargetGroupResponse()
92133
)
93134

94-
if v, ok := d.GetOk("target_group_instances"); ok {
95-
targetGroupInstances := v.([]interface{})
96-
for _, v1 := range targetGroupInstances {
97-
value := v1.(map[string]interface{})
98-
bindIP := value["bind_ip"].(string)
99-
port := uint64(value["port"].(int))
100-
weight := uint64(value["weight"].(int))
101-
newPort := uint64(value["new_port"].(int))
102-
tgtGrp := &clb.TargetGroupInstance{
103-
BindIP: &bindIP,
104-
Port: &port,
105-
Weight: &weight,
106-
NewPort: &newPort,
135+
if v, ok := d.GetOk("target_group_name"); ok {
136+
request.TargetGroupName = helper.String(v.(string))
137+
}
138+
139+
if v, ok := d.GetOk("vpc_id"); ok {
140+
request.VpcId = helper.String(v.(string))
141+
}
142+
143+
if v, ok := d.GetOkExists("port"); ok {
144+
request.Port = helper.IntUint64(v.(int))
145+
}
146+
147+
if v, ok := d.GetOk("type"); ok {
148+
request.Type = helper.String(v.(string))
149+
}
150+
151+
if v, ok := d.GetOk("protocol"); ok {
152+
request.Protocol = helper.String(v.(string))
153+
}
154+
155+
if v, ok := d.GetOk("tags"); ok {
156+
for _, item := range v.([]interface{}) {
157+
dMap := item.(map[string]interface{})
158+
clbTags := clb.TagInfo{}
159+
if v, ok := dMap["tag_key"]; ok {
160+
clbTags.TagKey = helper.String(v.(string))
161+
}
162+
163+
if v, ok := dMap["tag_value"]; ok {
164+
clbTags.TagValue = helper.String(v.(string))
107165
}
108-
insAttachments = append(insAttachments, tgtGrp)
166+
167+
request.Tags = append(request.Tags, &clbTags)
109168
}
110169
}
111170

112-
targetGroupId, err = clbService.CreateTargetGroup(ctx, targetGroupName, vpcId, port, insAttachments)
171+
if v, ok := d.GetOkExists("weight"); ok {
172+
request.Weight = helper.IntUint64(v.(int))
173+
}
174+
175+
if v, ok := d.GetOkExists("full_listen_switch"); ok {
176+
request.FullListenSwitch = helper.Bool(v.(bool))
177+
}
178+
179+
err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError {
180+
result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseClbClient().CreateTargetGroup(request)
181+
if e != nil {
182+
return tccommon.RetryError(e)
183+
} else {
184+
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), result.ToJsonString())
185+
}
186+
187+
if result == nil || result.Response == nil {
188+
return resource.NonRetryableError(fmt.Errorf("Create target group failed, Response is nil."))
189+
}
190+
191+
response = result
192+
return nil
193+
})
194+
113195
if err != nil {
196+
log.Printf("[CRITAL]%s create target group failed, reason:%+v", logId, err)
114197
return err
115198
}
116-
d.SetId(targetGroupId)
199+
200+
if response.Response.TargetGroupId == nil {
201+
return fmt.Errorf("TargetGroupId is nil.")
202+
}
203+
204+
d.SetId(*response.Response.TargetGroupId)
117205

118206
return resourceTencentCloudClbTargetRead(d, meta)
119207

@@ -124,23 +212,64 @@ func resourceTencentCloudClbTargetRead(d *schema.ResourceData, meta interface{})
124212
defer tccommon.InconsistentCheck(d, meta)()
125213

126214
var (
127-
logId = tccommon.GetLogId(tccommon.ContextNil)
128-
ctx = context.WithValue(context.TODO(), tccommon.LogIdKey, logId)
129-
clbService = ClbService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()}
130-
id = d.Id()
215+
logId = tccommon.GetLogId(tccommon.ContextNil)
216+
ctx = context.WithValue(context.TODO(), tccommon.LogIdKey, logId)
217+
clbService = ClbService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()}
218+
targetGroupId = d.Id()
131219
)
220+
132221
filters := make(map[string]string)
133-
targetGroupInfos, err := clbService.DescribeTargetGroups(ctx, id, filters)
222+
targetGroupInfos, err := clbService.DescribeTargetGroups(ctx, targetGroupId, filters)
134223
if err != nil {
135224
return err
136225
}
226+
137227
if len(targetGroupInfos) < 1 {
138228
d.SetId("")
139229
return nil
140230
}
141-
_ = d.Set("target_group_name", targetGroupInfos[0].TargetGroupName)
142-
_ = d.Set("vpc_id", targetGroupInfos[0].VpcId)
143-
_ = d.Set("port", targetGroupInfos[0].Port)
231+
232+
if targetGroupInfos[0].TargetGroupName != nil {
233+
_ = d.Set("target_group_name", targetGroupInfos[0].TargetGroupName)
234+
}
235+
236+
if targetGroupInfos[0].VpcId != nil {
237+
_ = d.Set("vpc_id", targetGroupInfos[0].VpcId)
238+
}
239+
240+
if targetGroupInfos[0].Port != nil {
241+
_ = d.Set("port", targetGroupInfos[0].Port)
242+
}
243+
244+
if targetGroupInfos[0].TargetGroupType != nil {
245+
_ = d.Set("type", targetGroupInfos[0].TargetGroupType)
246+
}
247+
248+
if targetGroupInfos[0].Tag != nil {
249+
tagsList := make([]interface{}, 0, len(targetGroupInfos[0].Tag))
250+
for _, tags := range targetGroupInfos[0].Tag {
251+
tagsMap := map[string]interface{}{}
252+
if tags.TagKey != nil {
253+
tagsMap["tag_key"] = tags.TagKey
254+
}
255+
256+
if tags.TagValue != nil {
257+
tagsMap["tag_value"] = tags.TagValue
258+
}
259+
260+
tagsList = append(tagsList, tagsMap)
261+
}
262+
263+
_ = d.Set("tags", tagsList)
264+
}
265+
266+
if targetGroupInfos[0].Weight != nil {
267+
_ = d.Set("weight", targetGroupInfos[0].Weight)
268+
}
269+
270+
if targetGroupInfos[0].FullListenSwitch != nil {
271+
_ = d.Set("full_listen_switch", targetGroupInfos[0].FullListenSwitch)
272+
}
144273

145274
return nil
146275
}
@@ -150,23 +279,44 @@ func resourceTencentCloudClbTargetUpdate(d *schema.ResourceData, meta interface{
150279

151280
var (
152281
logId = tccommon.GetLogId(tccommon.ContextNil)
153-
ctx = context.WithValue(context.TODO(), tccommon.LogIdKey, logId)
154-
clbService = ClbService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()}
155282
targetGroupId = d.Id()
156-
port uint64
157-
tgtGroupName string
158283
)
159284

160-
isChanged := false
161-
if d.HasChange("port") || d.HasChange("target_group_name") {
162-
isChanged = true
163-
port = uint64(d.Get("port").(int))
164-
tgtGroupName = d.Get("target_group_name").(string)
285+
immutableArgs := []string{"type", "protocol", "tags", "full_listen_switch"}
286+
for _, v := range immutableArgs {
287+
if d.HasChange(v) {
288+
return fmt.Errorf("argument `%s` cannot be changed", v)
289+
}
165290
}
166291

167-
if isChanged {
168-
err := clbService.ModifyTargetGroup(ctx, targetGroupId, tgtGroupName, port)
292+
if d.HasChange("target_group_name") || d.HasChange("port") || d.HasChange("weight") {
293+
request := clb.NewModifyTargetGroupAttributeRequest()
294+
if v, ok := d.GetOk("target_group_name"); ok {
295+
request.TargetGroupName = helper.String(v.(string))
296+
}
297+
298+
if v, ok := d.GetOkExists("port"); ok {
299+
request.Port = helper.IntUint64(v.(int))
300+
}
301+
302+
if v, ok := d.GetOkExists("weight"); ok {
303+
request.Weight = helper.IntUint64(v.(int))
304+
}
305+
306+
request.TargetGroupId = &targetGroupId
307+
err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError {
308+
result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseClbClient().ModifyTargetGroupAttribute(request)
309+
if e != nil {
310+
return tccommon.RetryError(e)
311+
} else {
312+
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), result.ToJsonString())
313+
}
314+
315+
return nil
316+
})
317+
169318
if err != nil {
319+
log.Printf("[CRITAL]%s modify target group failed, reason:%+v", logId, err)
170320
return err
171321
}
172322
}
@@ -185,9 +335,9 @@ func resourceTencentCloudClbTargetDelete(d *schema.ResourceData, meta interface{
185335
)
186336

187337
err := clbService.DeleteTarget(ctx, targetGroupId)
188-
189338
if err != nil {
190339
return err
191340
}
341+
192342
return nil
193343
}

0 commit comments

Comments
 (0)