/
data_iam_resource_group.go
81 lines (72 loc) · 1.65 KB
/
data_iam_resource_group.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package ovh
import (
"context"
"fmt"
"net/url"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func dataSourceIamResourceGroup() *schema.Resource {
return &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeString,
Required: true,
},
"name": {
Type: schema.TypeString,
Computed: true,
},
"resources": {
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"owner": {
Type: schema.TypeString,
Computed: true,
},
"created_at": {
Type: schema.TypeString,
Computed: true,
},
"updated_at": {
Type: schema.TypeString,
Computed: true,
},
"read_only": {
Type: schema.TypeBool,
Computed: true,
},
"urn": {
Type: schema.TypeString,
Computed: true,
},
},
ReadContext: datasourceIamResourceGroupRead,
}
}
func datasourceIamResourceGroupRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics {
config := meta.(*Config)
id := d.Get("id").(string)
var pol IamResourceGroup
err := config.OVHClient.GetWithContext(ctx, fmt.Sprintf("/v2/iam/resourceGroup/%s?details=true", url.PathEscape(id)), &pol)
if err != nil {
return diag.FromErr(err)
}
d.SetId(id)
var urns []string
for _, r := range pol.Resources {
urns = append(urns, r.URN)
}
d.Set("resources", urns)
d.Set("name", pol.Name)
d.Set("owner", pol.Owner)
d.Set("created_at", pol.CreatedAt)
d.Set("updated_at", pol.UpdatedAt)
d.Set("read_only", pol.ReadOnly)
d.Set("urn", pol.URN)
return nil
}