Skip to content

Commit dc4e154

Browse files
authored
fix: Allow severity values 1, 2, 3 and 5 in Policies (#54)
* docs: Update examples * fix: Allow policy severity values (1,2,3,5) * style: Format resource_sysdig_secure_policy
1 parent 4a18a3e commit dc4e154

File tree

5 files changed

+50
-28
lines changed

5 files changed

+50
-28
lines changed

examples/notification.tf

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,48 @@
11

2-
resource "sysdig_secure_notification_channel" "sample-email" {
2+
resource "sysdig_secure_notification_channel_email" "sample-email" {
33
name = "Example Channel - Email"
44
enabled = true
5-
type = "EMAIL"
6-
recipients = "[email protected]"
5+
recipients = ["[email protected]"]
76
notify_when_ok = false
87
notify_when_resolved = false
98
}
109

11-
resource "sysdig_secure_notification_channel" "sample-amazon-sns" {
10+
resource "sysdig_secure_notification_channel_sns" "sample-amazon-sns" {
1211
name = "Example Channel - Amazon SNS"
1312
enabled = true
14-
type = "SNS"
15-
topics = "arn:aws:sns:us-east-1:273107874544:my-alerts,arn:aws:sns:us-east-1:273107874544:my-alerts2"
13+
topics = ["arn:aws:sns:us-east-1:273107874544:my-alerts", "arn:aws:sns:us-east-1:273107874544:my-alerts2"]
1614
notify_when_ok = false
1715
notify_when_resolved = false
1816
}
1917

20-
resource "sysdig_secure_notification_channel" "sample-victorops" {
18+
resource "sysdig_secure_notification_channel_victorops" "sample-victorops" {
2119
name = "Example Channel - VictorOps"
2220
enabled = true
23-
type = "VICTOROPS"
2421
api_key = "1234342-4234243-4234-2"
2522
routing_key = "My team"
2623
notify_when_ok = false
2724
notify_when_resolved = false
2825
}
2926

30-
resource "sysdig_secure_notification_channel" "sample-opsgenie" {
27+
resource "sysdig_secure_notification_channel_opsgenie" "sample-opsgenie" {
3128
name = "Example Channel - OpsGenie"
3229
enabled = true
33-
type = "OPSGENIE"
3430
api_key = "2349324-342354353-5324-23"
3531
notify_when_ok = false
3632
notify_when_resolved = false
3733
}
3834

39-
resource "sysdig_secure_notification_channel" "sample-webhook" {
35+
resource "sysdig_secure_notification_channel_webhook" "sample-webhook" {
4036
name = "Example Channel - Webhook"
4137
enabled = true
42-
type = "WEBHOOK"
4338
url = "localhost:8080"
4439
notify_when_ok = false
4540
notify_when_resolved = false
4641
}
4742

48-
resource "sysdig_secure_notification_channel" "sample-slack" {
43+
resource "sysdig_secure_notification_channel_slack" "sample-slack" {
4944
name = "Example Channel - Slack"
5045
enabled = true
51-
type = "SLACK"
5246
url = "https://hooks.slack.cwom/services/XXXXXXXXX/XXXXXXXXX/XXXXXXXXXXXXXXXXXXXXXXXX"
5347
channel = "#sysdig"
5448
notify_when_ok = true

examples/user.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
resource "sysdig_user" "sample" {
2-
2+
33
system_role = "ROLE_CUSTOMER"
4-
first_name = "John"
5-
last_name = "Smith"
4+
first_name = "John"
5+
last_name = "Smith"
66
}

sysdig/resource_sysdig_secure_policy.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,10 @@ func resourceSysdigSecurePolicy() *schema.Resource {
5151
Required: true,
5252
},
5353
"severity": {
54-
Type: schema.TypeInt,
55-
Default: 4,
56-
Optional: true,
57-
ValidateFunc: validation.IntInSlice([]int{0, 4, 6, 7}),
54+
Type: schema.TypeInt,
55+
Default: 4,
56+
Optional: true,
57+
ValidateDiagFunc: validateDiagFunc(validation.IntBetween(0, 7)),
5858
},
5959
"enabled": {
6060
Type: schema.TypeBool,
@@ -100,14 +100,14 @@ func resourceSysdigSecurePolicy() *schema.Resource {
100100
Elem: &schema.Resource{
101101
Schema: map[string]*schema.Schema{
102102
"seconds_after_event": {
103-
Type: schema.TypeInt,
104-
Required: true,
105-
ValidateFunc: validation.IntAtLeast(0),
103+
Type: schema.TypeInt,
104+
Required: true,
105+
ValidateDiagFunc: validateDiagFunc(validation.IntAtLeast(0)),
106106
},
107107
"seconds_before_event": {
108-
Type: schema.TypeInt,
109-
Required: true,
110-
ValidateFunc: validation.IntAtLeast(0),
108+
Type: schema.TypeInt,
109+
Required: true,
110+
ValidateDiagFunc: validateDiagFunc(validation.IntAtLeast(0)),
111111
},
112112
},
113113
},

sysdig/resource_sysdig_secure_policy_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ func TestAccPolicy(t *testing.T) {
3737
{
3838
Config: policyWithMinimumConfiguration(rText()),
3939
},
40+
{
41+
Config: policiesWithDifferentSeverities(rText()),
42+
},
4043
},
4144
})
4245
}
@@ -104,3 +107,28 @@ resource "sysdig_secure_policy" "sample4" {
104107
}
105108
`, name, name)
106109
}
110+
111+
func policiesWithDifferentSeverities(name string) (res string) {
112+
for i := 0; i <= 7; i++ {
113+
res += fmt.Sprintf(`
114+
resource "sysdig_secure_policy" "sample_%d" {
115+
name = "TERRAFORM TEST 1 %s-%d"
116+
description = "TERRAFORM TEST %s-%d"
117+
enabled = true
118+
severity = %d
119+
scope = "container.id != \"\""
120+
rule_names = ["Terminal shell in container"]
121+
122+
actions {
123+
container = "stop"
124+
capture {
125+
seconds_before_event = 5
126+
seconds_after_event = 10
127+
}
128+
}
129+
}
130+
131+
`, i, name, i, name, i, i)
132+
}
133+
return
134+
}

website/docs/r/sysdig_secure_policy.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ resource "sysdig_secure_policy" "write_apt_database" {
4747
* `description` - (Required) The description of Secure policy.
4848

4949
* `severity` - (Optional) The severity of Secure policy. The accepted values
50-
are: 0 (High), 4 (Medium), 6 (Low) and 7 (Info). The default value is 4 (Medium).
50+
are: 0, 1, 2, 3 (High), 4, 5 (Medium), 6 (Low) and 7 (Info). The default value is 4 (Medium).
5151

5252
* `enabled` - (Optional) Will secure process with this rule?. By default this is true.
5353

0 commit comments

Comments
 (0)