Skip to content

Commit 07ad91f

Browse files
authored
feat/kms (#2222)
* feat/kms * feat/kms
1 parent d4bb36c commit 07ad91f

19 files changed

+1309
-0
lines changed

.changelog/2222.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
```release-note:new-data-source
2+
tencentcloud_kms_white_box_decrypt_key
3+
```
4+
5+
```release-note:new-data-source
6+
tencentcloud_kms_white_box_device_fingerprints
7+
```
8+
9+
```release-note:new-data-source
10+
tencentcloud_kms_list_algorithms
11+
```
12+
13+
```release-note:new-resource
14+
tencentcloud_kms_cloud_resource_attachment
15+
```
16+
17+
```release-note:new-resource
18+
tencentcloud_kms_overwrite_white_box_device_fingerprints
19+
```
Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
/*
2+
Use this data source to query detailed information of kms list_algorithms
3+
4+
Example Usage
5+
6+
```hcl
7+
data "tencentcloud_kms_list_algorithms" "example" {}
8+
```
9+
*/
10+
package tencentcloud
11+
12+
import (
13+
"context"
14+
"strconv"
15+
"time"
16+
17+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
18+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
19+
kms "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/kms/v20190118"
20+
)
21+
22+
func dataSourceTencentCloudKmsListAlgorithms() *schema.Resource {
23+
return &schema.Resource{
24+
Read: dataSourceTencentCloudKmsListAlgorithmsRead,
25+
Schema: map[string]*schema.Schema{
26+
"symmetric_algorithms": {
27+
Computed: true,
28+
Type: schema.TypeList,
29+
Description: "Symmetric encryption algorithms supported in this region.",
30+
Elem: &schema.Resource{
31+
Schema: map[string]*schema.Schema{
32+
"key_usage": {
33+
Type: schema.TypeString,
34+
Computed: true,
35+
Description: "Key usage.",
36+
},
37+
"algorithm": {
38+
Type: schema.TypeString,
39+
Computed: true,
40+
Description: "Algorithm.",
41+
},
42+
},
43+
},
44+
},
45+
"asymmetric_algorithms": {
46+
Computed: true,
47+
Type: schema.TypeList,
48+
Description: "Asymmetric encryption algorithms supported in this region.",
49+
Elem: &schema.Resource{
50+
Schema: map[string]*schema.Schema{
51+
"key_usage": {
52+
Type: schema.TypeString,
53+
Computed: true,
54+
Description: "Key usage.",
55+
},
56+
"algorithm": {
57+
Type: schema.TypeString,
58+
Computed: true,
59+
Description: "Algorithm.",
60+
},
61+
},
62+
},
63+
},
64+
"asymmetric_sign_verify_algorithms": {
65+
Computed: true,
66+
Type: schema.TypeList,
67+
Description: "Asymmetric signature verification algorithms supported in this region.",
68+
Elem: &schema.Resource{
69+
Schema: map[string]*schema.Schema{
70+
"key_usage": {
71+
Type: schema.TypeString,
72+
Computed: true,
73+
Description: "Key usage.",
74+
},
75+
"algorithm": {
76+
Type: schema.TypeString,
77+
Computed: true,
78+
Description: "Algorithm.",
79+
},
80+
},
81+
},
82+
},
83+
"result_output_file": {
84+
Type: schema.TypeString,
85+
Optional: true,
86+
Description: "Used to save results.",
87+
},
88+
},
89+
}
90+
}
91+
92+
func dataSourceTencentCloudKmsListAlgorithmsRead(d *schema.ResourceData, meta interface{}) error {
93+
defer logElapsed("data_source.tencentcloud_kms_list_algorithms.read")()
94+
defer inconsistentCheck(d, meta)()
95+
96+
var (
97+
logId = getLogId(contextNil)
98+
ctx = context.WithValue(context.TODO(), logIdKey, logId)
99+
service = KmsService{client: meta.(*TencentCloudClient).apiV3Conn}
100+
listAlgorithms *kms.ListAlgorithmsResponseParams
101+
)
102+
103+
err := resource.Retry(readRetryTimeout, func() *resource.RetryError {
104+
result, e := service.DescribeKmsListAlgorithmsByFilter(ctx)
105+
if e != nil {
106+
return retryError(e)
107+
}
108+
109+
listAlgorithms = result
110+
return nil
111+
})
112+
113+
if err != nil {
114+
return err
115+
}
116+
117+
if listAlgorithms.SymmetricAlgorithms != nil {
118+
tmpList := make([]map[string]interface{}, 0, len(listAlgorithms.SymmetricAlgorithms))
119+
for _, item := range listAlgorithms.SymmetricAlgorithms {
120+
itemMap := map[string]interface{}{}
121+
if item.KeyUsage != nil {
122+
itemMap["key_usage"] = item.KeyUsage
123+
}
124+
125+
if item.Algorithm != nil {
126+
itemMap["algorithm"] = item.Algorithm
127+
}
128+
129+
tmpList = append(tmpList, itemMap)
130+
}
131+
132+
_ = d.Set("symmetric_algorithms", tmpList)
133+
}
134+
135+
if listAlgorithms.AsymmetricAlgorithms != nil {
136+
tmpList := make([]map[string]interface{}, 0, len(listAlgorithms.AsymmetricAlgorithms))
137+
for _, item := range listAlgorithms.AsymmetricAlgorithms {
138+
itemMap := map[string]interface{}{}
139+
if item.KeyUsage != nil {
140+
itemMap["key_usage"] = item.KeyUsage
141+
}
142+
143+
if item.Algorithm != nil {
144+
itemMap["algorithm"] = item.Algorithm
145+
}
146+
147+
tmpList = append(tmpList, itemMap)
148+
}
149+
150+
_ = d.Set("asymmetric_algorithms", tmpList)
151+
}
152+
153+
if listAlgorithms.AsymmetricSignVerifyAlgorithms != nil {
154+
tmpList := make([]map[string]interface{}, 0, len(listAlgorithms.AsymmetricSignVerifyAlgorithms))
155+
for _, item := range listAlgorithms.AsymmetricSignVerifyAlgorithms {
156+
itemMap := map[string]interface{}{}
157+
if item.KeyUsage != nil {
158+
itemMap["key_usage"] = item.KeyUsage
159+
}
160+
161+
if item.Algorithm != nil {
162+
itemMap["algorithm"] = item.Algorithm
163+
}
164+
165+
tmpList = append(tmpList, itemMap)
166+
}
167+
168+
_ = d.Set("asymmetric_sign_verify_algorithms", tmpList)
169+
}
170+
171+
d.SetId(strconv.FormatInt(time.Now().Unix(), 10))
172+
output, ok := d.GetOk("result_output_file")
173+
if ok && output.(string) != "" {
174+
if e := writeToFile(output.(string), d); e != nil {
175+
return e
176+
}
177+
}
178+
179+
return nil
180+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package tencentcloud
2+
3+
import (
4+
"testing"
5+
6+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
7+
)
8+
9+
// go test -i; go test -test.run TestAccTencentCloudKmsListAlgorithmsDataSource_basic -v
10+
func TestAccTencentCloudKmsListAlgorithmsDataSource_basic(t *testing.T) {
11+
t.Parallel()
12+
resource.Test(t, resource.TestCase{
13+
PreCheck: func() {
14+
testAccPreCheck(t)
15+
},
16+
Providers: testAccProviders,
17+
Steps: []resource.TestStep{
18+
{
19+
Config: testAccKmsListAlgorithmsDataSource,
20+
Check: resource.ComposeTestCheckFunc(
21+
testAccCheckTencentCloudDataSourceID("data.tencentcloud_kms_list_algorithms.example"),
22+
),
23+
},
24+
},
25+
})
26+
}
27+
28+
const testAccKmsListAlgorithmsDataSource = `
29+
data "tencentcloud_kms_list_algorithms" "example" {}
30+
`
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/*
2+
Use this data source to query detailed information of kms white_box_decrypt_key
3+
4+
Example Usage
5+
6+
```hcl
7+
data "tencentcloud_kms_white_box_decrypt_key" "example" {
8+
key_id = "244dab8c-6dad-11ea-80c6-5254006d0810"
9+
}
10+
```
11+
*/
12+
package tencentcloud
13+
14+
import (
15+
"context"
16+
17+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
18+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
19+
kms "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/kms/v20190118"
20+
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
21+
)
22+
23+
func dataSourceTencentCloudKmsWhiteBoxDecryptKey() *schema.Resource {
24+
return &schema.Resource{
25+
Read: dataSourceTencentCloudKmsWhiteBoxDecryptKeyRead,
26+
Schema: map[string]*schema.Schema{
27+
"key_id": {
28+
Required: true,
29+
Type: schema.TypeString,
30+
Description: "Globally unique identifier for the white box key.",
31+
},
32+
"decrypt_key": {
33+
Computed: true,
34+
Type: schema.TypeString,
35+
Description: "White box decryption key, base64 encoded.",
36+
},
37+
"result_output_file": {
38+
Type: schema.TypeString,
39+
Optional: true,
40+
Description: "Used to save results.",
41+
},
42+
},
43+
}
44+
}
45+
46+
func dataSourceTencentCloudKmsWhiteBoxDecryptKeyRead(d *schema.ResourceData, meta interface{}) error {
47+
defer logElapsed("data_source.tencentcloud_kms_white_box_decrypt_key.read")()
48+
defer inconsistentCheck(d, meta)()
49+
50+
var (
51+
logId = getLogId(contextNil)
52+
ctx = context.WithValue(context.TODO(), logIdKey, logId)
53+
service = KmsService{client: meta.(*TencentCloudClient).apiV3Conn}
54+
whiteBoxDecryptKey *kms.DescribeWhiteBoxDecryptKeyResponseParams
55+
keyId string
56+
)
57+
58+
paramMap := make(map[string]interface{})
59+
if v, ok := d.GetOk("key_id"); ok {
60+
paramMap["KeyId"] = helper.String(v.(string))
61+
keyId = v.(string)
62+
}
63+
64+
err := resource.Retry(readRetryTimeout, func() *resource.RetryError {
65+
result, e := service.DescribeKmsWhiteBoxDecryptKeyByFilter(ctx, paramMap)
66+
if e != nil {
67+
return retryError(e)
68+
}
69+
70+
whiteBoxDecryptKey = result
71+
return nil
72+
})
73+
74+
if err != nil {
75+
return err
76+
}
77+
78+
if whiteBoxDecryptKey.DecryptKey != nil {
79+
_ = d.Set("decrypt_key", whiteBoxDecryptKey.DecryptKey)
80+
}
81+
82+
d.SetId(keyId)
83+
output, ok := d.GetOk("result_output_file")
84+
if ok && output.(string) != "" {
85+
if e := writeToFile(output.(string), d); e != nil {
86+
return e
87+
}
88+
}
89+
90+
return nil
91+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package tencentcloud
2+
3+
import (
4+
"testing"
5+
6+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
7+
)
8+
9+
// go test -i; go test -test.run TestAccTencentCloudKmsWhiteBoxDecryptKeyDataSource_basic -v
10+
func TestAccTencentCloudKmsWhiteBoxDecryptKeyDataSource_basic(t *testing.T) {
11+
t.Parallel()
12+
resource.Test(t, resource.TestCase{
13+
PreCheck: func() {
14+
testAccPreCheck(t)
15+
},
16+
Providers: testAccProviders,
17+
Steps: []resource.TestStep{
18+
{
19+
Config: testAccKmsWhiteBoxDecryptKeyDataSource,
20+
Check: resource.ComposeTestCheckFunc(
21+
testAccCheckTencentCloudDataSourceID("data.tencentcloud_kms_white_box_decrypt_key.example"),
22+
resource.TestCheckResourceAttrSet("data.tencentcloud_kms_white_box_decrypt_key.example", "key_id"),
23+
),
24+
},
25+
},
26+
})
27+
}
28+
29+
const testAccKmsWhiteBoxDecryptKeyDataSource = `
30+
data "tencentcloud_kms_white_box_decrypt_key" "example" {
31+
key_id = "8731f440-66c1-11ee-beb0-52540036aed2"
32+
}
33+
`

0 commit comments

Comments
 (0)