-
Notifications
You must be signed in to change notification settings - Fork 55
Expand file tree
/
Copy pathdata_source_sysdig_secure_rule_stateful_count.go
More file actions
58 lines (48 loc) · 1.31 KB
/
data_source_sysdig_secure_rule_stateful_count.go
File metadata and controls
58 lines (48 loc) · 1.31 KB
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
package sysdig
import (
"context"
"fmt"
"time"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func dataSourceSysdigSecureRuleStatefulCount() *schema.Resource {
timeout := 1 * time.Minute
return &schema.Resource{
ReadContext: dataSourceSysdigRuleStatefulCountRead,
Timeouts: &schema.ResourceTimeout{
Read: schema.DefaultTimeout(timeout),
},
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
},
"source": {
Type: schema.TypeString,
Required: true,
ValidateDiagFunc: validateDiagFunc(validateStatefulRuleSource),
},
"rule_count": {
Type: schema.TypeInt,
Computed: true,
},
},
}
}
func dataSourceSysdigRuleStatefulCountRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
client, err := getSecureRuleClient(meta.(SysdigClients))
if err != nil {
return diag.FromErr(err)
}
ruleName := d.Get("name").(string)
ruleType := d.Get("source").(string)
rules, err := client.GetStatefulRuleGroup(ctx, ruleName, ruleType)
if err != nil {
return diag.FromErr(err)
}
d.SetId(fmt.Sprintf("count__%s__%s", ruleName, ruleType))
_ = d.Set("name", ruleName)
_ = d.Set("rule_count", len(rules))
return nil
}