Skip to content

Commit 5c93ec9

Browse files
authored
fix/ssm (#2440)
* fix/ssm * fix/ssm
1 parent 1e7caeb commit 5c93ec9

File tree

3 files changed

+60
-4
lines changed

3 files changed

+60
-4
lines changed

.changelog/2440.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
resource/tencentcloud_ssm_ssh_key_pair_secret: Fix kms_key_id problem
3+
```

tencentcloud/services/ssm/resource_tc_ssm_ssh_key_pair_secret.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ func ResourceTencentCloudSsmSshKeyPairSecret() *schema.Resource {
3838
},
3939
"kms_key_id": {
4040
Optional: true,
41+
Computed: true,
4142
Type: schema.TypeString,
4243
Description: "Specifies a KMS CMK to encrypt the secret.If this parameter is left empty, the CMK created by Secrets Manager by default will be used for encryption.You can also specify a custom KMS CMK created in the same region for encryption.",
4344
},

tencentcloud/services/ssm/resource_tc_ssm_ssh_key_pair_secret_test.go

Lines changed: 56 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package ssm_test
33
import (
44
"fmt"
55
"testing"
6+
"time"
67

78
tcacctest "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/acctest"
89

@@ -14,21 +15,22 @@ import (
1415
func TestAccTencentCloudSsmSshKeyPairSecretResource_basic(t *testing.T) {
1516
t.Parallel()
1617
rName := fmt.Sprintf("tf-testacc-kms-key-%s", acctest.RandString(13))
18+
rSshName := fmt.Sprintf("%d", time.Now().Unix())
1719
resource.Test(t, resource.TestCase{
1820
PreCheck: func() {
1921
tcacctest.AccPreCheck(t)
2022
},
2123
Providers: tcacctest.AccProviders,
2224
Steps: []resource.TestStep{
2325
{
24-
Config: fmt.Sprintf(testAccSsmSshKeyPairSecret, rName),
26+
Config: fmt.Sprintf(testAccSsmSshKeyPairSecret, rName, rSshName),
2527
Check: resource.ComposeTestCheckFunc(
2628
resource.TestCheckResourceAttr("tencentcloud_ssm_ssh_key_pair_secret.example", "description", "desc."),
2729
resource.TestCheckResourceAttr("tencentcloud_ssm_ssh_key_pair_secret.example", "status", "Disabled"),
2830
),
2931
},
3032
{
31-
Config: fmt.Sprintf(testAccSsmSshKeyPairSecretUpdate, rName),
33+
Config: fmt.Sprintf(testAccSsmSshKeyPairSecretUpdate, rName, rSshName),
3234
Check: resource.ComposeTestCheckFunc(
3335
resource.TestCheckResourceAttr("tencentcloud_ssm_ssh_key_pair_secret.example", "description", "update desc."),
3436
resource.TestCheckResourceAttr("tencentcloud_ssm_ssh_key_pair_secret.example", "status", "Enabled"),
@@ -40,6 +42,26 @@ func TestAccTencentCloudSsmSshKeyPairSecretResource_basic(t *testing.T) {
4042
ImportStateVerify: true,
4143
ImportStateVerifyIgnore: []string{"clean_ssh_key"},
4244
},
45+
{
46+
Config: fmt.Sprintf(testAccSsmSshKeyPairSecretNoId, rSshName),
47+
Check: resource.ComposeTestCheckFunc(
48+
resource.TestCheckResourceAttr("tencentcloud_ssm_ssh_key_pair_secret.example1", "description", "desc."),
49+
resource.TestCheckResourceAttr("tencentcloud_ssm_ssh_key_pair_secret.example1", "status", "Disabled"),
50+
),
51+
},
52+
{
53+
Config: fmt.Sprintf(testAccSsmSshKeyPairSecretNoIdUpdate, rSshName),
54+
Check: resource.ComposeTestCheckFunc(
55+
resource.TestCheckResourceAttr("tencentcloud_ssm_ssh_key_pair_secret.example1", "description", "update desc."),
56+
resource.TestCheckResourceAttr("tencentcloud_ssm_ssh_key_pair_secret.example1", "status", "Enabled"),
57+
),
58+
},
59+
{
60+
ResourceName: "tencentcloud_ssm_ssh_key_pair_secret.example1",
61+
ImportState: true,
62+
ImportStateVerify: true,
63+
ImportStateVerifyIgnore: []string{"clean_ssh_key"},
64+
},
4365
},
4466
})
4567
}
@@ -61,7 +83,7 @@ resource "tencentcloud_ssm_ssh_key_pair_secret" "example" {
6183
project_id = 0
6284
description = "desc."
6385
kms_key_id = tencentcloud_kms_key.example.id
64-
ssh_key_name = "tf_example_ssh"
86+
ssh_key_name = "tf_ssh_name_%s"
6587
status = "Disabled"
6688
clean_ssh_key = true
6789
@@ -88,7 +110,7 @@ resource "tencentcloud_ssm_ssh_key_pair_secret" "example" {
88110
project_id = 0
89111
description = "update desc."
90112
kms_key_id = tencentcloud_kms_key.example.id
91-
ssh_key_name = "tf_example_ssh"
113+
ssh_key_name = "tf_ssh_name_%s"
92114
status = "Enabled"
93115
clean_ssh_key = true
94116
@@ -97,3 +119,33 @@ resource "tencentcloud_ssm_ssh_key_pair_secret" "example" {
97119
}
98120
}
99121
`
122+
123+
const testAccSsmSshKeyPairSecretNoId = `
124+
resource "tencentcloud_ssm_ssh_key_pair_secret" "example1" {
125+
secret_name = "tf-example-ssh-test-no-id"
126+
project_id = 0
127+
description = "desc."
128+
ssh_key_name = "tf_noid_name_%s"
129+
status = "Disabled"
130+
clean_ssh_key = true
131+
132+
tags = {
133+
createdBy = "terraform"
134+
}
135+
}
136+
`
137+
138+
const testAccSsmSshKeyPairSecretNoIdUpdate = `
139+
resource "tencentcloud_ssm_ssh_key_pair_secret" "example1" {
140+
secret_name = "tf-example-ssh-test-no-id"
141+
project_id = 0
142+
description = "update desc."
143+
ssh_key_name = "tf_noid_name_%s"
144+
status = "Enabled"
145+
clean_ssh_key = true
146+
147+
tags = {
148+
createdBy = "terraform"
149+
}
150+
}
151+
`

0 commit comments

Comments
 (0)