-
Notifications
You must be signed in to change notification settings - Fork 16
/
data_source_zpa_scim_group.go
85 lines (81 loc) · 1.95 KB
/
data_source_zpa_scim_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
82
83
84
85
package zpa
import (
"fmt"
"log"
"strconv"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/zscaler/zscaler-sdk-go/zpa/services/scimgroup"
)
func dataSourceScimGroup() *schema.Resource {
return &schema.Resource{
Read: dataSourceScimGroupRead,
Schema: map[string]*schema.Schema{
"creation_time": {
Type: schema.TypeInt,
Computed: true,
},
"id": {
Type: schema.TypeString,
Optional: true,
},
"name": {
Type: schema.TypeString,
Optional: true,
},
"idp_group_id": {
Type: schema.TypeString,
Computed: true,
},
"idp_id": {
Type: schema.TypeInt,
Optional: true,
},
"idp_name": {
Type: schema.TypeString,
Optional: true,
},
"modified_time": {
Type: schema.TypeInt,
Computed: true,
},
},
}
}
func dataSourceScimGroupRead(d *schema.ResourceData, m interface{}) error {
zClient := m.(*Client)
var resp *scimgroup.ScimGroup
id, ok := d.Get("id").(string)
if ok && id != "" {
res, _, err := zClient.scimgroup.Get(id)
if err != nil {
return err
}
resp = res
}
idpName, ok := d.Get("idp_name").(string)
name, ok2 := d.Get("name").(string)
if id == "" && ok && ok2 && idpName != "" && name != "" {
idpResp, _, err := zClient.idpcontroller.GetByName(idpName)
if err != nil || idpResp == nil {
log.Printf("[INFO] couldn't find idp by name: %s\n", idpName)
return err
}
res, _, err := zClient.scimgroup.GetByName(name, idpResp.ID)
if err != nil {
return err
}
resp = res
}
if resp != nil {
d.SetId(strconv.FormatInt(int64(resp.ID), 10))
_ = d.Set("creation_time", resp.CreationTime)
_ = d.Set("idp_group_id", resp.IdpGroupID)
_ = d.Set("idp_id", resp.IdpID)
_ = d.Set("idp_name", resp.IdpName)
_ = d.Set("modified_time", resp.ModifiedTime)
_ = d.Set("name", resp.Name)
} else {
return fmt.Errorf("no scim name '%s' & idp name '%s' OR id '%s' was found", name, idpName, id)
}
return nil
}