Skip to content

Commit

Permalink
Merge pull request #194 from kingsoftcloud/trunk
Browse files Browse the repository at this point in the history
Trunk
  • Loading branch information
notone0010 authored Jan 17, 2024
2 parents 4a029fe + 34f62ac commit b9b3822
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 5 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 1.14.2 (Jan 17, 2024)

BUGFIX:

- `resource_ksyun_ssh_key` 修复public key comments引发的plan diff

## 1.14.1 (Jan 12, 2024)

IMPROVEMENTS:
Expand Down
40 changes: 36 additions & 4 deletions ksyun/resource_ksyun_ssh_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ package ksyun

import (
"fmt"
"strings"

"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
)

Expand All @@ -49,10 +51,40 @@ func resourceKsyunSSHKey() *schema.Resource {
Description: "ID of the key.",
},
"public_key": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
// pKey := d.Get("public_key").(string)
if old == "" {
return false
}
old = strings.TrimSpace(old)
new = strings.TrimSpace(new)

if old == new {
return true
}
oPks := strings.Split(old, " ")
nPks := strings.Split(new, " ")

// new public key is incorrect
if len(nPks) < 2 {
return false
}

for i, s := range oPks {
if i > 1 {
return true
}
if s != nPks[i] {
return false
}
}

return false
},
Description: "public key.",
},
"private_key": {
Expand Down
3 changes: 2 additions & 1 deletion ksyun/resource_ksyun_ssh_key_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package ksyun

import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/terraform"
"testing"
)

func TestAccKsyunSSHKey_basic(t *testing.T) {
Expand Down

0 comments on commit b9b3822

Please sign in to comment.