-
Notifications
You must be signed in to change notification settings - Fork 132
/
data_me_ipxe_script.go
48 lines (40 loc) · 1.02 KB
/
data_me_ipxe_script.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
package ovh
import (
"fmt"
"net/url"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func dataSourceMeIpxeScript() *schema.Resource {
return &schema.Resource{
Read: dataSourceMeIpxeScriptRead,
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
Description: "Name of your script",
},
"script": {
Type: schema.TypeString,
Computed: true,
Description: "Content of your IPXE script",
},
},
}
}
// Common function with the datasource
func dataSourceMeIpxeScriptRead(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
ipxeScript := &MeIpxeScriptResponse{}
name := d.Get("name").(string)
err := config.OVHClient.Get(
fmt.Sprintf("/me/ipxeScript/%s", url.PathEscape(name)),
ipxeScript,
)
if err != nil {
return fmt.Errorf("Unable to find IpxeScript named %s:\n\t %q", name, err)
}
d.SetId(ipxeScript.Name)
d.Set("name", ipxeScript.Name)
d.Set("script", ipxeScript.Script)
return nil
}