Skip to content

Commit fae1c6f

Browse files
authored
Merge pull request #138 from squaredup/work/ss/dashboard-variable
New Dashboard Variable Resource
2 parents b4ebf77 + 0481d34 commit fae1c6f

12 files changed

Lines changed: 982 additions & 48 deletions

File tree

docs/resources/dashboard.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ EOT
228228

229229
### Optional
230230

231+
- `dashboard_variable_id` (String) ID of the dashboard variable to use for this dashboard
231232
- `schema_version` (String) The schema version of the dashboard
232233
- `template_bindings` (String) Template Bindings used for replacing mustache template in the dashboard template. Needs to be a JSON encoded string.
233234
- `timeframe` (String) The timeframe of the dashboard. It should be one of the following: last1hour, last12hours, last24hours, last7days, last30days, thisMonth, thisQuarter, thisYear, lastMonth, lastQuarter, lastYear
Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "squaredup_dashboard_variable Resource - squaredup"
4+
subcategory: ""
5+
description: |-
6+
Dashboard variables allow you to create flexible and reusable dashboards, allowing dashboard viewers to switch between objects on the fly.
7+
---
8+
9+
# squaredup_dashboard_variable (Resource)
10+
11+
Dashboard variables allow you to create flexible and reusable dashboards, allowing dashboard viewers to switch between objects on the fly.
12+
13+
## Example Usage
14+
15+
```terraform
16+
data "squaredup_datasources" "sample_data" {
17+
data_source_name = "Sample Data"
18+
}
19+
20+
resource "squaredup_datasource" "sample_data_source" {
21+
display_name = "Sample Data"
22+
data_source_name = data.squaredup_datasources.sample_data.plugins[0].display_name
23+
}
24+
25+
data "squaredup_data_streams" "sample_data_logs_dataStreams" {
26+
data_source_id = data.squaredup_datasources.sample_data.plugins[0].id
27+
}
28+
29+
resource "squaredup_workspace" "application_workspace" {
30+
display_name = "Application Team"
31+
description = "Workspace with Dashboards for Application Team"
32+
datasources_links = [squaredup_datasource.sample_data_source.id]
33+
tags = ["dashboard-variable"]
34+
}
35+
36+
resource "squaredup_scope" "dynamic_scope" {
37+
scope_type = "dynamic"
38+
display_name = "Dynamic Scope"
39+
workspace_id = squaredup_workspace.application_workspace.id
40+
data_source_id = [squaredup_datasource.sample_data_source.id]
41+
types = ["sample-function"]
42+
search_query = "account-common"
43+
}
44+
45+
resource "squaredup_dashboard_variable" "example_all_variable" {
46+
workspace_id = squaredup_workspace.application_workspace.id
47+
collection_id = squaredup_scope.dynamic_scope.id
48+
default_object_selection = "all" # or "none"
49+
}
50+
51+
resource "squaredup_dashboard" "all_objects" {
52+
workspace_id = squaredup_workspace.application_workspace.id
53+
display_name = "All Objects"
54+
dashboard_variable_id = squaredup_dashboard_variable.example_all_variable.id
55+
dashboard_template = <<EOT
56+
{
57+
"_type": "layout/grid",
58+
"contents": [
59+
{
60+
"x": 0,
61+
"h": 2,
62+
"i": "ebd9b9cd-2fb3-4978-9a7e-0c96a70a6e41",
63+
"y": 0,
64+
"config": {
65+
"variables": [
66+
"{{example_variable_id}}"
67+
],
68+
"scope": {
69+
"workspace": "{{workspace_id}}",
70+
"scope": "{{dynamic_scope_id}}"
71+
},
72+
"dataStream": {
73+
"name": "perf-lambda-duration",
74+
"id": "{{perf_lambda_duration_datastream_id}}"
75+
},
76+
"_type": "tile/data-stream",
77+
"description": "",
78+
"title": "Lambda Duration",
79+
"visualisation": {
80+
"type": "data-stream-line-graph",
81+
"config": {
82+
"data-stream-line-graph": {
83+
"seriesColumn": "data.lambdaDuration.label",
84+
"xAxisColumn": "data.timestamp",
85+
"yAxisColumn": "data.lambdaDuration.value"
86+
}
87+
}
88+
}
89+
},
90+
"w": 4
91+
}
92+
],
93+
"version": 1,
94+
"columns": 4
95+
}
96+
EOT
97+
template_bindings = jsonencode({
98+
example_variable_id = squaredup_dashboard_variable.example_variable.id
99+
workspace_id = squaredup_workspace.application_workspace.id
100+
dynamic_scope_id = squaredup_scope.dynamic_scope.id
101+
perf_lambda_duration_datastream_id = data.squaredup_data_streams.sample_data_logs_dataStreams.data_streams[index(data.squaredup_data_streams.sample_data_logs_dataStreams.data_streams.*.definition_name, "perf-lambda-duration")].id
102+
})
103+
}
104+
105+
resource "squaredup_dashboard_variable" "example_none_variable" {
106+
workspace_id = squaredup_workspace.application_workspace.id
107+
collection_id = squaredup_scope.dynamic_scope.id
108+
default_object_selection = "none"
109+
allow_multiple_object_selection = true
110+
}
111+
112+
resource "squaredup_dashboard" "no_default_objects" {
113+
workspace_id = squaredup_workspace.application_workspace.id
114+
display_name = "No Default Objects"
115+
dashboard_variable_id = squaredup_dashboard_variable.example_none_variable.id
116+
dashboard_template = <<EOT
117+
{
118+
"_type": "layout/grid",
119+
"columns": 4,
120+
"contents": [
121+
{
122+
"i": "5cbfb630-ba91-445a-aaaa-eb7fe9161ca0",
123+
"x": 0,
124+
"y": 0,
125+
"w": 4,
126+
"h": 2,
127+
"config": {
128+
"title": "Cost",
129+
"description": "",
130+
"_type": "tile/data-stream",
131+
"variables": [
132+
"{{example_none_variable_id}}"
133+
],
134+
"scope": {
135+
"scope": "{{dynamic_scope_id}}",
136+
"workspace": "{{workspace_id}}"
137+
},
138+
"dataStream": {
139+
"id": "{{perf_cost_datastream_id}}",
140+
"name": "perf-cost"
141+
},
142+
"visualisation": {
143+
"type": "data-stream-line-graph",
144+
"config": {
145+
"data-stream-line-graph": {
146+
"xAxisColumn": "data.timestamp",
147+
"yAxisColumn": "data.cost.value",
148+
"seriesColumn": "data.cost.label"
149+
}
150+
}
151+
}
152+
}
153+
}
154+
],
155+
"version": 1
156+
}
157+
EOT
158+
template_bindings = jsonencode({
159+
example_none_variable_id = squaredup_dashboard_variable.example_none_variable.id
160+
workspace_id = squaredup_workspace.application_workspace.id
161+
dynamic_scope_id = squaredup_scope.dynamic_scope.id
162+
perf_cost_datastream_id = data.squaredup_data_streams.sample_data_logs_dataStreams.data_streams[index(data.squaredup_data_streams.sample_data_logs_dataStreams.data_streams.*.definition_name, "perf-cost")].id
163+
})
164+
}
165+
```
166+
167+
<!-- schema generated by tfplugindocs -->
168+
## Schema
169+
170+
### Required
171+
172+
- `collection_id` (String) The id of the collection (scope) for the dashboard variable.
173+
- `default_object_selection` (String) The default object selection for the dashboard variable. Allowed values: `none`, `all`.
174+
- `workspace_id` (String) The id of the workspace.
175+
176+
### Optional
177+
178+
- `allow_multiple_object_selection` (Boolean) Whether to allow users to select multiple objects for the dashboard variable.
179+
180+
### Read-Only
181+
182+
- `id` (String) The id of the dashboard variable.
183+
- `last_updated` (String) Last updated timestamp of the dashboard variable
184+
185+
## Import
186+
187+
Import is supported using the following syntax:
188+
189+
```shell
190+
# Dashboard variable can be imported using the variable id.
191+
terraform import squaredup_dashboard_variable.example variable-123
192+
```
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Dashboard variable can be imported using the variable id.
2+
terraform import squaredup_dashboard_variable.example variable-123
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
data "squaredup_datasources" "sample_data" {
2+
data_source_name = "Sample Data"
3+
}
4+
5+
resource "squaredup_datasource" "sample_data_source" {
6+
display_name = "Sample Data"
7+
data_source_name = data.squaredup_datasources.sample_data.plugins[0].display_name
8+
}
9+
10+
data "squaredup_data_streams" "sample_data_logs_dataStreams" {
11+
data_source_id = data.squaredup_datasources.sample_data.plugins[0].id
12+
}
13+
14+
resource "squaredup_workspace" "application_workspace" {
15+
display_name = "Application Team"
16+
description = "Workspace with Dashboards for Application Team"
17+
datasources_links = [squaredup_datasource.sample_data_source.id]
18+
tags = ["dashboard-variable"]
19+
}
20+
21+
resource "squaredup_scope" "dynamic_scope" {
22+
scope_type = "dynamic"
23+
display_name = "Dynamic Scope"
24+
workspace_id = squaredup_workspace.application_workspace.id
25+
data_source_id = [squaredup_datasource.sample_data_source.id]
26+
types = ["sample-function"]
27+
search_query = "account-common"
28+
}
29+
30+
resource "squaredup_dashboard_variable" "example_all_variable" {
31+
workspace_id = squaredup_workspace.application_workspace.id
32+
collection_id = squaredup_scope.dynamic_scope.id
33+
default_object_selection = "all" # or "none"
34+
}
35+
36+
resource "squaredup_dashboard" "all_objects" {
37+
workspace_id = squaredup_workspace.application_workspace.id
38+
display_name = "All Objects"
39+
dashboard_variable_id = squaredup_dashboard_variable.example_all_variable.id
40+
dashboard_template = <<EOT
41+
{
42+
"_type": "layout/grid",
43+
"contents": [
44+
{
45+
"x": 0,
46+
"h": 2,
47+
"i": "ebd9b9cd-2fb3-4978-9a7e-0c96a70a6e41",
48+
"y": 0,
49+
"config": {
50+
"variables": [
51+
"{{example_variable_id}}"
52+
],
53+
"scope": {
54+
"workspace": "{{workspace_id}}",
55+
"scope": "{{dynamic_scope_id}}"
56+
},
57+
"dataStream": {
58+
"name": "perf-lambda-duration",
59+
"id": "{{perf_lambda_duration_datastream_id}}"
60+
},
61+
"_type": "tile/data-stream",
62+
"description": "",
63+
"title": "Lambda Duration",
64+
"visualisation": {
65+
"type": "data-stream-line-graph",
66+
"config": {
67+
"data-stream-line-graph": {
68+
"seriesColumn": "data.lambdaDuration.label",
69+
"xAxisColumn": "data.timestamp",
70+
"yAxisColumn": "data.lambdaDuration.value"
71+
}
72+
}
73+
}
74+
},
75+
"w": 4
76+
}
77+
],
78+
"version": 1,
79+
"columns": 4
80+
}
81+
EOT
82+
template_bindings = jsonencode({
83+
example_variable_id = squaredup_dashboard_variable.example_variable.id
84+
workspace_id = squaredup_workspace.application_workspace.id
85+
dynamic_scope_id = squaredup_scope.dynamic_scope.id
86+
perf_lambda_duration_datastream_id = data.squaredup_data_streams.sample_data_logs_dataStreams.data_streams[index(data.squaredup_data_streams.sample_data_logs_dataStreams.data_streams.*.definition_name, "perf-lambda-duration")].id
87+
})
88+
}
89+
90+
resource "squaredup_dashboard_variable" "example_none_variable" {
91+
workspace_id = squaredup_workspace.application_workspace.id
92+
collection_id = squaredup_scope.dynamic_scope.id
93+
default_object_selection = "none"
94+
allow_multiple_object_selection = true
95+
}
96+
97+
resource "squaredup_dashboard" "no_default_objects" {
98+
workspace_id = squaredup_workspace.application_workspace.id
99+
display_name = "No Default Objects"
100+
dashboard_variable_id = squaredup_dashboard_variable.example_none_variable.id
101+
dashboard_template = <<EOT
102+
{
103+
"_type": "layout/grid",
104+
"columns": 4,
105+
"contents": [
106+
{
107+
"i": "5cbfb630-ba91-445a-aaaa-eb7fe9161ca0",
108+
"x": 0,
109+
"y": 0,
110+
"w": 4,
111+
"h": 2,
112+
"config": {
113+
"title": "Cost",
114+
"description": "",
115+
"_type": "tile/data-stream",
116+
"variables": [
117+
"{{example_none_variable_id}}"
118+
],
119+
"scope": {
120+
"scope": "{{dynamic_scope_id}}",
121+
"workspace": "{{workspace_id}}"
122+
},
123+
"dataStream": {
124+
"id": "{{perf_cost_datastream_id}}",
125+
"name": "perf-cost"
126+
},
127+
"visualisation": {
128+
"type": "data-stream-line-graph",
129+
"config": {
130+
"data-stream-line-graph": {
131+
"xAxisColumn": "data.timestamp",
132+
"yAxisColumn": "data.cost.value",
133+
"seriesColumn": "data.cost.label"
134+
}
135+
}
136+
}
137+
}
138+
}
139+
],
140+
"version": 1
141+
}
142+
EOT
143+
template_bindings = jsonencode({
144+
example_none_variable_id = squaredup_dashboard_variable.example_none_variable.id
145+
workspace_id = squaredup_workspace.application_workspace.id
146+
dynamic_scope_id = squaredup_scope.dynamic_scope.id
147+
perf_cost_datastream_id = data.squaredup_data_streams.sample_data_logs_dataStreams.data_streams[index(data.squaredup_data_streams.sample_data_logs_dataStreams.data_streams.*.definition_name, "perf-cost")].id
148+
})
149+
}

0 commit comments

Comments
 (0)