-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathstructure_account_schema.go
65 lines (58 loc) · 1.82 KB
/
structure_account_schema.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
package main
import (
"fmt"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"log"
)
// Flatteners
func flattenAccountSchema(d *schema.ResourceData, in *AccountSchema) error {
if in == nil {
return nil
}
d.SetId(in.ID)
d.Set("name", in.Name)
d.Set("source_id", in.SourceID)
d.Set("schema_id", in.ID)
d.Set("native_object_type", in.NativeObjectType)
d.Set("identity_attribute", in.IdentityAttribute)
d.Set("display_attribute", in.DisplayAttribute)
d.Set("hierarchy_attribute", in.HierarchyAttribute)
d.Set("include_permissions", in.IncludePermissions)
d.Set("modified", in.Modified)
d.Set("created", in.Created)
if in.Attributes != nil {
v, ok := d.Get("attributes").([]interface{})
if !ok {
v = []interface{}{}
}
d.Set("attributes", flattenAccountSchemaAttributes(in.Attributes, v))
}
log.Printf("d *schema.ResourceData in flatten: %+v", d)
return nil
}
// Expanders
func expandAccountSchema(in *schema.ResourceData) (*AccountSchema, error) {
obj := AccountSchema{}
if in == nil {
return nil, fmt.Errorf("[ERROR] Expanding Account Schema: Schema Resource data is nil")
}
if v := in.Id(); len(v) > 0 {
obj.ID = v
}
obj.Name = in.Get("name").(string)
obj.SourceID = in.Get("source_id").(string)
obj.ID = in.Get("schema_id").(string)
obj.NativeObjectType = in.Get("native_object_type").(string)
obj.IdentityAttribute = in.Get("identity_attribute").(string)
obj.DisplayAttribute = in.Get("display_attribute").(string)
obj.HierarchyAttribute = in.Get("hierarchy_attribute").(string)
obj.Modified = in.Get("modified").(string)
obj.Created = in.Get("created").(string)
if v, ok := in.Get("include_permissions").(bool); ok {
obj.IncludePermissions = v
}
if v, ok := in.Get("attributes").([]interface{}); ok && len(v) > 0 {
obj.Attributes = expandAccountSchemaAttributes(v)
}
return &obj, nil
}