Skip to content

Commit 1bc88de

Browse files
committed
Resource: tencentcloud_kubernetes_cluster_attachment add new argument worker_config to support config with existing instances.
1 parent 56ee716 commit 1bc88de

File tree

6 files changed

+187
-1
lines changed

6 files changed

+187
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
## 1.39.0 (Unreleased)
2+
3+
ENHANCEMENTS:
4+
* Resource: `tencentcloud_kubernetes_cluster_attachment` add new argument `worker_config` to support config with existing instances.
5+
26
## 1.38.2 (July 03, 2020)
37

48
BUG FIXES:

tencentcloud/internal/helper/transform.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,12 @@ func BoolToInt64Pointer(s bool) (i *uint64) {
100100
i = &result
101101
return
102102
}
103+
104+
func BoolToInt64(s bool) (i *int64) {
105+
result := int64(0)
106+
if s {
107+
result = int64(1)
108+
}
109+
i = &result
110+
return
111+
}

tencentcloud/resource_tc_cam_role.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,30 @@ EOF
2525
}
2626
```
2727
28+
Created with SAML provider
29+
30+
```hcl
31+
resource "tencentcloud_cam_role" "boo" {
32+
name = "cam-role-test"
33+
document = <<EOF
34+
{
35+
"version": "2.0",
36+
"statement": [
37+
{
38+
"action": ["name/sts:AssumeRole"],
39+
"effect": "allow",
40+
"principal": {
41+
"federated": ["qcs::cam::uin/3374997817:saml-provider/XXXX-oooo"]
42+
}
43+
}
44+
]
45+
}
46+
EOF
47+
description = "test"
48+
console_login = true
49+
}
50+
```
51+
2852
Import
2953
3054
CAM role can be imported using the id, e.g.

tencentcloud/resource_tc_kubernetes_cluster_attachment.go

Lines changed: 112 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,63 @@ import (
108108
"github.com/terraform-providers/terraform-provider-tencentcloud/tencentcloud/ratelimit"
109109
)
110110

111+
func TkeInstanceAdvancedSetting() map[string]*schema.Schema {
112+
return map[string]*schema.Schema{
113+
"mount_target": {
114+
Type: schema.TypeString,
115+
Optional: true,
116+
ForceNew: true,
117+
Description: "Mount target. Default is not mounting.",
118+
},
119+
"docker_graph_path": {
120+
Type: schema.TypeString,
121+
Optional: true,
122+
ForceNew: true,
123+
Default: "/var/lib/docker",
124+
Description: "Docker graph path. Default is `/var/lib/docker`.",
125+
},
126+
"data_disk": {
127+
Type: schema.TypeList,
128+
ForceNew: true,
129+
Optional: true,
130+
MaxItems: 11,
131+
Description: "Configurations of data disk.",
132+
Elem: &schema.Resource{
133+
Schema: map[string]*schema.Schema{
134+
"disk_type": {
135+
Type: schema.TypeString,
136+
ForceNew: true,
137+
Optional: true,
138+
Default: SYSTEM_DISK_TYPE_CLOUD_PREMIUM,
139+
ValidateFunc: validateAllowedStringValue(SYSTEM_DISK_ALLOW_TYPE),
140+
Description: "Types of disk, available values: CLOUD_PREMIUM and CLOUD_SSD.",
141+
},
142+
"disk_size": {
143+
Type: schema.TypeInt,
144+
ForceNew: true,
145+
Optional: true,
146+
Default: 0,
147+
Description: "Volume of disk in GB. Default is 0.",
148+
},
149+
},
150+
},
151+
},
152+
"user_script": {
153+
Type: schema.TypeString,
154+
ForceNew: true,
155+
Optional: true,
156+
Description: "Ase64-encoded User Data text, the length limit is 16KB.",
157+
},
158+
"is_schedule": {
159+
Type: schema.TypeBool,
160+
ForceNew: true,
161+
Optional: true,
162+
Default: true,
163+
Description: "Indicate to schedule the adding node or not. Default is true.",
164+
},
165+
}
166+
}
167+
111168
func resourceTencentCloudTkeClusterAttachment() *schema.Resource {
112169
schemaBody := map[string]*schema.Schema{
113170
"cluster_id": {
@@ -138,7 +195,16 @@ func resourceTencentCloudTkeClusterAttachment() *schema.Resource {
138195
Elem: &schema.Schema{Type: schema.TypeString},
139196
Description: "The key pair to use for the instance, it looks like skey-16jig7tx, it should be set if `password` not set.",
140197
},
141-
198+
"worker_config": {
199+
Type: schema.TypeList,
200+
ForceNew: true,
201+
MaxItems: 1,
202+
Optional: true,
203+
Elem: &schema.Resource{
204+
Schema: TkeInstanceAdvancedSetting(),
205+
},
206+
Description: "Deploy the machine configuration information of the 'WORKER', commonly used to attach existing instances.",
207+
},
142208
//compute
143209
"security_groups": {
144210
Type: schema.TypeSet,
@@ -162,6 +228,43 @@ func resourceTencentCloudTkeClusterAttachment() *schema.Resource {
162228
}
163229
}
164230

231+
func tkeGetInstanceAdvancedPara(dMap map[string]interface{}, meta interface{}) (setting tke.InstanceAdvancedSettings) {
232+
setting = tke.InstanceAdvancedSettings{}
233+
if v, ok := dMap["mount_target"]; ok {
234+
setting.MountTarget = helper.String(v.(string))
235+
}
236+
237+
if v, ok := dMap["data_disk"]; ok {
238+
239+
dataDisks := v.([]interface{})
240+
setting.DataDisks = make([]*tke.DataDisk, 0, len(dataDisks))
241+
242+
for _, d := range dataDisks {
243+
var (
244+
value = d.(map[string]interface{})
245+
diskType = value["disk_type"].(string)
246+
diskSize = int64(value["disk_size"].(int))
247+
dataDisk = tke.DataDisk{
248+
DiskType: &diskType,
249+
DiskSize: &diskSize,
250+
}
251+
)
252+
setting.DataDisks = append(setting.DataDisks, &dataDisk)
253+
}
254+
}
255+
256+
setting.Unschedulable = helper.BoolToInt64(!dMap["is_schedule"].(bool))
257+
258+
if v, ok := dMap["user_script"]; ok {
259+
setting.UserScript = helper.String(v.(string))
260+
}
261+
262+
if v, ok := dMap["docker_graph_path"]; ok {
263+
setting.DockerGraphPath = helper.String(v.(string))
264+
}
265+
266+
return setting
267+
}
165268
func resourceTencentCloudTkeClusterAttachmentRead(d *schema.ResourceData, meta interface{}) error {
166269
defer logElapsed("resource.tencentcloud_kubernetes_cluster_attachment.read")()
167270
defer inconsistentCheck(d, meta)()
@@ -282,6 +385,14 @@ func resourceTencentCloudTkeClusterAttachmentCreate(d *schema.ResourceData, meta
282385
}
283386

284387
request.InstanceAdvancedSettings = &tke.InstanceAdvancedSettings{}
388+
if workConfig, ok := d.GetOk("worker_config"); ok {
389+
workConfigList := workConfig.([]interface{})
390+
if len(workConfigList) == 1 {
391+
workConfigPara := workConfigList[0].(map[string]interface{})
392+
setting := tkeGetInstanceAdvancedPara(workConfigPara, meta)
393+
request.InstanceAdvancedSettings = &setting
394+
}
395+
}
285396

286397
request.InstanceAdvancedSettings.Labels = GetTkeLabels(d, "labels")
287398

website/docs/r/cam_role.html.markdown

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,30 @@ EOF
3434
}
3535
```
3636

37+
Created with SAML provider
38+
39+
```hcl
40+
resource "tencentcloud_cam_role" "boo" {
41+
name = "cam-role-test"
42+
document = <<EOF
43+
{
44+
"version": "2.0",
45+
"statement": [
46+
{
47+
"action": ["name/sts:AssumeRole"],
48+
"effect": "allow",
49+
"principal": {
50+
"federated": ["qcs::cam::uin/3374997817:saml-provider/XXXX-oooo"]
51+
}
52+
}
53+
]
54+
}
55+
EOF
56+
description = "test"
57+
console_login = true
58+
}
59+
```
60+
3761
## Argument Reference
3862

3963
The following arguments are supported:

website/docs/r/kubernetes_cluster_attachment.html.markdown

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,20 @@ The following arguments are supported:
108108
* `key_ids` - (Optional, ForceNew) The key pair to use for the instance, it looks like skey-16jig7tx, it should be set if `password` not set.
109109
* `labels` - (Optional, ForceNew) Labels of tke attachment exits cvm.
110110
* `password` - (Optional, ForceNew) Password to access, should be set if `key_ids` not set.
111+
* `worker_config` - (Optional, ForceNew) Deploy the machine configuration information of the 'WORKER', commonly used to attach existing instances.
112+
113+
The `data_disk` object supports the following:
114+
115+
* `disk_size` - (Optional, ForceNew) Volume of disk in GB. Default is 0.
116+
* `disk_type` - (Optional, ForceNew) Types of disk, available values: CLOUD_PREMIUM and CLOUD_SSD.
117+
118+
The `worker_config` object supports the following:
119+
120+
* `data_disk` - (Optional, ForceNew) Configurations of data disk.
121+
* `docker_graph_path` - (Optional, ForceNew) Docker graph path. Default is `/var/lib/docker`.
122+
* `is_schedule` - (Optional, ForceNew) Indicate to schedule the adding node or not. Default is true.
123+
* `mount_target` - (Optional, ForceNew) Mount target. Default is not mounting.
124+
* `user_script` - (Optional, ForceNew) Ase64-encoded User Data text, the length limit is 16KB.
111125

112126
## Attributes Reference
113127

0 commit comments

Comments
 (0)