Skip to content

Commit c323e8f

Browse files
committed
merge master
2 parents ef53108 + 18dd65a commit c323e8f

21 files changed

+395
-161
lines changed

CHANGELOG.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
1-
## 1.21.2 (Unreleased)
1+
## 1.21.3 (Unreleased)
2+
## 1.21.2 (October 29, 2019)
3+
4+
BUG FIXES:
5+
6+
* Resource: `tencentcloud_gaap_realserver` add ip/domain exists check
7+
* Resource: `tencentcloud_kubernetes_cluster` add error handling logic and optional argument `tags`.
8+
* Resource: `tencentcloud_kubernetes_scale_worker` add error handling logic.
9+
* Data Source: `tencentcloud_kubernetes_clusters` add optional argument `tags`.
10+
211
## 1.21.1 (October 23, 2019)
312

413
ENHANCEMENTS:

examples/tencentcloud-tke/main.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ resource "tencentcloud_kubernetes_cluster" "managed_cluster" {
3030
}
3131

3232
cluster_deploy_type = "MANAGED_CLUSTER"
33+
34+
tags = {
35+
"test" = "test"
36+
}
3337
}
3438

3539
#examples for INDEPENDENT_CLUSTER cluster

gendoc/gendoc_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,15 @@ resource "tencentcloud_cos_bucket" "mycos" {
8383
func TestContainsBigSymbol(t *testing.T) {
8484
cases := "中国人繁體字abcABC~!@#¥%…&()—+{}|:“”《》?1234567890-=【】\;‘’,。、 "
8585
for _, c := range cases {
86-
if ContainsBigSymbol(string(c)) == "" {
86+
if containsBigSymbol(string(c)) == "" {
8787
t.Log(c)
8888
t.Errorf("Expected %s to be Chinese symbol", string(c))
8989
}
9090
}
9191

9292
cases = "abcABC~!@#$%^&*()_+{}|:\"<>?`1234567890-=[]\\;',./ \t\r\n"
9393
for _, c := range cases {
94-
if ContainsBigSymbol(string(c)) != "" {
94+
if containsBigSymbol(string(c)) != "" {
9595
t.Errorf("Expected %s not to be Chinese symbol", string(c))
9696
}
9797
}

gendoc/main.go

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,11 @@ func genIdx(fpath string) {
6363
Resources [][]string
6464
}
6565

66-
resources := ""
67-
dataSources := []Index{}
68-
sources := []Index{}
66+
var (
67+
resources string
68+
dataSources []Index
69+
sources []Index
70+
)
6971

7072
fname := "provider.go"
7173
message("[START]get description from file: %s\n", fname)
@@ -212,10 +214,21 @@ func genDoc(dtype, fpath, name string, resource *schema.Resource) {
212214
data["description_short"] = description
213215
}
214216

215-
requiredArgs := []string{}
216-
optionalArgs := []string{}
217-
attributes := []string{}
218-
subStruct := []string{}
217+
var (
218+
requiredArgs []string
219+
optionalArgs []string
220+
attributes []string
221+
subStruct []string
222+
)
223+
224+
if _, ok := resource.Schema["result_output_file"]; dtype == "data_source" && !ok {
225+
if resource.DeprecationMessage != "" {
226+
message("[SKIP!]argument 'result_output_file' is missing, skip: %s", fname)
227+
} else {
228+
message("[FAIL!]argument 'result_output_file' is missing: %s", fname)
229+
os.Exit(1)
230+
}
231+
}
219232

220233
for k, v := range resource.Schema {
221234
if v.Description == "" {
@@ -307,7 +320,7 @@ func genDoc(dtype, fpath, name string, resource *schema.Resource) {
307320

308321
// getAttributes get attributes from schema
309322
func getAttributes(step int, k string, v *schema.Schema) []string {
310-
attributes := []string{}
323+
var attributes []string
311324
ident := strings.Repeat(" ", step*2)
312325

313326
if v.Description == "" {
@@ -321,14 +334,14 @@ func getAttributes(step int, k string, v *schema.Schema) []string {
321334
v.Description = fmt.Sprintf("(**Deprecated**) %s %s", v.Deprecated, v.Description)
322335
}
323336
if _, ok := v.Elem.(*schema.Resource); ok {
324-
listAttributes := []string{}
337+
var listAttributes []string
325338
for kk, vv := range v.Elem.(*schema.Resource).Schema {
326339
attrs := getAttributes(step+1, kk, vv)
327340
if len(attrs) > 0 {
328341
listAttributes = append(listAttributes, attrs...)
329342
}
330343
}
331-
slistAttributes := ""
344+
var slistAttributes string
332345
sort.Strings(listAttributes)
333346
if len(listAttributes) > 0 {
334347
slistAttributes = "\n" + strings.Join(listAttributes, "\n")
@@ -356,20 +369,22 @@ func getFileDescription(fname string) (string, error) {
356369

357370
// getSubStruct get sub structure from go file
358371
func getSubStruct(step int, k string, v *schema.Schema) []string {
359-
subStructs := []string{}
372+
var subStructs []string
360373

361374
if v.Description == "" {
362375
return subStructs
363376
} else {
364377
checkDescription(k, v.Description)
365378
}
366379

367-
subStruct := []string{}
380+
var subStruct []string
368381
if v.Type == schema.TypeMap || v.Type == schema.TypeList || v.Type == schema.TypeSet {
369382
if _, ok := v.Elem.(*schema.Resource); ok {
370383
subStruct = append(subStruct, fmt.Sprintf("\nThe `%s` object supports the following:\n", k))
371-
requiredArgs := []string{}
372-
optionalArgs := []string{}
384+
var (
385+
requiredArgs []string
386+
optionalArgs []string
387+
)
373388
for kk, vv := range v.Elem.(*schema.Resource).Schema {
374389
if vv.Required {
375390
opt := "Required"
@@ -402,7 +417,7 @@ func getSubStruct(step int, k string, v *schema.Schema) []string {
402417

403418
// formatHCL format HLC code
404419
func formatHCL(s string) string {
405-
rr := []string{}
420+
var rr []string
406421

407422
s = strings.TrimSpace(s)
408423
m := hclMatch.FindAllStringSubmatch(s, -1)

go.sum

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,7 @@ github.com/shurcooL/go v0.0.0-20180423040247-9e1955d9fb6e/go.mod h1:TDJrrUr11Vxr
496496
github.com/shurcooL/go-goon v0.0.0-20170922171312-37c2f522c041 h1:llrF3Fs4018ePo4+G/HV/uQUqEI1HMDjCeOf2V6puPc=
497497
github.com/shurcooL/go-goon v0.0.0-20170922171312-37c2f522c041/go.mod h1:N5mDOmsrJOB+vfqUK+7DmDyjhSLIIBnXo9lvZJj3MWQ=
498498
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
499+
github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4=
499500
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
500501
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM=
501502
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=

tencentcloud/connectivity/client.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ type TencentCloudClient struct {
4444
mongodbConn *mongodb.Client
4545
tkeConn *tke.Client
4646
camConn *cam.Client
47-
gaapCoon *gaap.Client
48-
sslCoon *ssl.Client
47+
gaapConn *gaap.Client
48+
sslConn *ssl.Client
4949
}
5050

5151
// NewTencentCloudClient returns a new TencentCloudClient
@@ -245,28 +245,28 @@ func (me *TencentCloudClient) UseTkeClient() *tke.Client {
245245

246246
// UseGaapClient returns gaap client for service
247247
func (me *TencentCloudClient) UseGaapClient() *gaap.Client {
248-
if me.gaapCoon != nil {
249-
return me.gaapCoon
248+
if me.gaapConn != nil {
249+
return me.gaapConn
250250
}
251251

252252
cpf := newTencentCloudClientProfile(300)
253-
me.gaapCoon, _ = gaap.NewClient(me.Credential, me.Region, cpf)
254-
me.gaapCoon.WithHttpTransport(&LogRoundTripper{})
253+
me.gaapConn, _ = gaap.NewClient(me.Credential, me.Region, cpf)
254+
me.gaapConn.WithHttpTransport(&LogRoundTripper{})
255255

256-
return me.gaapCoon
256+
return me.gaapConn
257257
}
258258

259259
// UseSslClient returns ssl client for service
260260
func (me *TencentCloudClient) UseSslClient() *ssl.Client {
261-
if me.sslCoon != nil {
262-
return me.sslCoon
261+
if me.sslConn != nil {
262+
return me.sslConn
263263
}
264264

265265
cpf := newTencentCloudClientProfile(300)
266-
me.sslCoon, _ = ssl.NewClient(me.Credential, me.Region, cpf)
267-
me.sslCoon.WithHttpTransport(&LogRoundTripper{})
266+
me.sslConn, _ = ssl.NewClient(me.Credential, me.Region, cpf)
267+
me.sslConn.WithHttpTransport(&LogRoundTripper{})
268268

269-
return me.sslCoon
269+
return me.sslConn
270270
}
271271

272272
// UseCamClient returns cam client for service

tencentcloud/data_source_tc_image.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,11 @@ func dataSourceTencentCloudSourceImages() *schema.Resource {
101101
ValidateFunc: validateNotEmpty,
102102
Description: "A string to apply with fuzzy match to the os_name atrribute on the image list returned by TencentCloud. **NOTE**: when os_name is provided, highest priority is applied in this field instead of `image_name_regex`.",
103103
},
104+
"result_output_file": {
105+
Type: schema.TypeString,
106+
Optional: true,
107+
Description: "Used to save results.",
108+
},
104109
"image_id": {
105110
Type: schema.TypeString,
106111
Computed: true,
@@ -197,12 +202,17 @@ func dataSourceTencentCloudImagesRead(d *schema.ResourceData, meta interface{})
197202
return errors.New("No image found")
198203
}
199204

200-
id := dataResourceIdHash(resultImageId)
201-
d.SetId(id)
202-
205+
d.SetId(dataResourceIdHash(resultImageId))
203206
if err := d.Set("image_id", resultImageId); err != nil {
204207
return err
205208
}
206209

210+
output, ok := d.GetOk("result_output_file")
211+
if ok && output.(string) != "" {
212+
if err = writeToFile(output.(string), resultImageId); err != nil {
213+
return err
214+
}
215+
}
216+
207217
return nil
208218
}

tencentcloud/data_source_tc_kubernetes_clusters.go

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,23 @@ Use this data source to query detailed information of kubernetes clusters.
44
Example Usage
55
66
```hcl
7-
data "tencentcloud_kubernetes_clusters" "name" {
8-
cluster_name ="terraform"
7+
data "tencentcloud_kubernetes_clusters" "name" {
8+
cluster_name ="terraform"
99
}
1010
11-
data "tencentcloud_kubernetes_clusters" "id" {
12-
cluster_id ="cls-godovr32"
11+
data "tencentcloud_kubernetes_clusters" "id" {
12+
cluster_id ="cls-godovr32"
1313
}
1414
```
1515
*/
1616
package tencentcloud
1717

1818
import (
1919
"context"
20+
"log"
21+
2022
"github.com/hashicorp/terraform/helper/resource"
2123
"github.com/hashicorp/terraform/helper/schema"
22-
"log"
2324
)
2425

2526
func tkeClusterInfo() map[string]*schema.Schema {
@@ -93,7 +94,7 @@ func tkeClusterInfo() map[string]*schema.Schema {
9394
"cluster_node_num": {
9495
Type: schema.TypeInt,
9596
Computed: true,
96-
Description: "Number of nodes in the cluster.",
97+
Description: "Number of nodes in the cluster.",
9798
},
9899
"worker_instances_list": {
99100
Type: schema.TypeList,
@@ -103,6 +104,11 @@ func tkeClusterInfo() map[string]*schema.Schema {
103104
Schema: tkeCvmState(),
104105
},
105106
},
107+
"tags": {
108+
Type: schema.TypeMap,
109+
Computed: true,
110+
Description: "Tags of the cluster.",
111+
},
106112
}
107113

108114
for k, v := range tkeSecurityInfo() {
@@ -128,12 +134,17 @@ func dataSourceTencentCloudKubernetesClusters() *schema.Resource {
128134
Optional: true,
129135
Description: "Name of the cluster. Conflict with cluster_id, can not be set at the same time.",
130136
},
131-
137+
"tags": {
138+
Type: schema.TypeMap,
139+
Optional: true,
140+
Description: "Tags of the cluster.",
141+
},
132142
"result_output_file": {
133143
Type: schema.TypeString,
134144
Optional: true,
135145
Description: "Used to save results.",
136146
},
147+
137148
"list": {
138149
Type: schema.TypeList,
139150
Computed: true,
@@ -156,8 +167,10 @@ func dataSourceTencentCloudKubernetesClustersRead(d *schema.ResourceData, meta i
156167
client: meta.(*TencentCloudClient).apiV3Conn,
157168
}
158169

159-
id := ""
160-
name := ""
170+
var (
171+
id string
172+
name string
173+
)
161174

162175
if v, ok := d.GetOk("cluster_id"); ok {
163176
id = v.(string)
@@ -167,8 +180,9 @@ func dataSourceTencentCloudKubernetesClustersRead(d *schema.ResourceData, meta i
167180
name = v.(string)
168181
}
169182

170-
infos, err := service.DescribeClusters(ctx, id, name)
183+
tags := getTags(d, "tags")
171184

185+
infos, err := service.DescribeClusters(ctx, id, name)
172186
if err != nil && id == "" {
173187
err = resource.Retry(readRetryTimeout, func() *resource.RetryError {
174188
infos, err = service.DescribeClusters(ctx, id, name)
@@ -193,7 +207,16 @@ func dataSourceTencentCloudKubernetesClustersRead(d *schema.ResourceData, meta i
193207
}
194208
}
195209

210+
LOOP:
196211
for _, info := range infos {
212+
if len(tags) > 0 {
213+
for k, v := range tags {
214+
if info.Tags[k] != v {
215+
continue LOOP
216+
}
217+
}
218+
}
219+
197220
var infoMap = map[string]interface{}{}
198221
infoMap["cluster_name"] = info.ClusterName
199222
infoMap["cluster_desc"] = info.ClusterDescription
@@ -208,6 +231,7 @@ func dataSourceTencentCloudKubernetesClustersRead(d *schema.ResourceData, meta i
208231
infoMap["cluster_max_pod_num"] = info.MaxClusterServiceNum
209232
infoMap["cluster_max_service_num"] = info.MaxClusterServiceNum
210233
infoMap["cluster_node_num"] = info.ClusterNodeNum
234+
infoMap["tags"] = info.Tags
211235

212236
_, workers, err := service.DescribeClusterInstances(ctx, info.ClusterId)
213237
if err != nil {

0 commit comments

Comments
 (0)