-
Notifications
You must be signed in to change notification settings - Fork 952
Expand file tree
/
Copy pathresource_github_user_ssh_key_migration.go
More file actions
60 lines (54 loc) · 1.44 KB
/
resource_github_user_ssh_key_migration.go
File metadata and controls
60 lines (54 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package github
import (
"context"
"fmt"
"strconv"
"strings"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func resourceGithubUserSshKeyV0() *schema.Resource {
return &schema.Resource{
SchemaVersion: 0,
Schema: map[string]*schema.Schema{
"title": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: "A descriptive name for the new key.",
},
"key": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: "The public SSH key to add to your GitHub account.",
DiffSuppressFunc: func(k, oldV, newV string, d *schema.ResourceData) bool {
newTrimmed := strings.TrimSpace(newV)
return oldV == newTrimmed
},
},
"url": {
Type: schema.TypeString,
Computed: true,
Description: "The URL of the SSH key.",
},
"etag": {
Type: schema.TypeString,
Computed: true,
},
},
}
}
func resourceGithubUserSshKeyStateUpgradeV0(ctx context.Context, rawState map[string]any, m any) (map[string]any, error) {
if rawState == nil {
return nil, fmt.Errorf("resource state upgrade failed, state is nil")
}
// copy d.Id() into key_id
if id, ok := rawState["id"].(string); ok {
keyID, err := strconv.ParseInt(id, 10, 64)
if err != nil {
return nil, fmt.Errorf("resource state upgrade failed, invalid SSH key ID format: %w", err)
}
rawState["key_id"] = keyID
}
return rawState, nil
}