Skip to content

Commit 405d970

Browse files
authored
fix: Solve crash when updating Dashboard v3 (#89)
* fix: Solve crash when updating Dashboard v3 * style: Format files * fix: Increase timeout while removing teams * style: Format files
1 parent 29aa4dd commit 405d970

File tree

4 files changed

+63
-3
lines changed

4 files changed

+63
-3
lines changed

sysdig/resource_sysdig_monitor_dashboard.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
1010
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
1111
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
12+
"github.com/spf13/cast"
1213

1314
"github.com/draios/terraform-provider-sysdig/sysdig/internal/client/monitor/model"
1415
)
@@ -227,7 +228,7 @@ func resourceSysdigDashboardDelete(ctx context.Context, data *schema.ResourceDat
227228

228229
func dashboardFromResourceData(data *schema.ResourceData) (dashboard *model.Dashboard, err error) {
229230
dashboard = model.NewDashboard(data.Get("name").(string), data.Get("description").(string)).AsPublic(data.Get("public").(bool))
230-
231+
dashboard.Version = cast.ToInt(data.Get("version"))
231232
dashboard.PublicToken = data.Get("public_token").(string)
232233

233234
panels, err := panelsFromResourceData(data)

sysdig/resource_sysdig_monitor_dashboard_test.go

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ func TestAccDashboard(t *testing.T) {
4141
ImportState: true,
4242
ImportStateVerify: true,
4343
},
44+
{
45+
Config: multipleUpdatedPanelsDashboard(rText()),
46+
},
4447
},
4548
})
4649
}
@@ -148,3 +151,59 @@ resource "sysdig_monitor_dashboard" "dashboard" {
148151
}
149152
`, name, name)
150153
}
154+
155+
func multipleUpdatedPanelsDashboard(name string) string {
156+
return fmt.Sprintf(`
157+
resource "sysdig_monitor_dashboard" "dashboard" {
158+
name = "TERRAFORM TEST - METRIC %s"
159+
description = "TERRAFORM TEST - METRIC %s"
160+
161+
panel {
162+
pos_x = 0
163+
pos_y = 0
164+
width = 12 # Maximum size: 24
165+
height = 6
166+
type = "timechart"
167+
name = "example panel"
168+
description = "description"
169+
170+
query {
171+
promql = "avg(avg_over_time(sysdig_host_cpu_used_percent[$__interval]))"
172+
unit = "percent"
173+
}
174+
query {
175+
promql = "avg(avg_over_time(sysdig_host_cpu_used_percent[$__interval]))"
176+
unit = "number"
177+
}
178+
}
179+
180+
panel {
181+
pos_x = 12
182+
pos_y = 0
183+
width = 12
184+
height = 12
185+
type = "number"
186+
name = "example panel - 2"
187+
description = "description of panel 2"
188+
189+
query {
190+
promql = "avg(avg_over_time(sysdig_host_cpu_used_percent[$__interval]))"
191+
unit = "time"
192+
}
193+
}
194+
195+
panel {
196+
pos_x = 12
197+
pos_y = 12
198+
width = 12
199+
height = 6
200+
type = "text"
201+
name = "example panel - 2"
202+
content = "description of panel 2"
203+
visible_title = true
204+
autosize_text = true
205+
transparent_background = true
206+
}
207+
}
208+
`, name, name)
209+
}

sysdig/resource_sysdig_monitor_team.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func resourceSysdigMonitorTeam() *schema.Resource {
2828
Create: schema.DefaultTimeout(timeout),
2929
Update: schema.DefaultTimeout(timeout),
3030
Read: schema.DefaultTimeout(timeout),
31-
Delete: schema.DefaultTimeout(timeout),
31+
Delete: schema.DefaultTimeout(5 * time.Minute), // Removing the team is for some reason slower.
3232
},
3333

3434
Schema: map[string]*schema.Schema{

sysdig/resource_sysdig_secure_team.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func resourceSysdigSecureTeam() *schema.Resource {
2828
Create: schema.DefaultTimeout(timeout),
2929
Update: schema.DefaultTimeout(timeout),
3030
Read: schema.DefaultTimeout(timeout),
31-
Delete: schema.DefaultTimeout(timeout),
31+
Delete: schema.DefaultTimeout(5 * time.Minute), // Removing the team is for some reason slower.
3232
},
3333

3434
Schema: map[string]*schema.Schema{

0 commit comments

Comments
 (0)