-
Notifications
You must be signed in to change notification settings - Fork 10
/
data_source_appgate_ringfence_rule.go
55 lines (46 loc) · 1.35 KB
/
data_source_appgate_ringfence_rule.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
package appgate
import (
"context"
"log"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func dataSourceAppgateRingfenceRule() *schema.Resource {
return &schema.Resource{
ReadContext: dataSourceAppgateRingfenceRuleRead,
Schema: map[string]*schema.Schema{
"ringfence_rule_id": {
Type: schema.TypeString,
Optional: true,
ConflictsWith: []string{"ringfence_rule_name"},
},
"ringfence_rule_name": {
Type: schema.TypeString,
Optional: true,
ConflictsWith: []string{"ringfence_rule_id"},
},
"tags": {
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
},
}
}
func dataSourceAppgateRingfenceRuleRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
log.Printf("[DEBUG] Data source Ringfence Rules")
token, err := meta.(*Client).GetToken()
if err != nil {
return diag.FromErr(err)
}
api := meta.(*Client).API.RingfenceRulesApi
ringfenceRule, diags := ResolveRingfenceRuleFromResourceData(ctx, d, api, token)
if diags != nil {
return diags
}
d.SetId(ringfenceRule.GetId())
d.Set("ringfence_rule_id", ringfenceRule.GetId())
d.Set("ringfence_rule_name", ringfenceRule.GetName())
d.Set("tags", ringfenceRule.GetTags())
return nil
}