Skip to content

Commit e704a37

Browse files
committed
add
1 parent e9ecd6b commit e704a37

16 files changed

+1430
-499
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ require (
6262
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/emr v1.0.1115
6363
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/es v1.0.777
6464
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/gaap v1.0.970
65-
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/kms v1.0.563
65+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/kms v1.0.1145
6666
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/lighthouse v1.0.729
6767
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/live v1.0.777
6868
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/mariadb v1.0.672

go.sum

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -942,6 +942,7 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.1133/go.mod
942942
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.1135 h1:NAu4sH5c+kGTZQ0rwhnuYjIXbentw3Np+TbwimH22uc=
943943
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.1135/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
944944
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.1136/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
945+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.1142/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
945946
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.1145 h1:DETyir/MtG+GLOD0OatzjrQTTXRguFSJo1ZtPXtbIQw=
946947
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.1145/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
947948
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/controlcenter v1.0.993 h1:WlPgXldQCxt7qi5Xrc6j6zTrsXWzN5BcOGs7Irq7fwQ=
@@ -984,6 +985,8 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/gwlb v1.0.1127 h1:1ZhrN
984985
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/gwlb v1.0.1127/go.mod h1:HSfd/mm8VyXn7VTe3tOvPgsumbsfeYcG5QgaCI1vsRk=
985986
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/kms v1.0.563 h1:FoX+MK4vHThvPO6FbP5q98zD8S3n+d5+DbtK7skl++c=
986987
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/kms v1.0.563/go.mod h1:uom4Nvi9W+Qkom0exYiJ9VWJjXwyxtPYTkKkaLMlfE0=
988+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/kms v1.0.1145 h1:/wV6YoCqDU1XXci7kxt/k+RTwx2xLzcxH4NYbC1UT6k=
989+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/kms v1.0.1145/go.mod h1:tUblC9MYww0ZRScBkLYINJ7F1fxAv/Ymmpbjn05RTPY=
987990
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/lighthouse v1.0.729 h1:WQpzm3x27Jo/5uh6/Yqe/gbJ7r2ui9hc9ST7Ml2eP9Y=
988991
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/lighthouse v1.0.729/go.mod h1:lLoyD7Z6OQQDFxDGGTe8wmirhUFZ36l5OaxzP75853Y=
989992
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/live v1.0.777 h1:8nSy6GAXc4lHj7jpSimcM2eM1wE1r7PQJM9WVzY82+U=

tencentcloud/services/kms/data_source_tc_kms_keys.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ func DataSourceTencentCloudKmsKeys() *schema.Resource {
5757
Optional: true,
5858
Description: "Tags to filter CMK.",
5959
},
60+
"hsm_cluster_id": {
61+
Type: schema.TypeString,
62+
Optional: true,
63+
Description: "The HSM cluster ID corresponding to KMS Advanced Edition (only valid for KMS Exclusive/Managed Edition service instances).",
64+
},
6065
"result_output_file": {
6166
Type: schema.TypeString,
6267
Optional: true,
@@ -133,6 +138,11 @@ func DataSourceTencentCloudKmsKeys() *schema.Resource {
133138
Computed: true,
134139
Description: "Valid when origin is `EXTERNAL`, it means the effective date of the key material.",
135140
},
141+
"hsm_cluster_id": {
142+
Type: schema.TypeString,
143+
Computed: true,
144+
Description: "The HSM cluster ID corresponding to KMS Advanced Edition (only valid for KMS Exclusive/Managed Edition service instances).",
145+
},
136146
},
137147
},
138148
},
@@ -169,6 +179,9 @@ func dataSourceTencentCloudKmsKeysRead(d *schema.ResourceData, meta interface{})
169179
if tags := helper.GetTags(d, "tags"); len(tags) > 0 {
170180
param["tag_filter"] = tags
171181
}
182+
if v, ok := d.GetOk("hsm_cluster_id"); ok {
183+
param["hsm_cluster_id"] = v.(string)
184+
}
172185

173186
kmsService := KmsService{
174187
client: meta.(tccommon.ProviderMeta).GetAPIV3Conn(),
@@ -203,6 +216,7 @@ func dataSourceTencentCloudKmsKeysRead(d *schema.ResourceData, meta interface{})
203216
"deletion_date": key.DeletionDate,
204217
"origin": key.Origin,
205218
"valid_to": key.ValidTo,
219+
"hsm_cluster_id": key.HsmClusterId,
206220
}
207221

208222
keyList = append(keyList, mapping)
Lines changed: 210 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,210 @@
1+
package kms
2+
3+
import (
4+
"context"
5+
6+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
7+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
8+
kms "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/kms/v20190118"
9+
10+
tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common"
11+
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
12+
)
13+
14+
func DataSourceTencentCloudKmsServiceStatus() *schema.Resource {
15+
return &schema.Resource{
16+
Read: dataSourceTencentCloudKmsServiceStatusRead,
17+
Schema: map[string]*schema.Schema{
18+
"service_enabled": {
19+
Type: schema.TypeBool,
20+
Computed: true,
21+
Description: "Whether the KMS service has been activated. true: activated.",
22+
},
23+
24+
"invalid_type": {
25+
Type: schema.TypeInt,
26+
Computed: true,
27+
Description: "Service unavailability type. 0: not purchased; 1: normal; 2: suspended due to arrears; 3: resource released.",
28+
},
29+
30+
"user_level": {
31+
Type: schema.TypeInt,
32+
Computed: true,
33+
Description: "0: Basic Edition, 1: Ultimate Edition.",
34+
},
35+
36+
"pro_expire_time": {
37+
Type: schema.TypeInt,
38+
Computed: true,
39+
Description: "Expiration time of the KMS Ultimate edition. It's represented in a Unix Epoch timestamp.\nNote: This field may return null, indicating that no valid values can be obtained.",
40+
},
41+
42+
"pro_renew_flag": {
43+
Type: schema.TypeInt,
44+
Computed: true,
45+
Description: "Whether to automatically renew Ultimate Edition. 0: no, 1: yes\nNote: this field may return null, indicating that no valid values can be obtained.",
46+
},
47+
48+
"pro_resource_id": {
49+
Type: schema.TypeString,
50+
Computed: true,
51+
Description: "Unique ID of the Ultimate Edition purchase record. If the Ultimate Edition is not activated, the returned value will be null.\nNote: this field may return null, indicating that no valid values can be obtained.",
52+
},
53+
54+
"exclusive_vsm_enabled": {
55+
Type: schema.TypeBool,
56+
Computed: true,
57+
Description: "Whether to activate Managed KMS\nNote: This field may return `null`, indicating that no valid value can be obtained.",
58+
},
59+
60+
"exclusive_hsm_enabled": {
61+
Type: schema.TypeBool,
62+
Computed: true,
63+
Description: "Whether to activate Exclusive KMS\nNote: This field may return `null`, indicating that no valid value can be obtained.",
64+
},
65+
66+
"subscription_info": {
67+
Type: schema.TypeString,
68+
Computed: true,
69+
Description: "KMS subscription information.\nNote: This field may return null, indicating that no valid values can be obtained.",
70+
},
71+
72+
"cmk_user_count": {
73+
Type: schema.TypeInt,
74+
Computed: true,
75+
Description: "Return the number of KMS user key usage.",
76+
},
77+
78+
"cmk_limit": {
79+
Type: schema.TypeInt,
80+
Computed: true,
81+
Description: "Return KMS user key specification quantity.",
82+
},
83+
84+
"exclusive_hsm_list": {
85+
Type: schema.TypeList,
86+
Computed: true,
87+
Description: "Return to Exclusive Cluster Group.",
88+
Elem: &schema.Resource{
89+
Schema: map[string]*schema.Schema{
90+
"hsm_cluster_id": {
91+
Type: schema.TypeInt,
92+
Required: true,
93+
Description: "Exclusive cluster ID.",
94+
},
95+
"hsm_cluster_name": {
96+
Type: schema.TypeInt,
97+
Required: true,
98+
Description: "Exclusive cluster name.",
99+
},
100+
},
101+
},
102+
},
103+
104+
"result_output_file": {
105+
Type: schema.TypeString,
106+
Optional: true,
107+
Description: "Used to save results.",
108+
},
109+
},
110+
}
111+
}
112+
113+
func dataSourceTencentCloudKmsServiceStatusRead(d *schema.ResourceData, meta interface{}) error {
114+
defer tccommon.LogElapsed("data_source.tencentcloud_kms_service_status.read")()
115+
defer tccommon.InconsistentCheck(d, meta)()
116+
117+
var (
118+
logId = tccommon.GetLogId(nil)
119+
ctx = tccommon.NewResourceLifeCycleHandleFuncContext(context.Background(), logId, d, meta)
120+
service = KmsService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()}
121+
)
122+
123+
paramMap := make(map[string]interface{})
124+
var respData *kms.GetServiceStatusResponseParams
125+
reqErr := resource.Retry(tccommon.ReadRetryTimeout, func() *resource.RetryError {
126+
result, e := service.DescribeKmsServiceStatusByFilter(ctx, paramMap)
127+
if e != nil {
128+
return tccommon.RetryError(e)
129+
}
130+
131+
respData = result
132+
return nil
133+
})
134+
135+
if reqErr != nil {
136+
return reqErr
137+
}
138+
139+
if respData.ServiceEnabled != nil {
140+
_ = d.Set("service_enabled", respData.ServiceEnabled)
141+
}
142+
143+
if respData.InvalidType != nil {
144+
_ = d.Set("invalid_type", respData.InvalidType)
145+
}
146+
147+
if respData.UserLevel != nil {
148+
_ = d.Set("user_level", respData.UserLevel)
149+
}
150+
151+
if respData.ProExpireTime != nil {
152+
_ = d.Set("pro_expire_time", respData.ProExpireTime)
153+
}
154+
155+
if respData.ProRenewFlag != nil {
156+
_ = d.Set("pro_renew_flag", respData.ProRenewFlag)
157+
}
158+
159+
if respData.ProResourceId != nil {
160+
_ = d.Set("pro_resource_id", respData.ProResourceId)
161+
}
162+
163+
if respData.ExclusiveVSMEnabled != nil {
164+
_ = d.Set("exclusive_vsm_enabled", respData.ExclusiveVSMEnabled)
165+
}
166+
167+
if respData.ExclusiveHSMEnabled != nil {
168+
_ = d.Set("exclusive_hsm_enabled", respData.ExclusiveHSMEnabled)
169+
}
170+
171+
if respData.SubscriptionInfo != nil {
172+
_ = d.Set("subscription_info", respData.SubscriptionInfo)
173+
}
174+
175+
if respData.CmkUserCount != nil {
176+
_ = d.Set("cmk_user_count", respData.CmkUserCount)
177+
}
178+
179+
if respData.CmkLimit != nil {
180+
_ = d.Set("cmk_limit", respData.CmkLimit)
181+
}
182+
183+
if respData.ExclusiveHSMList != nil {
184+
tmpList := make([]map[string]interface{}, 0, len(respData.ExclusiveHSMList))
185+
for _, item := range respData.ExclusiveHSMList {
186+
dMap := make(map[string]interface{})
187+
if item.HsmClusterId != nil {
188+
dMap["hsm_cluster_id"] = item.HsmClusterId
189+
}
190+
191+
if item.HsmClusterName != nil {
192+
dMap["hsm_cluster_name"] = item.HsmClusterName
193+
}
194+
195+
tmpList = append(tmpList, dMap)
196+
}
197+
198+
_ = d.Set("exclusive_hsm_list", tmpList)
199+
}
200+
201+
d.SetId(helper.BuildToken())
202+
output, ok := d.GetOk("result_output_file")
203+
if ok && output.(string) != "" {
204+
if e := tccommon.WriteToFile(output.(string), d); e != nil {
205+
return e
206+
}
207+
}
208+
209+
return nil
210+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Use this data source to query detailed information of KMS service_status
2+
3+
Example Usage
4+
5+
```hcl
6+
data "tencentcloud_kms_service_status" "example" {}
7+
```
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package kms_test
2+
3+
import (
4+
"testing"
5+
6+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
7+
8+
tcacctest "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/acctest"
9+
)
10+
11+
func TestAccTencentCloudKmsServiceStatusDataSource_basic(t *testing.T) {
12+
t.Parallel()
13+
resource.Test(t, resource.TestCase{
14+
PreCheck: func() {
15+
tcacctest.AccPreCheck(t)
16+
},
17+
Providers: tcacctest.AccProviders,
18+
Steps: []resource.TestStep{{
19+
Config: testAccKmsServiceStatusDataSource,
20+
Check: resource.ComposeTestCheckFunc(
21+
tcacctest.AccCheckTencentCloudDataSourceID("data.tencentcloud_kms_service_status.example"),
22+
),
23+
}},
24+
})
25+
}
26+
27+
const testAccKmsServiceStatusDataSource = `
28+
data "tencentcloud_kms_service_status" "example" {}
29+
`

tencentcloud/services/kms/resource_tc_kms_external_key.go

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ func ResourceTencentCloudKmsExternalKey() *schema.Resource {
3434
Optional: true,
3535
Description: "This value means the effective timestamp of the key material, 0 means it does not expire. Need to be greater than the current timestamp, the maximum support is 2147443200.",
3636
},
37+
"hsm_cluster_id": {
38+
Type: schema.TypeString,
39+
Optional: true,
40+
Description: "The HSM cluster ID corresponding to KMS Advanced Edition (only valid for KMS Exclusive/Managed Edition service instances).",
41+
},
3742
}
3843

3944
basic := TencentKmsBasicInfo()
@@ -66,15 +71,20 @@ func resourceTencentCloudKmsExternalKeyCreate(d *schema.ResourceData, meta inter
6671
keyType := KMS_ORIGIN_TYPE[KMS_ORIGIN_EXTERNAL]
6772
alias := d.Get("alias").(string)
6873
description := ""
74+
hsmClusterId := ""
6975
keyUsage := KMS_KEY_USAGE_ENCRYPT_DECRYPT
7076
if v, ok := d.GetOk("description"); ok {
7177
description = v.(string)
7278
}
7379

80+
if v, ok := d.GetOk("hsm_cluster_id"); ok {
81+
hsmClusterId = v.(string)
82+
}
83+
7484
var keyId string
7585
var outErr, inErr error
7686
outErr = resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError {
77-
keyId, inErr = kmsService.CreateKey(ctx, keyType, alias, description, keyUsage)
87+
keyId, inErr = kmsService.CreateKey(ctx, keyType, alias, description, keyUsage, hsmClusterId)
7888
if inErr != nil {
7989
return tccommon.RetryError(inErr)
8090
}
@@ -185,6 +195,10 @@ func resourceTencentCloudKmsExternalKeyRead(d *schema.ResourceData, meta interfa
185195
_ = d.Set("description", key.Description)
186196
_ = d.Set("valid_to", key.ValidTo)
187197
_ = d.Set("key_state", key.KeyState)
198+
if key.HsmClusterId != nil {
199+
_ = d.Set("hsm_cluster_id", key.HsmClusterId)
200+
}
201+
188202
transformKeyState(d)
189203

190204
tcClient := meta.(tccommon.ProviderMeta).GetAPIV3Conn()
@@ -206,6 +220,14 @@ func resourceTencentCloudKmsExternalKeyUpdate(d *schema.ResourceData, meta inter
206220
kmsService := KmsService{
207221
client: meta.(tccommon.ProviderMeta).GetAPIV3Conn(),
208222
}
223+
224+
immutableArgs := []string{"hsm_cluster_id"}
225+
for _, v := range immutableArgs {
226+
if d.HasChange(v) {
227+
return fmt.Errorf("argument `%s` cannot be changed", v)
228+
}
229+
}
230+
209231
d.Partial(true)
210232

211233
if d.HasChange("description") {

0 commit comments

Comments
 (0)