forked from ovh/terraform-provider-ovh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
data_cloud_project_kube_iprestrictions.go
58 lines (50 loc) · 1.6 KB
/
data_cloud_project_kube_iprestrictions.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
package ovh
import (
"fmt"
"log"
"net/url"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/ovh/terraform-provider-ovh/ovh/helpers"
)
func dataSourceCloudProjectKubeIPRestrictions() *schema.Resource {
return &schema.Resource{
Read: dataSourceCloudProjectKubeIpRestrictionsRead,
Schema: map[string]*schema.Schema{
"service_name": {
Type: schema.TypeString,
Description: "Service name",
Required: true,
ForceNew: true,
DefaultFunc: schema.EnvDefaultFunc("OVH_CLOUD_PROJECT_SERVICE", nil),
},
"kube_id": {
Type: schema.TypeString,
Description: "Kube ID",
Required: true,
ForceNew: true,
},
"ips": {
Type: schema.TypeSet,
Elem: &schema.Schema{Type: schema.TypeString},
Set: schema.HashString,
Description: "List of IP restrictions for the cluster",
Computed: true,
},
},
}
}
func dataSourceCloudProjectKubeIpRestrictionsRead(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
serviceName := d.Get("service_name").(string)
kubeId := d.Get("kube_id").(string)
endpoint := fmt.Sprintf("/cloud/project/%s/kube/%s/ipRestrictions", url.PathEscape(serviceName), url.PathEscape(kubeId))
var res CloudProjectKubeIpRestrictionsResponse
log.Printf("[DEBUG] Will read iprestrictions from cluster %s in project %s", kubeId, serviceName)
if err := config.OVHClient.Get(endpoint, &res); err != nil {
return helpers.CheckDeleted(d, err, endpoint)
}
d.SetId(kubeId)
d.Set("ips", res)
log.Printf("[DEBUG] Read iprestrictions: %+v", res)
return nil
}