-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathdata_source_source.go
106 lines (99 loc) · 2.34 KB
/
data_source_source.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
package main
import (
"context"
"log"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
)
func dataSourceSource() *schema.Resource {
return &schema.Resource{
Read: dataSourceSourceRead,
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeString,
Required: true,
Description: "Source id",
},
"name": {
Type: schema.TypeString,
Computed: true,
Description: "Source name",
},
"description": {
Type: schema.TypeString,
Computed: true,
Description: "Source description",
},
"connector": {
Type: schema.TypeString,
Computed: true,
Description: "Source connector type",
},
"delete_threshold": {
Type: schema.TypeInt,
Computed: true,
},
"authoritative": {
Type: schema.TypeBool,
Computed: true,
Description: "True if this source is authoritative",
},
"owner": {
Type: schema.TypeList,
MaxItems: 1,
Computed: true,
Elem: &schema.Resource{
Schema: sourceOwnerFields(),
},
},
"schemas": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: sourceSchemaFields(),
},
},
"cluster": {
Type: schema.TypeList,
MaxItems: 1,
Computed: true,
Elem: &schema.Resource{
Schema: sourceClusterFields(),
},
},
"account_correlation_config": {
Type: schema.TypeList,
MaxItems: 1,
Computed: true,
Elem: &schema.Resource{
Schema: sourceAccountCorrelationConfigFields(),
},
},
"connector_attributes": {
Type: schema.TypeList,
MaxItems: 1,
Computed: true,
Elem: &schema.Resource{
Schema: sourceConnectorAttributesFields(),
},
},
},
}
}
func dataSourceSourceRead(d *schema.ResourceData, meta interface{}) error {
log.Printf("[INFO] Data source for Source ID %s", d.Get("id").(string))
client, err := meta.(*Config).IdentityNowClient()
if err != nil {
return err
}
source, err := client.GetSource(context.Background(), d.Get("id").(string))
if err != nil {
// non-panicking type assertion, 2nd arg is boolean indicating type match
_, notFound := err.(*NotFoundError)
if notFound {
log.Printf("[INFO] Data source for Source ID %s not found.", d.Get("id").(string))
return nil
}
return err
}
return flattenSource(d, source)
}