Skip to content

Commit 8b3b1a1

Browse files
authored
CLB feature support (#590)
1 parent d2b44b5 commit 8b3b1a1

22 files changed

+417
-91
lines changed

CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,20 @@
11
## 1.53.5 (Unreleased)
2+
3+
ENHANCEMENTS:
4+
5+
* Resource `tencentcloud_clb_instance` add `internet_charge_type`, `internet_bandwidth_max_out` to support internet traffic setting with OPEN CLB instance.
6+
* Resource `tencentcloud_clb_rule` add `http2_switch` to support HTTP2 protocol setting.
7+
* Resource `tencentcloud_kubernetes_cluster` add `lan_ip` to show node LAN IP.
8+
* Resource `tencentcloud_kubernetes_scale_worker` add `lan_ip` to show node LAN IP.
9+
* Resource `tencentcloud_kubernetes_cluster_attachment` add `state` to show node state.
10+
* Resource `tencentcloud_clb_rule` support certificate modifying.
11+
* Data Source `tencentcloud_clb_instances` add `internet_charge_type`, `internet_bandwidth_max_out`.
12+
* Data Source `tencentcloud_clb_rules` add `http2_switch`.
13+
14+
BUG FIXES:
15+
16+
* Resource: `tencentcloud_clb_attachment` fix bug that attach more than 20 targets will failed.
17+
218
## 1.53.4 (February 08, 2021)
319

420
ENHANCEMENTS:

tencentcloud/data_source_tc_clb_instances.go

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,26 @@ func dataSourceTencentCloudClbInstances() *schema.Resource {
134134
Computed: true,
135135
Description: "The available tags within this CLB.",
136136
},
137+
"address_ip_version": {
138+
Type: schema.TypeString,
139+
Computed: true,
140+
Description: "IP version, only applicable to open CLB. Valid values are `IPV4`, `IPV6` and `IPv6FullChain`.",
141+
},
142+
"vip_isp": {
143+
Type: schema.TypeString,
144+
Computed: true,
145+
Description: "Network operator, only applicable to open CLB. Valid values are `CMCC`(China Mobile), `CTCC`(Telecom), `CUCC`(China Unicom) and `BGP`. If this ISP is specified, network billing method can only use the bandwidth package billing (BANDWIDTH_PACKAGE).",
146+
},
147+
"internet_charge_type": {
148+
Type: schema.TypeString,
149+
Computed: true,
150+
Description: "Internet charge type, only applicable to open CLB. Valid values are `TRAFFIC_POSTPAID_BY_HOUR`, `BANDWIDTH_POSTPAID_BY_HOUR` and `BANDWIDTH_PACKAGE`.",
151+
},
152+
"internet_bandwidth_max_out": {
153+
Type: schema.TypeInt,
154+
Computed: true,
155+
Description: "Max bandwidth out, only applicable to open CLB. Valid value ranges is [1, 2048]. Unit is MB.",
156+
},
137157
},
138158
},
139159
},
@@ -181,20 +201,26 @@ func dataSourceTencentCloudClbInstancesRead(d *schema.ResourceData, meta interfa
181201
ids := make([]string, 0, len(clbs))
182202
for _, clbInstance := range clbs {
183203
mapping := map[string]interface{}{
184-
"clb_id": *clbInstance.LoadBalancerId,
185-
"clb_name": *clbInstance.LoadBalancerName,
186-
"network_type": *clbInstance.LoadBalancerType,
187-
"status": *clbInstance.Status,
188-
"create_time": *clbInstance.CreateTime,
189-
"status_time": *clbInstance.StatusTime,
190-
"project_id": *clbInstance.ProjectId,
191-
"vpc_id": *clbInstance.VpcId,
192-
"subnet_id": *clbInstance.SubnetId,
204+
"clb_id": clbInstance.LoadBalancerId,
205+
"clb_name": clbInstance.LoadBalancerName,
206+
"network_type": clbInstance.LoadBalancerType,
207+
"status": clbInstance.Status,
208+
"create_time": clbInstance.CreateTime,
209+
"status_time": clbInstance.StatusTime,
210+
"project_id": clbInstance.ProjectId,
211+
"vpc_id": clbInstance.VpcId,
212+
"subnet_id": clbInstance.SubnetId,
193213
"clb_vips": helper.StringsInterfaces(clbInstance.LoadBalancerVips),
194-
"target_region_info_region": *clbInstance.TargetRegionInfo.Region,
195-
"target_region_info_vpc_id": *clbInstance.TargetRegionInfo.VpcId,
214+
"target_region_info_region": clbInstance.TargetRegionInfo.Region,
215+
"target_region_info_vpc_id": clbInstance.TargetRegionInfo.VpcId,
216+
"address_ip_version": clbInstance.AddressIPVersion,
217+
"vip_isp": clbInstance.VipIsp,
196218
"security_groups": helper.StringsInterfaces(clbInstance.SecureGroups),
197219
}
220+
if clbInstance.NetworkAttributes != nil {
221+
mapping["internet_charge_type"] = *clbInstance.NetworkAttributes.InternetChargeType
222+
mapping["internet_bandwidth_max_out"] = *clbInstance.NetworkAttributes.InternetMaxBandwidthOut
223+
}
198224
if clbInstance.Tags != nil {
199225
tags := make(map[string]interface{}, len(clbInstance.Tags))
200226
for _, t := range clbInstance.Tags {

tencentcloud/data_source_tc_clb_listener_rules.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,14 @@ func dataSourceTencentCloudClbListenerRules() *schema.Resource {
160160
},
161161
"scheduler": {
162162
Type: schema.TypeString,
163-
Optional: true,
164163
Computed: true,
165164
Description: "Scheduling method of the CLB listener, and available values include 'WRR', 'IP_HASH' and 'LEAST_CONN'. The default is 'WRR'. NOTES: TCP/UDP/TCP_SSL listener allows direct configuration, HTTP/HTTPS listener needs to be configured in tencentcloud_clb_listener_rule.",
166165
},
166+
"http2_switch": {
167+
Type: schema.TypeBool,
168+
Computed: true,
169+
Description: "Indicate to set HTTP2 protocol or not.",
170+
},
167171
},
168172
},
169173
},
@@ -228,11 +232,12 @@ func dataSourceTencentCloudClbListenerRulesRead(d *schema.ResourceData, meta int
228232
mapping := map[string]interface{}{
229233
"clb_id": clbId,
230234
"listener_id": listenerId,
231-
"rule_id": *rule.LocationId,
232-
"domain": *rule.Domain,
233-
"url": *rule.Url,
234-
"session_expire_time": *rule.SessionExpireTime,
235-
"scheduler": *rule.Scheduler,
235+
"rule_id": rule.LocationId,
236+
"domain": rule.Domain,
237+
"url": rule.Url,
238+
"session_expire_time": rule.SessionExpireTime,
239+
"scheduler": rule.Scheduler,
240+
"http2_switch": rule.Http2,
236241
}
237242
if rule.HealthCheck != nil {
238243
healthCheckSwitch := false

tencentcloud/resource_tc_clb_attachment.go

Lines changed: 75 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ import (
3737
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
3838
"github.com/pkg/errors"
3939
clb "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb/v20180317"
40+
sdkErrors "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/errors"
4041
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
42+
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/ratelimit"
4143
)
4244

4345
func resourceTencentCloudClbServerAttachment() *schema.Resource {
@@ -134,29 +136,41 @@ func resourceTencentCloudClbServerAttachmentCreate(d *schema.ResourceData, meta
134136
}
135137
}
136138

137-
for _, inst_ := range d.Get("targets").(*schema.Set).List() {
138-
inst := inst_.(map[string]interface{})
139-
request.Targets = append(request.Targets, clbNewTarget(inst["instance_id"], inst["port"], inst["weight"]))
140-
}
141-
err := resource.Retry(writeRetryTimeout, func() *resource.RetryError {
142-
requestId := ""
143-
result, e := meta.(*TencentCloudClient).apiV3Conn.UseClbClient().RegisterTargets(request)
144-
if e != nil {
145-
return retryError(e)
146-
} else {
147-
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]",
148-
logId, request.GetAction(), request.ToJsonString(), result.ToJsonString())
149-
requestId = *result.Response.RequestId
150-
retryErr := waitForTaskFinish(requestId, meta.(*TencentCloudClient).apiV3Conn.UseClbClient())
151-
if retryErr != nil {
152-
return resource.NonRetryableError(errors.WithStack(retryErr))
139+
insList := d.Get("targets").(*schema.Set).List()
140+
insLen := len(insList)
141+
for count := 0; count < insLen; count += 20 {
142+
//this request only support 20 targets at most once time
143+
request.Targets = make([]*clb.Target, 0, 20)
144+
for i := 0; i < 20; i++ {
145+
index := count + i
146+
if index >= insLen {
147+
break
153148
}
149+
inst := insList[index].(map[string]interface{})
150+
request.Targets = append(request.Targets, clbNewTarget(inst["instance_id"], inst["port"], inst["weight"]))
151+
}
152+
153+
err := resource.Retry(writeRetryTimeout, func() *resource.RetryError {
154+
requestId := ""
155+
ratelimit.Check(request.GetAction())
156+
result, e := meta.(*TencentCloudClient).apiV3Conn.UseClbClient().RegisterTargets(request)
157+
if e != nil {
158+
return retryError(e)
159+
} else {
160+
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]",
161+
logId, request.GetAction(), request.ToJsonString(), result.ToJsonString())
162+
requestId = *result.Response.RequestId
163+
retryErr := waitForTaskFinish(requestId, meta.(*TencentCloudClient).apiV3Conn.UseClbClient())
164+
if retryErr != nil {
165+
return resource.NonRetryableError(errors.WithStack(retryErr))
166+
}
167+
}
168+
return nil
169+
})
170+
if err != nil {
171+
log.Printf("[CRITAL]%s create CLB attachment failed, reason:%+v", logId, err)
172+
return err
154173
}
155-
return nil
156-
})
157-
if err != nil {
158-
log.Printf("[CRITAL]%s create CLB attachment failed, reason:%+v", logId, err)
159-
return err
160174
}
161175
id := fmt.Sprintf("%s#%v#%v", locationId, d.Get("listener_id"), d.Get("clb_id"))
162176
d.SetId(id)
@@ -171,7 +185,6 @@ func resourceTencentCloudClbServerAttachmentDelete(d *schema.ResourceData, meta
171185
defer clbActionMu.Unlock()
172186

173187
logId := getLogId(contextNil)
174-
ctx := context.WithValue(context.TODO(), logIdKey, logId)
175188

176189
attachmentId := d.Id()
177190

@@ -191,23 +204,49 @@ func resourceTencentCloudClbServerAttachmentDelete(d *schema.ResourceData, meta
191204
request.LocationId = helper.String(locationId)
192205
}
193206

194-
//check exists
195-
clbService := ClbService{
196-
client: meta.(*TencentCloudClient).apiV3Conn,
197-
}
198-
199-
err := resource.Retry(writeRetryTimeout, func() *resource.RetryError {
200-
e := clbService.DeleteAttachmentById(ctx, clbId, listenerId, locationId, d.Get("targets").(*schema.Set).List())
201-
if e != nil {
202-
return retryError(e)
207+
insList := d.Get("targets").(*schema.Set).List()
208+
insLen := len(insList)
209+
for count := 0; count < insLen; count += 20 {
210+
//this request only support 20 targets at most once time
211+
request.Targets = make([]*clb.Target, 0, 20)
212+
for i := 0; i < 20; i++ {
213+
index := count + i
214+
if index >= insLen {
215+
break
216+
}
217+
inst := insList[index].(map[string]interface{})
218+
request.Targets = append(request.Targets, clbNewTarget(inst["instance_id"], inst["port"], inst["weight"]))
203219
}
204220

205-
return nil
206-
})
207-
if err != nil {
208-
log.Printf("[CRITAL]%s reason[%+v]", logId, err)
209-
return err
221+
err := resource.Retry(writeRetryTimeout, func() *resource.RetryError {
222+
requestId := ""
223+
ratelimit.Check(request.GetAction())
224+
result, e := meta.(*TencentCloudClient).apiV3Conn.UseClbClient().DeregisterTargets(request)
225+
if e != nil {
226+
227+
ee, ok := e.(*sdkErrors.TencentCloudSDKError)
228+
if ok && ee.GetCode() == "InvalidParameter" {
229+
return nil
230+
}
231+
return retryError(e)
232+
233+
} else {
234+
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]",
235+
logId, request.GetAction(), request.ToJsonString(), result.ToJsonString())
236+
requestId = *result.Response.RequestId
237+
retryErr := waitForTaskFinish(requestId, meta.(*TencentCloudClient).apiV3Conn.UseClbClient())
238+
if retryErr != nil {
239+
return resource.NonRetryableError(errors.WithStack(retryErr))
240+
}
241+
}
242+
return nil
243+
})
244+
if err != nil {
245+
log.Printf("[CRITAL]%s create CLB attachment failed, reason:%+v", logId, err)
246+
return err
247+
}
210248
}
249+
211250
return nil
212251
}
213252

0 commit comments

Comments
 (0)