Skip to content

Commit 04d4c95

Browse files
tongyimingmikatong
andauthored
fix key_id update exception (#1688)
* fix key_id update exception * add changelog --------- Co-authored-by: mikatong <mikatong@tencent.com>
1 parent 2ea97d7 commit 04d4c95

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

.changelog/1688.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:bug
2+
resource/tencentcloud_instance: fix key_ids update exception
3+
```

tencentcloud/resource_tc_instance.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1341,6 +1341,8 @@ func resourceTencentCloudInstanceUpdate(d *schema.ResourceData, meta interface{}
13411341

13421342
adds := nv.Difference(ov)
13431343
removes := ov.Difference(nv)
1344+
adds.Remove("")
1345+
removes.Remove("")
13441346

13451347
if removes.Len() > 0 {
13461348
err := cvmService.UnbindKeyPair(ctx, helper.InterfacesStringsPoint(removes.List()), []*string{&instanceId})

tencentcloud/resource_tc_instance_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,15 @@ func TestAccTencentCloudInstanceResource_WithKeyPairs(t *testing.T) {
214214
Providers: testAccProviders,
215215
CheckDestroy: testAccCheckInstanceDestroy,
216216
Steps: []resource.TestStep{
217+
{
218+
PreConfig: func() { testAccStepPreConfigSetTempAKSK(t, ACCOUNT_TYPE_COMMON) },
219+
Config: testAccTencentCloudInstanceWithKeyPair_withoutKeyPair,
220+
Check: resource.ComposeTestCheckFunc(
221+
testAccCheckTencentCloudDataSourceID(id),
222+
testAccCheckTencentCloudInstanceExists(id),
223+
resource.TestCheckResourceAttr(id, "instance_status", "RUNNING"),
224+
),
225+
},
217226
{
218227
PreConfig: func() { testAccStepPreConfigSetTempAKSK(t, ACCOUNT_TYPE_COMMON) },
219228
Config: testAccTencentCloudInstanceWithKeyPair(
@@ -938,6 +947,16 @@ resource "tencentcloud_instance" "foo" {
938947
}
939948
`
940949

950+
const testAccTencentCloudInstanceWithKeyPair_withoutKeyPair = defaultInstanceVariable + `
951+
resource "tencentcloud_instance" "foo" {
952+
instance_name = var.instance_name
953+
availability_zone = var.availability_cvm_zone
954+
image_id = data.tencentcloud_images.default.images.0.image_id
955+
instance_type = data.tencentcloud_instance_types.default.instance_types.0.instance_type
956+
system_disk_type = "CLOUD_PREMIUM"
957+
}
958+
`
959+
941960
func testAccTencentCloudInstanceWithKeyPair(keyIds string) string {
942961

943962
return fmt.Sprintf(

0 commit comments

Comments
 (0)