@@ -3,6 +3,7 @@ package ssm_test
33import (
44 "fmt"
55 "testing"
6+ "time"
67
78 tcacctest "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/acctest"
89
@@ -14,21 +15,22 @@ import (
1415func 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