Skip to content

Commit 9174476

Browse files
authored
fix(kms): [123689078] kms support hsm_cluster_id (#3327)
* add * add * add * add
1 parent fc8ef63 commit 9174476

24 files changed

+1574
-510
lines changed

.changelog/3327.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
```release-note:new-data-source
2+
tencentcloud_kms_service_status
3+
```
4+
5+
```release-note:enhancement
6+
resource/tencentcloud_kms_key: support `hsm_cluster_id`
7+
```
8+
9+
```release-note:enhancement
10+
resource/tencentcloud_kms_external_key: support `hsm_cluster_id`
11+
```
12+
13+
```release-note:enhancement
14+
datasource/tencentcloud_kms_keys: support `hsm_cluster_id`
15+
```

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/provider.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -890,6 +890,7 @@ func Provider() *schema.Provider {
890890
"tencentcloud_kms_white_box_decrypt_key": kms.DataSourceTencentCloudKmsWhiteBoxDecryptKey(),
891891
"tencentcloud_kms_white_box_device_fingerprints": kms.DataSourceTencentCloudKmsWhiteBoxDeviceFingerprints(),
892892
"tencentcloud_kms_list_algorithms": kms.DataSourceTencentCloudKmsListAlgorithms(),
893+
"tencentcloud_kms_service_status": kms.DataSourceTencentCloudKmsServiceStatus(),
893894
"tencentcloud_ssm_products": ssm.DataSourceTencentCloudSsmProducts(),
894895
"tencentcloud_ssm_secrets": ssm.DataSourceTencentCloudSsmSecrets(),
895896
"tencentcloud_ssm_secret_versions": ssm.DataSourceTencentCloudSsmSecretVersions(),

tencentcloud/provider.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,7 @@ tencentcloud_kms_list_keys
664664
tencentcloud_kms_white_box_decrypt_key
665665
tencentcloud_kms_white_box_device_fingerprints
666666
tencentcloud_kms_list_algorithms
667+
tencentcloud_kms_service_status
667668

668669
Resource
669670
tencentcloud_kms_key

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)

tencentcloud/services/kms/data_source_tc_kms_keys.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ data "tencentcloud_kms_keys" "example" {
88
key_state = 0
99
origin = "TENCENT_KMS"
1010
key_usage = "ALL"
11+
hsm_cluster_id = "cls-hsm-mwpd9cjm"
1112
}
1213
```
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.TypeString,
92+
Required: true,
93+
Description: "Exclusive cluster ID.",
94+
},
95+
"hsm_cluster_name": {
96+
Type: schema.TypeString,
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+
`

0 commit comments

Comments
 (0)