-
Notifications
You must be signed in to change notification settings - Fork 10
/
data_source_appgate_site.go
75 lines (64 loc) · 1.56 KB
/
data_source_appgate_site.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
package appgate
import (
"context"
"log"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func dataSourceAppgateSite() *schema.Resource {
return &schema.Resource{
ReadContext: dataSourceAppgateSiteRead,
Schema: map[string]*schema.Schema{
"site_id": {
Type: schema.TypeString,
Optional: true,
ConflictsWith: []string{"site_name"},
},
"site_name": {
Type: schema.TypeString,
Optional: true,
ConflictsWith: []string{"site_id"},
},
"notes": {
Type: schema.TypeString,
Computed: true,
},
"created": {
Type: schema.TypeString,
Computed: true,
},
"updated": {
Type: schema.TypeString,
Computed: true,
},
"tags": {
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"short_name": {
Type: schema.TypeString,
Computed: true,
},
},
}
}
func dataSourceAppgateSiteRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
log.Printf("[DEBUG] Data source Site")
token, err := meta.(*Client).GetToken()
if err != nil {
return diag.FromErr(err)
}
api := meta.(*Client).API.SitesApi
site, diags := ResolveSiteFromResourceData(ctx, d, api, token)
if diags != nil {
return diags
}
d.SetId(site.GetId())
d.Set("site_name", site.GetName())
d.Set("short_name", site.GetShortName())
d.Set("site_id", site.GetId())
d.Set("notes", site.GetNotes())
d.Set("tags", site.GetTags())
return nil
}