From 3b2ec12e67e4542feb801982b239be6e3ae5a8c1 Mon Sep 17 00:00:00 2001 From: Shaswot Subedi Date: Tue, 19 Dec 2023 17:17:07 +0000 Subject: [PATCH 1/3] support dashboard timeframes --- internal/provider/client_dashboard.go | 6 ++++-- internal/provider/models.go | 1 + internal/provider/resource_dashboard.go | 28 +++++++++++++++++++++++-- 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/internal/provider/client_dashboard.go b/internal/provider/client_dashboard.go index d2b7711..a672896 100644 --- a/internal/provider/client_dashboard.go +++ b/internal/provider/client_dashboard.go @@ -6,11 +6,12 @@ import ( "strings" ) -func (c *SquaredUpClient) CreateDashboard(displayName string, workspaceId string, dashboardContent string) (*Dashboard, error) { +func (c *SquaredUpClient) CreateDashboard(displayName string, workspaceId string, timeframe string, dashboardContent string) (*Dashboard, error) { DashboardPayload := map[string]interface{}{ "displayName": displayName, "workspaceId": workspaceId, + "timeframe": timeframe, } rb, err := json.Marshal(DashboardPayload) @@ -59,10 +60,11 @@ func (c *SquaredUpClient) GetDashboard(dashboardId string) (*Dashboard, error) { return &newDashboard, nil } -func (c *SquaredUpClient) UpdateDashboard(dashboardId string, displayName string, workspaceId string, dashboardContent string) (*Dashboard, error) { +func (c *SquaredUpClient) UpdateDashboard(dashboardId string, displayName string, workspaceId string, timeframe string, dashboardContent string) (*Dashboard, error) { DashboardPayload := map[string]interface{}{ "displayName": displayName, "workspaceId": workspaceId, + "timeframe": timeframe, } rb, err := json.Marshal(DashboardPayload) diff --git a/internal/provider/models.go b/internal/provider/models.go index 46c5a86..d4bc178 100644 --- a/internal/provider/models.go +++ b/internal/provider/models.go @@ -86,6 +86,7 @@ type Dashboard struct { Group string `json:"group,omitempty"` Name string `json:"name"` SchemaVersion string `json:"schemaVersion"` + Timeframe string `json:"timeframe,omitempty"` } type SquaredupGremlinQuery struct { diff --git a/internal/provider/resource_dashboard.go b/internal/provider/resource_dashboard.go index 00ae16e..31da078 100644 --- a/internal/provider/resource_dashboard.go +++ b/internal/provider/resource_dashboard.go @@ -7,11 +7,13 @@ import ( "github.com/cbroglie/mustache" "github.com/hashicorp/terraform-plugin-framework-jsontypes/jsontypes" + "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/resource/schema" "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" + "github.com/hashicorp/terraform-plugin-framework/schema/validator" "github.com/hashicorp/terraform-plugin-framework/types" ) @@ -36,6 +38,7 @@ type squaredupDashboard struct { DashboardTemplate jsontypes.Normalized `tfsdk:"dashboard_template"` TemplateBindings jsontypes.Normalized `tfsdk:"template_bindings"` DashboardContent jsontypes.Normalized `tfsdk:"dashboard_content"` + Timeframe types.String `tfsdk:"timeframe"` Group types.String `tfsdk:"group"` Name types.String `tfsdk:"name"` SchemaVersion types.String `tfsdk:"schema_version"` @@ -81,6 +84,24 @@ func (r *DashboardResource) Schema(_ context.Context, _ resource.SchemaRequest, Computed: true, CustomType: jsontypes.NormalizedType{}, }, + "timeframe": schema.StringAttribute{ + Description: "The timeframe of the dashboard. It should be one of the following: last1hour, last12hours, last24hours, last7days, last30days, thisMonth, thisQuarter, thisYear, lastMonth, lastQuarter, lastYear", + Optional: true, + Computed: true, + Validators: []validator.String{stringvalidator.OneOf( + "last1hour", + "last12hours", + "last24hours", + "last7days", + "last30days", + "thisMonth", + "thisQuarter", + "thisYear", + "lastMonth", + "lastQuarter", + "lastYear", + )}, + }, "group": schema.StringAttribute{ Description: "The group of the dashboard", Computed: true, @@ -149,7 +170,7 @@ func (r *DashboardResource) Create(ctx context.Context, req resource.CreateReque plan.TemplateBindings = jsontypes.NewNormalizedNull() } - dashboard, err := r.client.CreateDashboard(plan.DisplayName.ValueString(), plan.WorkspaceID.ValueString(), updatedDashboard) + dashboard, err := r.client.CreateDashboard(plan.DisplayName.ValueString(), plan.WorkspaceID.ValueString(), plan.Timeframe.ValueString(), updatedDashboard) if err != nil { resp.Diagnostics.AddError( "Unable to create dashboard", @@ -165,6 +186,7 @@ func (r *DashboardResource) Create(ctx context.Context, req resource.CreateReque DashboardTemplate: plan.DashboardTemplate, TemplateBindings: plan.TemplateBindings, DashboardContent: jsontypes.NewNormalizedValue(updatedDashboard), + Timeframe: types.StringValue(dashboard.Timeframe), Group: types.StringValue(dashboard.Group), Name: types.StringValue(dashboard.Name), SchemaVersion: types.StringValue(dashboard.SchemaVersion), @@ -203,6 +225,7 @@ func (r *DashboardResource) Read(ctx context.Context, req resource.ReadRequest, DashboardTemplate: state.DashboardTemplate, TemplateBindings: state.TemplateBindings, DashboardContent: state.DashboardContent, + Timeframe: types.StringValue(dashboard.Timeframe), Group: types.StringValue(dashboard.Group), Name: types.StringValue(dashboard.Name), SchemaVersion: types.StringValue(dashboard.SchemaVersion), @@ -253,7 +276,7 @@ func (r *DashboardResource) Update(ctx context.Context, req resource.UpdateReque plan.TemplateBindings = jsontypes.NewNormalizedNull() } - dashboard, err := r.client.UpdateDashboard(state.DashboardID.ValueString(), plan.DisplayName.ValueString(), state.DashboardID.String(), updatedDashboard) + dashboard, err := r.client.UpdateDashboard(state.DashboardID.ValueString(), plan.DisplayName.ValueString(), state.DashboardID.String(), plan.Timeframe.ValueString(), updatedDashboard) if err != nil { resp.Diagnostics.AddError( "Unable to update dashboard", @@ -269,6 +292,7 @@ func (r *DashboardResource) Update(ctx context.Context, req resource.UpdateReque DashboardTemplate: plan.DashboardTemplate, TemplateBindings: plan.TemplateBindings, DashboardContent: jsontypes.NewNormalizedValue(updatedDashboard), + Timeframe: types.StringValue(dashboard.Timeframe), Group: types.StringValue(dashboard.Group), Name: types.StringValue(dashboard.Name), SchemaVersion: types.StringValue(dashboard.SchemaVersion), From 4dfd8a4ad228cce93a1c8536b60a35ef720c8f16 Mon Sep 17 00:00:00 2001 From: Shaswot Subedi Date: Tue, 19 Dec 2023 17:17:28 +0000 Subject: [PATCH 2/3] timeframe docs --- .vscode/settings.json | 1 + docs/resources/dashboard.md | 2 ++ examples/resources/squaredup_dashboard/resource.tf | 1 + 3 files changed, 4 insertions(+) diff --git a/.vscode/settings.json b/.vscode/settings.json index f25785b..caae88b 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -16,6 +16,7 @@ "stringvalidator", "tfprotov", "tfsdk", + "timeframe", "unmarshalling", "visualisation" ] diff --git a/docs/resources/dashboard.md b/docs/resources/dashboard.md index a21acec..7ced219 100644 --- a/docs/resources/dashboard.md +++ b/docs/resources/dashboard.md @@ -129,6 +129,7 @@ EOT }) workspace_id = squaredup_workspace.application_workspace.id display_name = "Sample Dashboard" + timeframe = "last12hours" } ``` @@ -144,6 +145,7 @@ EOT ### Optional - `template_bindings` (String) Template Bindings used for replacing mustache template in the dashboard template. Needs to be a JSON encoded string. +- `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 ### Read-Only diff --git a/examples/resources/squaredup_dashboard/resource.tf b/examples/resources/squaredup_dashboard/resource.tf index 7f50bcc..d39192e 100644 --- a/examples/resources/squaredup_dashboard/resource.tf +++ b/examples/resources/squaredup_dashboard/resource.tf @@ -114,4 +114,5 @@ EOT }) workspace_id = squaredup_workspace.application_workspace.id display_name = "Sample Dashboard" + timeframe = "last12hours" } From c4dc3284028f55287e9ade7d6db4bd718f46b9ef Mon Sep 17 00:00:00 2001 From: Shaswot Subedi Date: Tue, 19 Dec 2023 20:42:03 +0000 Subject: [PATCH 3/3] cspell configuration --- .vscode/settings.json => cspell.json | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) rename .vscode/settings.json => cspell.json (66%) diff --git a/.vscode/settings.json b/cspell.json similarity index 66% rename from .vscode/settings.json rename to cspell.json index caae88b..de14b2d 100644 --- a/.vscode/settings.json +++ b/cspell.json @@ -1,5 +1,15 @@ { - "cSpell.words": [ + "version": "0.2", + "language": "en,en-US", + "allowCompoundWords": true, + "dictionaries": [ + "en_US", + "en_GB", + "softwareTerms", + "golang", + "bash" + ], + "words": [ "basetypes", "cbroglie", "datasource", @@ -20,4 +30,4 @@ "unmarshalling", "visualisation" ] -} \ No newline at end of file +}