Skip to content

Commit a130c55

Browse files
authored
fix: Modify to not require condition when appending rule (#200)
1 parent a75db65 commit a130c55

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

sysdig/resource_sysdig_secure_rule_falco.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func resourceSysdigSecureRuleFalco() *schema.Resource {
3838
Schema: createRuleSchema(map[string]*schema.Schema{
3939
"condition": {
4040
Type: schema.TypeString,
41-
Required: true,
41+
Optional: true,
4242
},
4343
"output": {
4444
Type: schema.TypeString,
@@ -132,8 +132,10 @@ func resourceSysdigRuleFalcoRead(ctx context.Context, d *schema.ResourceData, me
132132
d.SetId("")
133133
}
134134

135-
if rule.Details.Condition == nil {
136-
return diag.Errorf("no condition data for a falco rule")
135+
if rule.Details.Append != nil && !(*(rule.Details.Append)) {
136+
if rule.Details.Condition == nil {
137+
return diag.Errorf("no condition data for a falco rule")
138+
}
137139
}
138140

139141
updateResourceDataForRule(d, rule)

sysdig/resource_sysdig_secure_rule_falco_test.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ func TestAccRuleFalco(t *testing.T) {
1818

1919
ruleRandomImmutableText := rText()
2020

21+
randomText := rText()
2122
resource.ParallelTest(t, resource.TestCase{
2223
PreCheck: func() {
2324
if v := os.Getenv("SYSDIG_SECURE_API_TOKEN"); v == "" {
@@ -67,7 +68,10 @@ func TestAccRuleFalco(t *testing.T) {
6768
ExpectError: regexp.MustCompile("source must be set when append = false"),
6869
},
6970
{
70-
Config: ruleFalcoWithExceptions(rText()),
71+
Config: ruleFalcoWithExceptions(randomText),
72+
},
73+
{
74+
Config: existingFalcoRuleWithExceptions(randomText),
7175
},
7276
},
7377
})
@@ -182,3 +186,19 @@ resource "sysdig_secure_rule_falco" "attach_to_cluster_admin_role" {
182186
}
183187
`, name)
184188
}
189+
190+
func existingFalcoRuleWithExceptions(name string) string {
191+
192+
return `
193+
resource "sysdig_secure_rule_falco" "attach_to_cluster_admin_role_exceptions" {
194+
name = "Terminal shell in container" # Sysdig-provided
195+
append = true
196+
197+
exceptions {
198+
name = "proc_name"
199+
fields = ["proc.name"]
200+
comps = ["in"]
201+
values = jsonencode(["sh"])
202+
}
203+
}`
204+
}

0 commit comments

Comments
 (0)