From a7420fcd4e99343b8b6e3f68b5a4c895de24c9c8 Mon Sep 17 00:00:00 2001 From: SevenEarth <391613297@qq.com> Date: Fri, 29 Dec 2023 14:04:03 +0800 Subject: [PATCH 1/4] fix/ssm --- .../resource_tc_ssm_ssh_key_pair_secret.go | 1 + ...esource_tc_ssm_ssh_key_pair_secret_test.go | 60 +++++++++++++++++-- 2 files changed, 57 insertions(+), 4 deletions(-) diff --git a/tencentcloud/services/ssm/resource_tc_ssm_ssh_key_pair_secret.go b/tencentcloud/services/ssm/resource_tc_ssm_ssh_key_pair_secret.go index 1c6bb40b5f..54c050b114 100644 --- a/tencentcloud/services/ssm/resource_tc_ssm_ssh_key_pair_secret.go +++ b/tencentcloud/services/ssm/resource_tc_ssm_ssh_key_pair_secret.go @@ -38,6 +38,7 @@ func ResourceTencentCloudSsmSshKeyPairSecret() *schema.Resource { }, "kms_key_id": { Optional: true, + Computed: true, Type: schema.TypeString, 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.", }, diff --git a/tencentcloud/services/ssm/resource_tc_ssm_ssh_key_pair_secret_test.go b/tencentcloud/services/ssm/resource_tc_ssm_ssh_key_pair_secret_test.go index 51355eaa0f..b96349d024 100644 --- a/tencentcloud/services/ssm/resource_tc_ssm_ssh_key_pair_secret_test.go +++ b/tencentcloud/services/ssm/resource_tc_ssm_ssh_key_pair_secret_test.go @@ -3,6 +3,7 @@ package ssm_test import ( "fmt" "testing" + "time" tcacctest "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/acctest" @@ -14,6 +15,7 @@ import ( func TestAccTencentCloudSsmSshKeyPairSecretResource_basic(t *testing.T) { t.Parallel() rName := fmt.Sprintf("tf-testacc-kms-key-%s", acctest.RandString(13)) + rSshName := fmt.Sprintf("%d", time.Now().Unix()) resource.Test(t, resource.TestCase{ PreCheck: func() { tcacctest.AccPreCheck(t) @@ -21,14 +23,14 @@ func TestAccTencentCloudSsmSshKeyPairSecretResource_basic(t *testing.T) { Providers: tcacctest.AccProviders, Steps: []resource.TestStep{ { - Config: fmt.Sprintf(testAccSsmSshKeyPairSecret, rName), + Config: fmt.Sprintf(testAccSsmSshKeyPairSecret, rName, rSshName), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("tencentcloud_ssm_ssh_key_pair_secret.example", "description", "desc."), resource.TestCheckResourceAttr("tencentcloud_ssm_ssh_key_pair_secret.example", "status", "Disabled"), ), }, { - Config: fmt.Sprintf(testAccSsmSshKeyPairSecretUpdate, rName), + Config: fmt.Sprintf(testAccSsmSshKeyPairSecretUpdate, rName, rSshName), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("tencentcloud_ssm_ssh_key_pair_secret.example", "description", "update desc."), resource.TestCheckResourceAttr("tencentcloud_ssm_ssh_key_pair_secret.example", "status", "Enabled"), @@ -40,6 +42,26 @@ func TestAccTencentCloudSsmSshKeyPairSecretResource_basic(t *testing.T) { ImportStateVerify: true, ImportStateVerifyIgnore: []string{"clean_ssh_key"}, }, + { + Config: fmt.Sprintf(testAccSsmSshKeyPairSecretNoId, rSshName), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("tencentcloud_ssm_ssh_key_pair_secret.example1", "description", "desc."), + resource.TestCheckResourceAttr("tencentcloud_ssm_ssh_key_pair_secret.example1", "status", "Disabled"), + ), + }, + { + Config: fmt.Sprintf(testAccSsmSshKeyPairSecretNoIdUpdate, rSshName), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("tencentcloud_ssm_ssh_key_pair_secret.example1", "description", "update desc."), + resource.TestCheckResourceAttr("tencentcloud_ssm_ssh_key_pair_secret.example1", "status", "Enabled"), + ), + }, + { + ResourceName: "tencentcloud_ssm_ssh_key_pair_secret.example1", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"clean_ssh_key"}, + }, }, }) } @@ -61,7 +83,7 @@ resource "tencentcloud_ssm_ssh_key_pair_secret" "example" { project_id = 0 description = "desc." kms_key_id = tencentcloud_kms_key.example.id - ssh_key_name = "tf_example_ssh" + ssh_key_name = "tf_ssh_name_%s" status = "Disabled" clean_ssh_key = true @@ -88,7 +110,7 @@ resource "tencentcloud_ssm_ssh_key_pair_secret" "example" { project_id = 0 description = "update desc." kms_key_id = tencentcloud_kms_key.example.id - ssh_key_name = "tf_example_ssh" + ssh_key_name = "tf_ssh_name_%s" status = "Enabled" clean_ssh_key = true @@ -97,3 +119,33 @@ resource "tencentcloud_ssm_ssh_key_pair_secret" "example" { } } ` + +const testAccSsmSshKeyPairSecretNoId = ` +resource "tencentcloud_ssm_ssh_key_pair_secret" "example1" { + secret_name = "tf-example-ssh-test-no-id" + project_id = 0 + description = "desc." + ssh_key_name = "tf_noid_name_%s" + status = "Disabled" + clean_ssh_key = true + + tags = { + createdBy = "terraform" + } +} +` + +const testAccSsmSshKeyPairSecretNoIdUpdate = ` +resource "tencentcloud_ssm_ssh_key_pair_secret" "example1" { + secret_name = "tf-example-ssh-test-no-id" + project_id = 0 + description = "update desc." + ssh_key_name = "tf_noid_name_%s" + status = "Enabled" + clean_ssh_key = true + + tags = { + createdBy = "terraform" + } +} +` From 6b6ee7500d655e02e4d8e8901ef1e7d163b9b401 Mon Sep 17 00:00:00 2001 From: SevenEarth <391613297@qq.com> Date: Fri, 29 Dec 2023 14:05:07 +0800 Subject: [PATCH 2/4] fix/ssm --- .changelog/2440.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/2440.txt diff --git a/.changelog/2440.txt b/.changelog/2440.txt new file mode 100644 index 0000000000..5999d092b5 --- /dev/null +++ b/.changelog/2440.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +resource/tencentcloud_ssm_ssh_key_pair_secret: Fix kms_key_id problem +``` From 474bcb6252ea040c9db688042ab3cb45aae160e1 Mon Sep 17 00:00:00 2001 From: SevenEarth <391613297@qq.com> Date: Tue, 2 Jan 2024 14:43:03 +0800 Subject: [PATCH 3/4] fix/ssm --- .../resource_tc_ssm_ssh_key_pair_secret.go | 1 + ...esource_tc_ssm_ssh_key_pair_secret_test.go | 48 +++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/tencentcloud/services/ssm/resource_tc_ssm_ssh_key_pair_secret.go b/tencentcloud/services/ssm/resource_tc_ssm_ssh_key_pair_secret.go index 54c050b114..bc069b144d 100644 --- a/tencentcloud/services/ssm/resource_tc_ssm_ssh_key_pair_secret.go +++ b/tencentcloud/services/ssm/resource_tc_ssm_ssh_key_pair_secret.go @@ -49,6 +49,7 @@ func ResourceTencentCloudSsmSshKeyPairSecret() *schema.Resource { }, "ssh_key_name": { Optional: true, + Computed: true, Type: schema.TypeString, Description: "Name of the SSH key pair, which only contains digits, letters and underscores and must start with a digit or letter. The maximum length is 25 characters.", }, diff --git a/tencentcloud/services/ssm/resource_tc_ssm_ssh_key_pair_secret_test.go b/tencentcloud/services/ssm/resource_tc_ssm_ssh_key_pair_secret_test.go index b96349d024..1a7c09906f 100644 --- a/tencentcloud/services/ssm/resource_tc_ssm_ssh_key_pair_secret_test.go +++ b/tencentcloud/services/ssm/resource_tc_ssm_ssh_key_pair_secret_test.go @@ -62,6 +62,26 @@ func TestAccTencentCloudSsmSshKeyPairSecretResource_basic(t *testing.T) { ImportStateVerify: true, ImportStateVerifyIgnore: []string{"clean_ssh_key"}, }, + { + Config: testAccSsmSshKeyPairSecretNoName, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("tencentcloud_ssm_ssh_key_pair_secret.example2", "description", "desc."), + resource.TestCheckResourceAttr("tencentcloud_ssm_ssh_key_pair_secret.example2", "status", "Disabled"), + ), + }, + { + Config: testAccSsmSshKeyPairSecretNoNameUpdate, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("tencentcloud_ssm_ssh_key_pair_secret.example2", "description", "update desc."), + resource.TestCheckResourceAttr("tencentcloud_ssm_ssh_key_pair_secret.example2", "status", "Enabled"), + ), + }, + { + ResourceName: "tencentcloud_ssm_ssh_key_pair_secret.example2", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"clean_ssh_key"}, + }, }, }) } @@ -149,3 +169,31 @@ resource "tencentcloud_ssm_ssh_key_pair_secret" "example1" { } } ` + +const testAccSsmSshKeyPairSecretNoName = ` +resource "tencentcloud_ssm_ssh_key_pair_secret" "example2" { + secret_name = "tf-example-ssh-test-no-id" + project_id = 0 + description = "desc." + status = "Disabled" + clean_ssh_key = true + + tags = { + createdBy = "terraform" + } +} +` + +const testAccSsmSshKeyPairSecretNoNameUpdate = ` +resource "tencentcloud_ssm_ssh_key_pair_secret" "example2" { + secret_name = "tf-example-ssh-test-no-id" + project_id = 0 + description = "update desc." + status = "Enabled" + clean_ssh_key = true + + tags = { + createdBy = "terraform" + } +} +` From a50fa750664c4fc6e9b3bc84641d40ba2d626a28 Mon Sep 17 00:00:00 2001 From: SevenEarth <391613297@qq.com> Date: Tue, 2 Jan 2024 14:43:50 +0800 Subject: [PATCH 4/4] fix/ssm --- .changelog/2444.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/2444.txt diff --git a/.changelog/2444.txt b/.changelog/2444.txt new file mode 100644 index 0000000000..058e455bfe --- /dev/null +++ b/.changelog/2444.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +resource/tencentcloud_ssm_ssh_key_pair_secret: Fix ssh_key_name problem +```