-
Notifications
You must be signed in to change notification settings - Fork 0
/
data_source_openstack_compute_keypair_v2.go
63 lines (50 loc) · 1.4 KB
/
data_source_openstack_compute_keypair_v2.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
53
54
55
56
57
58
59
60
61
62
63
package openstack
import (
"fmt"
"log"
"github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/keypairs"
"github.com/hashicorp/terraform/helper/schema"
)
func dataSourceComputeKeypairV2() *schema.Resource {
return &schema.Resource{
Read: dataSourceComputeKeypairV2Read,
Schema: map[string]*schema.Schema{
"region": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"name": &schema.Schema{
Type: schema.TypeString,
Required: true,
},
// computed-only
"fingerprint": &schema.Schema{
Type: schema.TypeString,
Computed: true,
},
"public_key": &schema.Schema{
Type: schema.TypeString,
Computed: true,
},
},
}
}
func dataSourceComputeKeypairV2Read(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
computeClient, err := config.computeV2Client(GetRegion(d, config))
if err != nil {
return fmt.Errorf("Error creating OpenStack compute client: %s", err)
}
name := d.Get("name").(string)
kp, err := keypairs.Get(computeClient, name).Extract()
if err != nil {
return fmt.Errorf("Error retrieving openstack_compute_keypair_v2 %s: %s", name, err)
}
d.SetId(name)
log.Printf("[DEBUG] Retrieved openstack_compute_keypair_v2 %s: %#v", d.Id(), kp)
d.Set("fingerprint", kp.Fingerprint)
d.Set("public_key", kp.PublicKey)
d.Set("region", GetRegion(d, config))
return nil
}