Skip to content

Commit 266b0c6

Browse files
authored
fix: Solve fields not correctly set (#69)
Some fields weren't being correctly set when retrieved from the API, like: - `severity` in all `sysdig_monitor_alert_*` resources - `can_see_infrastructure_events` in `sysdig_monitor_team` - `can_use_aws_data` in `sysdig_monitor_team` - `severity` in `sysdig_secure_policy` Also - `tcp.ports` and `udp.ports` in `sysdig_secure_rule_network` weren't being created correctly in the backend, thus, creating a network rule with no checked ports.
1 parent 8325d23 commit 266b0c6

5 files changed

+34
-15
lines changed

sysdig/resource_sysdig_monitor_alert_common.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ func alertToResourceData(alert *monitor.Alert, data *schema.ResourceData) (err e
139139
data.Set("trigger_after_minutes", int(trigger_after_minutes.Minutes()))
140140
data.Set("team", alert.TeamID)
141141
data.Set("enabled", alert.Enabled)
142+
data.Set("severity", alert.Severity)
142143

143144
if len(alert.NotificationChannelIds) > 0 {
144145
data.Set("notification_channels", alert.NotificationChannelIds)

sysdig/resource_sysdig_monitor_team.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,8 @@ func resourceSysdigMonitorTeamRead(ctx context.Context, d *schema.ResourceData,
154154
d.Set("scope_by", t.Show)
155155
d.Set("filter", t.Filter)
156156
d.Set("can_use_sysdig_capture", t.CanUseSysdigCapture)
157+
d.Set("can_see_infrastructure_events", t.CanUseCustomEvents)
158+
d.Set("can_use_aws_data", t.CanUseAwsMetrics)
157159
d.Set("default_team", t.DefaultTeam)
158160
d.Set("user_roles", userMonitorRolesToSet(t.UserRoles))
159161
d.Set("entrypoint", entrypointToSet(t.EntryPoint))

sysdig/resource_sysdig_secure_policy.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ func resourceSysdigPolicyRead(ctx context.Context, d *schema.ResourceData, meta
214214
d.Set("scope", policy.Scope)
215215
d.Set("enabled", policy.Enabled)
216216
d.Set("version", policy.Version)
217+
d.Set("severity", policy.Severity)
217218

218219
actions := []map[string]interface{}{{}}
219220
for _, action := range policy.Actions {

sysdig/resource_sysdig_secure_rule_network.go

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func resourceSysdigSecureRuleNetwork() *schema.Resource {
4747
Default: true,
4848
},
4949
"ports": {
50-
Type: schema.TypeList,
50+
Type: schema.TypeSet,
5151
Required: true,
5252
Elem: &schema.Schema{
5353
Type: schema.TypeInt,
@@ -67,7 +67,7 @@ func resourceSysdigSecureRuleNetwork() *schema.Resource {
6767
Default: true,
6868
},
6969
"ports": {
70-
Type: schema.TypeList,
70+
Type: schema.TypeSet,
7171
Required: true,
7272
Elem: &schema.Schema{
7373
Type: schema.TypeInt,
@@ -133,15 +133,31 @@ func resourceSysdigRuleNetworkRead(ctx context.Context, d *schema.ResourceData,
133133
}
134134

135135
if len(rule.Details.TCPListenPorts.Items) > 0 {
136+
tcpPorts := []int{}
137+
for _, port := range rule.Details.TCPListenPorts.Items {
138+
intPort, err := strconv.Atoi(port)
139+
if err != nil {
140+
return diag.FromErr(err)
141+
}
142+
tcpPorts = append(tcpPorts, intPort)
143+
}
136144
d.Set("tcp", []map[string]interface{}{{
137145
"matching": rule.Details.TCPListenPorts.MatchItems,
138-
"ports": rule.Details.TCPListenPorts.Items,
146+
"ports": tcpPorts,
139147
}})
140148
}
141149
if len(rule.Details.UDPListenPorts.Items) > 0 {
150+
udpPorts := []int{}
151+
for _, port := range rule.Details.UDPListenPorts.Items {
152+
intPort, err := strconv.Atoi(port)
153+
if err != nil {
154+
return diag.FromErr(err)
155+
}
156+
udpPorts = append(udpPorts, intPort)
157+
}
142158
d.Set("udp", []map[string]interface{}{{
143159
"matching": rule.Details.UDPListenPorts.MatchItems,
144-
"ports": rule.Details.UDPListenPorts.Items,
160+
"ports": udpPorts,
145161
}})
146162
}
147163

@@ -200,23 +216,22 @@ func resourceSysdigRuleNetworkFromResourceData(d *schema.ResourceData) (rule sec
200216
rule.Details.AllOutbound = d.Get("block_outbound").(bool)
201217

202218
rule.Details.TCPListenPorts.Items = []string{}
203-
if tcpRules, ok := d.Get("tcp").([]interface{}); ok && len(tcpRules) > 0 {
219+
if tcpRules := d.Get("tcp").([]interface{}); len(tcpRules) > 0 {
204220
rule.Details.TCPListenPorts.MatchItems = d.Get("tcp.0.matching").(bool)
205-
for _, port := range d.Get("tcp.0.ports").([]interface{}) {
206-
if portStr, ok := port.(string); ok {
207-
rule.Details.TCPListenPorts.Items = append(rule.Details.TCPListenPorts.Items, portStr)
208-
}
221+
for _, port := range d.Get("tcp.0.ports").(*schema.Set).List() {
222+
portStr := port.(int)
223+
rule.Details.TCPListenPorts.Items = append(rule.Details.TCPListenPorts.Items, strconv.Itoa(portStr))
209224
}
210225
}
211226

212227
rule.Details.UDPListenPorts.Items = []string{}
213228
if udpRules, ok := d.Get("udp").([]interface{}); ok && len(udpRules) > 0 {
214229
rule.Details.UDPListenPorts.MatchItems = d.Get("udp.0.matching").(bool)
215-
for _, port := range d.Get("udp.0.ports").([]interface{}) {
216-
if portStr, ok := port.(string); ok {
217-
rule.Details.UDPListenPorts.Items = append(rule.Details.UDPListenPorts.Items, portStr)
218-
}
230+
for _, port := range d.Get("udp.0.ports").(*schema.Set).List() {
231+
portStr := port.(int)
232+
rule.Details.UDPListenPorts.Items = append(rule.Details.UDPListenPorts.Items, strconv.Itoa(portStr))
219233
}
220234
}
235+
221236
return
222237
}

sysdig/resource_sysdig_secure_rule_process_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ resource "sysdig_secure_rule_process" "foo" {
4646
tags = ["container", "cis"]
4747
4848
matching = true // default
49-
processes = ["bash"]
49+
processes = ["bash", "sh"]
5050
}`, name, name)
5151
}
5252

@@ -57,7 +57,7 @@ resource "sysdig_secure_rule_process" "foo" {
5757
description = "TERRAFORM TEST %s"
5858
5959
matching = true // default
60-
processes = ["bash"]
60+
processes = ["bash", "sh"]
6161
}`, name, name)
6262
}
6363

0 commit comments

Comments
 (0)