Skip to content

Commit 9e31032

Browse files
authored
Merge pull request #521 from gailwang/master
Support encrypt with ES & CVM data disks, support authorization with TKE
2 parents 096e692 + 3daa20b commit 9e31032

17 files changed

+67
-7
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ FEATURES:
1010
ENHANCEMENTS:
1111

1212
* Resource: `tencentcloud_mongodb_standby_instance` change example type to `POSTPAID`.
13+
* Resource: `tencentcloud_instance` add new argument `encrypt` to support data disk with encrypt
14+
* Resource: `tencentcloud_elasticsearch` add new argument `encrypt` to support disk with encrypt
15+
* Resource: `tencentcloud_kubernetes_cluster` add new argument `cam_role_name` to support authorization with instances
1316

1417
## 1.43.0 (September 18, 2020)
1518

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ require (
1515
github.com/mattn/go-colorable v0.1.6 // indirect
1616
github.com/mitchellh/go-homedir v1.1.0
1717
github.com/pkg/errors v0.9.1
18-
github.com/tencentcloud/tencentcloud-sdk-go v1.0.24
18+
github.com/tencentcloud/tencentcloud-sdk-go v1.0.25
1919
github.com/yangwenmai/ratelimit v0.0.0-20180104140304-44221c2292e1
2020
github.com/zclconf/go-cty v1.4.2 // indirect
2121
golang.org/x/sys v0.0.0-20200523222454-059865788121 // indirect

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -469,8 +469,8 @@ github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s
469469
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
470470
github.com/tdakkota/asciicheck v0.0.0-20200416190851-d7f85be797a2 h1:Xr9gkxfOP0KQWXKNqmwe8vEeSUiUj4Rlee9CMVX2ZUQ=
471471
github.com/tdakkota/asciicheck v0.0.0-20200416190851-d7f85be797a2/go.mod h1:yHp0ai0Z9gUljN3o0xMhYJnH/IcvkdTBOX2fmJ93JEM=
472-
github.com/tencentcloud/tencentcloud-sdk-go v1.0.24 h1:N/2RtegEJHVp+piscvLovjkPGTgUlgI2nN4jQVxtsCg=
473-
github.com/tencentcloud/tencentcloud-sdk-go v1.0.24/go.mod h1:asUz5BPXxgoPGaRgZaVm1iGcUAuHyYUo1nXqKa83cvI=
472+
github.com/tencentcloud/tencentcloud-sdk-go v1.0.25 h1:tLExcllerEwYTIx/58PA9r5v69uPfpc2yf6DLtDggTo=
473+
github.com/tencentcloud/tencentcloud-sdk-go v1.0.25/go.mod h1:asUz5BPXxgoPGaRgZaVm1iGcUAuHyYUo1nXqKa83cvI=
474474
github.com/tetafro/godot v0.3.7 h1:+mecr7RKrUKB5UQ1gwqEMn13sDKTyDR8KNIquB9mm+8=
475475
github.com/tetafro/godot v0.3.7/go.mod h1:/7NLHhv08H1+8DNj0MElpAACw1ajsCuf3TKNQxA5S+0=
476476
github.com/timakin/bodyclose v0.0.0-20190930140734-f7f2e9bca95e h1:RumXZ56IrCj4CL+g1b9OL/oH0QnsF976bC8xQFYUD5Q=

tencentcloud/data_source_tc_elasticsearch_instances.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,11 @@ func dataSourceTencentCloudElasticsearchInstances() *schema.Resource {
149149
Computed: true,
150150
Description: "Node disk size.",
151151
},
152+
"encrypt": {
153+
Type: schema.TypeBool,
154+
Computed: true,
155+
Description: "Decides this disk encrypted or not.",
156+
},
152157
},
153158
},
154159
},
@@ -271,6 +276,7 @@ func dataSourceTencentCloudElasticsearchInstancesRead(d *schema.ResourceData, me
271276
"type": v.Type,
272277
"disk_type": v.DiskType,
273278
"disk_size": v.DiskSize,
279+
"encrypt": *v.DiskEncrypt > 0,
274280
}
275281
infos = append(infos, info)
276282
}

tencentcloud/data_source_tc_elasticsearch_instances_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ func TestAccTencentCloudElasticsearchInstancesDataSource(t *testing.T) {
3131
resource.TestCheckResourceAttr("data.tencentcloud_elasticsearch_instances.foo", "instance_list.0.node_info_list.#", "1"),
3232
resource.TestCheckResourceAttr("data.tencentcloud_elasticsearch_instances.foo", "instance_list.0.node_info_list.0.node_num", "2"),
3333
resource.TestCheckResourceAttr("data.tencentcloud_elasticsearch_instances.foo", "instance_list.0.node_info_list.0.node_type", "ES.S1.SMALL2"),
34+
resource.TestCheckResourceAttr("data.tencentcloud_elasticsearch_instances.foo", "instance_list.0.node_info_list.0.encrypt", "false"),
3435
resource.TestCheckResourceAttrSet("data.tencentcloud_elasticsearch_instances.foo", "instance_list.0.create_time"),
3536
),
3637
},

tencentcloud/resource_tc_elasticsearch_instance.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ resource "tencentcloud_elasticsearch_instance" "foo" {
1616
node_info_list {
1717
node_num = 2
1818
node_type = "ES.S1.SMALL2"
19+
encrypt = false
1920
}
2021
2122
tags = {
@@ -83,7 +84,6 @@ func resourceTencentCloudElasticsearchInstance() *schema.Resource {
8384
},
8485
"subnet_id": {
8586
Type: schema.TypeString,
86-
Sensitive: true,
8787
Required: true,
8888
ForceNew: true,
8989
Description: "The id of a VPC subnetwork.",
@@ -128,6 +128,7 @@ func resourceTencentCloudElasticsearchInstance() *schema.Resource {
128128
Type: schema.TypeList,
129129
Optional: true,
130130
ForceNew: true,
131+
Computed: true,
131132
Description: "Details of AZs in multi-AZ deployment mode (which is required when deploy_mode is `1`).",
132133
Elem: &schema.Resource{
133134
Schema: map[string]*schema.Schema{
@@ -189,6 +190,12 @@ func resourceTencentCloudElasticsearchInstance() *schema.Resource {
189190
Default: 100,
190191
Description: "Node disk size. Unit is GB, and default value is `100`.",
191192
},
193+
"encrypt": {
194+
Type: schema.TypeBool,
195+
Optional: true,
196+
Default: false,
197+
Description: "Decides to encrypt this disk or not.",
198+
},
192199
},
193200
},
194201
},
@@ -310,6 +317,9 @@ func resourceTencentCloudElasticsearchInstanceCreate(d *schema.ResourceData, met
310317
if v := value["disk_size"].(int); v > 0 {
311318
info.DiskSize = helper.IntUint64(v)
312319
}
320+
if v := value["encrypt"].(bool); v {
321+
info.DiskEncrypt = helper.BoolToInt64Pointer(v)
322+
}
313323
request.NodeInfoList = append(request.NodeInfoList, &info)
314324
}
315325
}
@@ -421,6 +431,7 @@ func resourceTencentCloudElasticsearchInstanceRead(d *schema.ResourceData, meta
421431
info["type"] = item.Type
422432
info["disk_type"] = item.DiskType
423433
info["disk_size"] = item.DiskSize
434+
info["encrypt"] = *item.DiskEncrypt > 0
424435
nodeInfoList = append(nodeInfoList, info)
425436
}
426437
_ = d.Set("node_info_list", nodeInfoList)

tencentcloud/resource_tc_elasticsearch_instance_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"github.com/hashicorp/terraform-plugin-sdk/terraform"
1010
)
1111

12-
func TestAccTencentCloudElasticsearchInstance(t *testing.T) {
12+
func TestAccTencentCloudElasticsearchInstance_basic(t *testing.T) {
1313
t.Parallel()
1414

1515
resource.Test(t, resource.TestCase{
@@ -31,6 +31,7 @@ func TestAccTencentCloudElasticsearchInstance(t *testing.T) {
3131
resource.TestCheckResourceAttr("tencentcloud_elasticsearch_instance.foo", "node_info_list.0.node_num", "2"),
3232
resource.TestCheckResourceAttr("tencentcloud_elasticsearch_instance.foo", "node_info_list.0.node_type", "ES.S1.SMALL2"),
3333
resource.TestCheckResourceAttr("tencentcloud_elasticsearch_instance.foo", "node_info_list.0.type", "hotData"),
34+
resource.TestCheckResourceAttr("tencentcloud_elasticsearch_instance.foo", "node_info_list.0.encrypt", "false"),
3435
resource.TestCheckResourceAttr("tencentcloud_elasticsearch_instance.foo", "tags.test", "terraform"),
3536
),
3637
},

tencentcloud/resource_tc_instance.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ resource "tencentcloud_instance" "my_awesome_app" {
5757
data_disks {
5858
data_disk_type = "CLOUD_PREMIUM"
5959
data_disk_size = 50
60+
encrypt = false
6061
}
6162
6263
tags = {
@@ -301,6 +302,13 @@ func resourceTencentCloudInstance() *schema.Resource {
301302
ForceNew: true,
302303
Description: "Decides whether the disk is deleted with instance(only applied to `CLOUD_BASIC`, `CLOUD_SSD` and `CLOUD_PREMIUM` disk with `POSTPAID_BY_HOUR` instance), default is true.",
303304
},
305+
"encrypt": {
306+
Type: schema.TypeBool,
307+
Optional: true,
308+
Default: false,
309+
ForceNew: true,
310+
Description: "Decides whether the disk is encrypted. Default is `false`.",
311+
},
304312
},
305313
},
306314
},
@@ -515,6 +523,10 @@ func resourceTencentCloudInstanceCreate(d *schema.ResourceData, meta interface{}
515523
dataDisk.DeleteWithInstance = &deleteWithInstanceBool
516524
}
517525

526+
if encrypt, ok := value["encrypt"]; ok {
527+
encryptBool := encrypt.(bool)
528+
dataDisk.Encrypt = &encryptBool
529+
}
518530
request.DataDisks = append(request.DataDisks, &dataDisk)
519531
}
520532
}
@@ -719,6 +731,7 @@ func resourceTencentCloudInstanceRead(d *schema.ResourceData, meta interface{})
719731
var (
720732
snapshotId, diskId string
721733
deleteWithInstanceBool bool
734+
encryptBool bool
722735
)
723736
diskType := value["data_disk_type"].(string)
724737
diskSize := int64(value["data_disk_size"].(int))
@@ -728,7 +741,9 @@ func resourceTencentCloudInstanceRead(d *schema.ResourceData, meta interface{})
728741
if deleteWithInstance, ok := value["delete_with_instance"]; ok {
729742
deleteWithInstanceBool = deleteWithInstance.(bool)
730743
}
731-
744+
if encrypt, ok := value["encrypt"]; ok {
745+
encryptBool = encrypt.(bool)
746+
}
732747
// find the disk id value
733748
for _, disk := range instance.DataDisks {
734749
if diskType == *disk.DiskType && diskSize == *disk.DiskSize &&
@@ -746,6 +761,7 @@ func resourceTencentCloudInstanceRead(d *schema.ResourceData, meta interface{})
746761
dataDisk["data_disk_size"] = diskSize
747762
dataDisk["data_disk_id"] = diskId
748763
dataDisk["delete_with_instance"] = deleteWithInstanceBool
764+
dataDisk["encrypt"] = encryptBool
749765
dataDiskList = append(dataDiskList, dataDisk)
750766
}
751767
}

tencentcloud/resource_tc_instance_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,7 @@ resource "tencentcloud_instance" "foo" {
570570
data_disk_type = "CLOUD_PREMIUM"
571571
data_disk_size = 100
572572
delete_with_instance = true
573+
encrypt = true
573574
}
574575
575576
data_disks {

tencentcloud/resource_tc_kubernetes_cluster.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ resource "tencentcloud_kubernetes_cluster" "managed_cluster" {
8383
enhanced_monitor_service = false
8484
user_data = "dGVzdA=="
8585
password = "ZZXXccvv1212"
86+
cam_role_name = "CVM_QcsRole"
8687
}
8788
8889
labels = {
@@ -348,6 +349,12 @@ func TkeCvmCreateInfo() map[string]*schema.Schema {
348349
Optional: true,
349350
Description: "ase64-encoded User Data text, the length limit is 16KB.",
350351
},
352+
"cam_role_name": {
353+
Type: schema.TypeString,
354+
ForceNew: true,
355+
Optional: true,
356+
Description: "CAM role name authorized to access.",
357+
},
351358
}
352359
}
353360

@@ -786,6 +793,10 @@ func tkeGetCvmRunInstancesPara(dMap map[string]interface{}, meta interface{},
786793

787794
}
788795

796+
if v, ok := dMap["cam_role_name"]; ok {
797+
request.CamRoleName = helper.String(v.(string))
798+
}
799+
789800
if v, ok := dMap["data_disk"]; ok {
790801

791802
dataDisks := v.([]interface{})

0 commit comments

Comments
 (0)