-
Notifications
You must be signed in to change notification settings - Fork 132
/
data_me_ssh_keys.go
43 lines (35 loc) · 1000 Bytes
/
data_me_ssh_keys.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
package ovh
import (
"fmt"
"log"
"sort"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/ovh/terraform-provider-ovh/ovh/helpers/hashcode"
)
func dataSourceMeSshKeys() *schema.Resource {
return &schema.Resource{
Read: dataSourceMeSshKeysRead,
DeprecationMessage: "[DEPRECATED] SSH key names '/me/sshKey' will be deprecated soon",
Schema: map[string]*schema.Schema{
"names": {
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
Set: schema.HashString,
},
},
}
}
func dataSourceMeSshKeysRead(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
names := make([]string, 0)
err := config.OVHClient.Get("/me/sshKey", &names)
if err != nil {
return fmt.Errorf("Error calling /me/sshKey:\n\t %q", err)
}
sort.Strings(names)
d.SetId(hashcode.Strings(names))
d.Set("names", names)
log.Printf("[DEBUG] Read SSH Keys names %s", names)
return nil
}