-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for Dashboard Timeframe #21
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -86,6 +86,7 @@ type Dashboard struct { | |
Group string `json:"group,omitempty"` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't want to advertise Group (it was an old thing left over from Beacon days) |
||
Name string `json:"name"` | ||
SchemaVersion string `json:"schemaVersion"` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't want to advertise SchemaVersion (it's an internal thing used for dashboard migrations). Perhaps we need to strip SchemaVersion and Group from Dashobard reads (GETs) too. |
||
Timeframe string `json:"timeframe,omitempty"` | ||
} | ||
|
||
type SquaredupGremlinQuery struct { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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"` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto previous comment on SchemaVersion and Group |
||
|
@@ -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, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is timeframe marked as Computed (in fact lots of attribs are - obviously doesn't mean what I think it does)? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Its to handle null value as its marked as optional. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Ah, ta, so what value will it compute when null? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just an empty string |
||
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), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto previous comments on SchemaVersion and Group (both fields are referened in a few other places in this repo I haven't commented on too as not changed in this PR) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will do a cleanup of these based on our new API documentation. I have raised a JIRA for this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Thanks @shaswot77 |
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does adding a required argument (timeframe) impact upgrades of Terraform provider versions? e.g. user upgrades to this version of provider and their Terraform deployment breaks as now they need to provide an extra string argument.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
timeframe
is not a required argument. Its optional ininternal/provider/resource_dashboard.go