/
datasource_scim_groups.go
137 lines (127 loc) · 3.61 KB
/
datasource_scim_groups.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
package datasources
import (
"context"
"github.com/MaterializeInc/terraform-provider-materialize/pkg/frontegg"
"github.com/MaterializeInc/terraform-provider-materialize/pkg/utils"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
var dataSourceSCIMGroupsSchema = map[string]*schema.Schema{
"groups": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeString,
Computed: true,
Description: "The ID of the group. This is a unique identifier for the group. ",
},
"name": {
Type: schema.TypeString,
Computed: true,
Description: "The name of the group.",
},
"description": {
Type: schema.TypeString,
Computed: true,
Description: "The description of the group.",
},
"metadata": {
Type: schema.TypeString,
Computed: true,
Optional: true,
Description: "The metadata of the group.",
},
"roles": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeString,
Computed: true,
Description: "The ID of the role. This is a unique identifier for the role.",
},
"key": {
Type: schema.TypeString,
Computed: true,
Description: "The key of the role.",
},
"name": {
Type: schema.TypeString,
Computed: true,
Description: "The name of the role.",
},
"description": {
Type: schema.TypeString,
Computed: true,
Description: "The description of the role.",
},
"is_default": {
Type: schema.TypeBool,
Computed: true,
Description: "Indicates whether the role is the default role.",
},
},
},
},
"users": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeString,
Computed: true,
Description: "The ID of the user. This is a unique identifier for the user.",
},
"name": {
Type: schema.TypeString,
Computed: true,
Description: "The name of the user.",
},
"email": {
Type: schema.TypeString,
Computed: true,
Description: "The email of the user.",
},
},
},
},
"managed_by": {
Type: schema.TypeString,
Computed: true,
Description: "The ID of the user who manages the group.",
},
},
},
},
}
// SCIMGroups data source function
func SCIMGroups() *schema.Resource {
return &schema.Resource{
ReadContext: dataSourceSCIMGroupsRead,
Schema: dataSourceSCIMGroupsSchema,
Description: "The SCIM groups data source allows you to fetch the available groups.",
}
}
// Read function for SCIM groups data source
func dataSourceSCIMGroupsRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
providerMeta, err := utils.GetProviderMeta(meta)
if err != nil {
return diag.FromErr(err)
}
client := providerMeta.Frontegg
groups, err := frontegg.FetchSCIMGroups(ctx, client)
if err != nil {
return diag.FromErr(err)
}
// Map the response to the schema
if err := d.Set("groups", frontegg.FlattenScimGroups(groups)); err != nil {
return diag.FromErr(err)
}
// Set the ID of the data source
d.SetId("scim_groups")
return nil
}