Skip to content

Commit

Permalink
support for change widgets + tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dashashifrina committed Oct 25, 2023
1 parent 6579a3f commit 7b3551d
Show file tree
Hide file tree
Showing 5 changed files with 167 additions and 0 deletions.
2 changes: 2 additions & 0 deletions datadog/resource_datadog_powerpack.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,8 @@ func ppkWidgetsToDashboardWidgets(ppkWidgets []datadogV2.PowerpackInnerWidgets)
switch widgetType {
case "alert_graph":
definition = datadogV1.AlertGraphWidgetDefinitionAsWidgetDefinition(buildDatadogAlertGraphDefinition(widgetDefinition))
case "change":
definition = datadogV1.ChangeWidgetDefinitionAsWidgetDefinition(buildDatadogChangeDefinition(widgetDefinition))
case "check_status":
definition = datadogV1.CheckStatusWidgetDefinitionAsWidgetDefinition(buildDatadogCheckStatusDefinition(widgetDefinition))
case "event_stream":
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2023-10-25T11:37:17.305655-04:00
106 changes: 106 additions & 0 deletions datadog/tests/cassettes/TestAccDatadogPowerpackChange.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
---
version: 1
interactions:
- request:
body: |
{"data":{"attributes":{"description":"Created using the Datadog provider in Terraform","group_widget":{"definition":{"layout_type":"ordered","title":"tf-TestAccDatadogPowerpackChange-local-1698248237","type":"group","widgets":[{"definition":{"requests":[{"change_type":"absolute","compare_to":"week_before","increase_good":true,"order_by":"name","order_dir":"desc","q":"avg:system.load.1{env:staging} by {account}","show_present":false}],"title":"Widget Title","type":"change"}}]}},"name":"tf-TestAccDatadogPowerpackChange-local-1698248237","tags":["tag:foo1"],"template_variables":[{"defaults":["defaults"],"name":"datacenter"}]},"type":"powerpack"}}
form: {}
headers:
Accept:
- application/json
Content-Type:
- application/json
url: https://api.datadoghq.com/api/v2/powerpacks
method: POST
response:
body: |
{"data":{"type":"powerpack","id":"61eaaa9a-734c-11ee-a4c1-da7ad0900002","attributes":{"name":"tf-TestAccDatadogPowerpackChange-local-1698248237","description":"Created using the Datadog provider in Terraform","group_widget":{"definition":{"layout_type":"ordered","title":"tf-TestAccDatadogPowerpackChange-local-1698248237","type":"group","widgets":[{"definition":{"requests":[{"change_type":"absolute","compare_to":"week_before","increase_good":true,"order_by":"name","order_dir":"desc","q":"avg:system.load.1{env:staging} by {account}","show_present":false}],"title":"Widget Title","type":"change"},"id":1146273042797575}]}},"template_variables":[{"defaults":["defaults"],"name":"datacenter"}],"tags":["tag:foo1"]},"relationships":{"author":{"data":{"type":"users","id":"3ad549bf-eba0-11e9-a77a-0705486660d0"}}}},"included":[{"type":"users","id":"3ad549bf-eba0-11e9-a77a-0705486660d0","attributes":{"name":null,"email":"[email protected]"}}]}
headers:
Content-Type:
- application/json
status: 200 OK
code: 200
duration: ""
- request:
body: ""
form: {}
headers:
Accept:
- application/json
url: https://api.datadoghq.com/api/v2/powerpacks/61eaaa9a-734c-11ee-a4c1-da7ad0900002
method: GET
response:
body: |
{"data":{"type":"powerpack","id":"61eaaa9a-734c-11ee-a4c1-da7ad0900002","attributes":{"name":"tf-TestAccDatadogPowerpackChange-local-1698248237","description":"Created using the Datadog provider in Terraform","group_widget":{"definition":{"layout_type":"ordered","title":"tf-TestAccDatadogPowerpackChange-local-1698248237","type":"group","widgets":[{"definition":{"requests":[{"change_type":"absolute","compare_to":"week_before","increase_good":true,"order_by":"name","order_dir":"desc","q":"avg:system.load.1{env:staging} by {account}","show_present":false}],"title":"Widget Title","type":"change"},"id":1146273042797575}]}},"template_variables":[{"defaults":["defaults"],"name":"datacenter"}],"tags":["tag:foo1"]},"relationships":{"author":{"data":{"type":"users","id":"3ad549bf-eba0-11e9-a77a-0705486660d0"}}}},"included":[{"type":"users","id":"3ad549bf-eba0-11e9-a77a-0705486660d0","attributes":{"name":null,"email":"[email protected]"}}]}
headers:
Content-Type:
- application/json
status: 200 OK
code: 200
duration: ""
- request:
body: ""
form: {}
headers:
Accept:
- application/json
url: https://api.datadoghq.com/api/v2/powerpacks/61eaaa9a-734c-11ee-a4c1-da7ad0900002
method: GET
response:
body: |
{"data":{"type":"powerpack","id":"61eaaa9a-734c-11ee-a4c1-da7ad0900002","attributes":{"name":"tf-TestAccDatadogPowerpackChange-local-1698248237","description":"Created using the Datadog provider in Terraform","group_widget":{"definition":{"layout_type":"ordered","title":"tf-TestAccDatadogPowerpackChange-local-1698248237","type":"group","widgets":[{"definition":{"requests":[{"change_type":"absolute","compare_to":"week_before","increase_good":true,"order_by":"name","order_dir":"desc","q":"avg:system.load.1{env:staging} by {account}","show_present":false}],"title":"Widget Title","type":"change"},"id":1146273042797575}]}},"template_variables":[{"defaults":["defaults"],"name":"datacenter"}],"tags":["tag:foo1"]},"relationships":{"author":{"data":{"type":"users","id":"3ad549bf-eba0-11e9-a77a-0705486660d0"}}}},"included":[{"type":"users","id":"3ad549bf-eba0-11e9-a77a-0705486660d0","attributes":{"name":null,"email":"[email protected]"}}]}
headers:
Content-Type:
- application/json
status: 200 OK
code: 200
duration: ""
- request:
body: ""
form: {}
headers:
Accept:
- application/json
url: https://api.datadoghq.com/api/v2/powerpacks/61eaaa9a-734c-11ee-a4c1-da7ad0900002
method: GET
response:
body: |
{"data":{"type":"powerpack","id":"61eaaa9a-734c-11ee-a4c1-da7ad0900002","attributes":{"name":"tf-TestAccDatadogPowerpackChange-local-1698248237","description":"Created using the Datadog provider in Terraform","group_widget":{"definition":{"layout_type":"ordered","title":"tf-TestAccDatadogPowerpackChange-local-1698248237","type":"group","widgets":[{"definition":{"requests":[{"change_type":"absolute","compare_to":"week_before","increase_good":true,"order_by":"name","order_dir":"desc","q":"avg:system.load.1{env:staging} by {account}","show_present":false}],"title":"Widget Title","type":"change"},"id":1146273042797575}]}},"template_variables":[{"defaults":["defaults"],"name":"datacenter"}],"tags":["tag:foo1"]},"relationships":{"author":{"data":{"type":"users","id":"3ad549bf-eba0-11e9-a77a-0705486660d0"}}}},"included":[{"type":"users","id":"3ad549bf-eba0-11e9-a77a-0705486660d0","attributes":{"name":null,"email":"[email protected]"}}]}
headers:
Content-Type:
- application/json
status: 200 OK
code: 200
duration: ""
- request:
body: ""
form: {}
headers:
Accept:
- '*/*'
url: https://api.datadoghq.com/api/v2/powerpacks/61eaaa9a-734c-11ee-a4c1-da7ad0900002
method: DELETE
response:
body: ""
headers:
Content-Type:
- text/html; charset=utf-8
status: 204 No Content
code: 204
duration: ""
- request:
body: ""
form: {}
headers:
Accept:
- application/json
url: https://api.datadoghq.com/api/v2/powerpacks/61eaaa9a-734c-11ee-a4c1-da7ad0900002
method: GET
response:
body: '{"errors":["Powerpack with ID 61eaaa9a-734c-11ee-a4c1-da7ad0900002 not found"]}'
headers:
Content-Type:
- application/json
status: 404 Not Found
code: 404
duration: ""
1 change: 1 addition & 0 deletions datadog/tests/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ var testFiles2EndpointTags = map[string]string{
"tests/resource_datadog_dashboard_treemap_test": "dashboards",
"tests/resource_datadog_powerpack_test": "powerpacks",
"tests/resource_datadog_powerpack_alert_graph_test": "powerpacks",
"tests/resource_datadog_powerpack_change_test": "powerpacks",
"tests/resource_datadog_powerpack_check_status_test": "powerpacks",
"tests/resource_datadog_powerpack_event_stream_test": "powerpacks",
"tests/resource_datadog_powerpack_iframe_test": "powerpacks",
Expand Down
57 changes: 57 additions & 0 deletions datadog/tests/resource_datadog_powerpack_change_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package test

import (
"testing"
)

const datadogPowerpackChangeTest = `
resource "datadog_powerpack" "change_powerpack" {
name = "{{uniq}}"
tags = ["tag:foo1"]
description = "Created using the Datadog provider in Terraform"
template_variables {
defaults = ["defaults"]
name = "datacenter"
}
widget {
change_definition {
request {
q = "avg:system.load.1{env:staging} by {account}"
change_type = "absolute"
compare_to = "week_before"
increase_good = true
order_by = "name"
order_dir = "desc"
show_present = false
}
title = "Widget Title"
}
}
}
`

var datadogPowerpackChangeTestAsserts = []string{
// Powerpack metadata
"description = Created using the Datadog provider in Terraform",
"widget.# = 1",
"tags.# = 1",
"tags.0 = tag:foo1",
// Change widget
"widget.0.change_definition.0.request.0.q = avg:system.load.1{env:staging} by {account}",
"widget.0.change_definition.0.request.0.change_type = absolute",
"widget.0.change_definition.0.request.0.compare_to = week_before",
"widget.0.change_definition.0.request.0.increase_good = true",
"widget.0.change_definition.0.request.0.order_by = name",
"widget.0.change_definition.0.request.0.order_dir = desc",
"widget.0.change_definition.0.request.0.show_present = false",
"widget.0.change_definition.0.title = Widget Title",
// Template Variables
"template_variables.# = 1",
"template_variables.0.name = datacenter",
"template_variables.0.defaults.# = 1",
"template_variables.0.defaults.0 = defaults",
}

func TestAccDatadogPowerpackChange(t *testing.T) {
testAccDatadogPowerpackWidgetUtil(t, datadogPowerpackChangeTest, "datadog_powerpack.change_powerpack", datadogPowerpackChangeTestAsserts)
}

0 comments on commit 7b3551d

Please sign in to comment.