forked from ovh/terraform-provider-ovh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata_source_ovh_me_ssh_key.go
52 lines (44 loc) · 1.14 KB
/
data_source_ovh_me_ssh_key.go
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
package ovh
import (
"fmt"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
)
func dataSourceMeSshKey() *schema.Resource {
return &schema.Resource{
Read: dataSourceMeSshKeyRead,
Schema: map[string]*schema.Schema{
"key_name": {
Type: schema.TypeString,
Required: true,
Description: "Name of this public Ssh key",
},
"key": {
Type: schema.TypeString,
Computed: true,
Description: "ASCII encoded public Ssh key",
},
"default": {
Type: schema.TypeBool,
Computed: true,
Description: "True when this public Ssh key is used for rescue mode and reinstallations",
},
},
}
}
func dataSourceMeSshKeyRead(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
sshKey := &MeSshKeyResponse{}
keyName := d.Get("key_name").(string)
err := config.OVHClient.Get(
fmt.Sprintf("/me/sshKey/%s", keyName),
sshKey,
)
if err != nil {
return fmt.Errorf("Unable to find SSH key named %s:\n\t %q", keyName, err)
}
d.SetId(sshKey.KeyName)
d.Set("key_name", sshKey.KeyName)
d.Set("key", sshKey.Key)
d.Set("default", sshKey.Default)
return nil
}