Skip to content

Commit

Permalink
Adding properties sort_groups and sort_dimensions
Browse files Browse the repository at this point in the history
  • Loading branch information
dianibar committed Jan 19, 2024
1 parent 35ee031 commit 92e6df5
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 54 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
example.tf
terraform.tfplan
terraform.tfstate
.terraform.tfstate.lock.info
bin/
dist/
modules-dev/
Expand All @@ -25,6 +26,7 @@ website/node_modules
*.test
*.iml


website/vendor

# Test exclusions
Expand Down
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ terraform {
required_providers {
doit = {
source = "doitintl/doit"
version = "0.10.0"
version = "0.12.0"
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions docs/resources/report.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ Optional:
- `layout` (String)
- `metric` (Attributes) (see [below for nested schema](#nestedatt--config--metric))
- `metric_filter` (Attributes) (see [below for nested schema](#nestedatt--config--metric_filter))
- `sort_dimensions` (String) Sort dimensions. This configuration has no impact when reading a report's data via API. Default value is "desc".
- `sort_groups` (String) Sort groups. This configuration has no impact when reading a report's data via API. Default value is "asc".
- `splits` (Attributes List) The splits to use in the report. (see [below for nested schema](#nestedatt--config--splits))
- `time_interval` (String)
- `time_range` (Attributes) (see [below for nested schema](#nestedatt--config--time_range))
Expand Down
1 change: 0 additions & 1 deletion examples/.terraform.tfstate.lock.info

This file was deleted.

4 changes: 3 additions & 1 deletion examples/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@ terraform {
}
}

resource "doit_report" "my-report" {
resource "doit_report" "my-report_january" {
name = "my-report"
description = "description report"
config = {
metric = {
type = "basic"
value = "cost"
}
sort_groups = "asc"
sort_dimensions = "asc"
advanced_analysis = {
trending_up = true
trending_down = false
Expand Down
2 changes: 1 addition & 1 deletion examples/provider/provider.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ terraform {
required_providers {
doit = {
source = "doitintl/doit"
version = "0.10.0"
version = "0.12.0"
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion internal/provider/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ type ExternalConfig struct {
// We set the mode to "last", the amount to 2 and the unit to "day"
// If includeCurrent is not set, the range will be the 15th and 16th of April
// If it is, then the range will be 16th and 17th
TimeRange *TimeSettings `json:"timeRange,omitempty"`
TimeRange *TimeSettings `json:"timeRange,omitempty"`
SortGroups string `json:"sortGroups,omitempty"`
SortDimensions string `json:"sortDimensions,omitempty"`
}

// AdvancedAnalysis Advanced analysis toggles. Each of these can be set independently
Expand Down
23 changes: 23 additions & 0 deletions internal/provider/report_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ type ExternalConfigModel struct {
// If set, the report must use time interval “month”/”quarter”/”year”
IncludePromotionalCredits types.Bool `tfsdk:"include_promotional_credits"`
Layout types.String `tfsdk:"layout"`
SortGroups types.String `tfsdk:"sort_groups"`
SortDimensions types.String `tfsdk:"sort_dimensions"`
Metric *ExternalMetricModel `tfsdk:"metric"`

// MetricFilter {
Expand Down Expand Up @@ -526,6 +528,18 @@ func (r *reportResource) Schema(_ context.Context, _ resource.SchemaRequest, res
Description: "",
Optional: true,
},
"sort_groups": schema.StringAttribute{
Description: "Sort groups. This configuration has no impact when reading a report's data via API. Default value is \"asc\".",
Optional: true,
Default: stringdefault.StaticString("asc"),
Computed: true,
},
"sort_dimensions": schema.StringAttribute{
Description: "Sort dimensions. This configuration has no impact when reading a report's data via API. Default value is \"desc\".",
Optional: true,
Default: stringdefault.StaticString("desc"),
Computed: true,
},
},
Description: "Report configuration",
Optional: true,
Expand Down Expand Up @@ -680,13 +694,16 @@ func (r *reportResource) Create(ctx context.Context, req resource.CreateRequest,
}

config.Layout = plan.Config.Layout.ValueString()
config.SortGroups = plan.Config.SortGroups.ValueString()
config.SortDimensions = plan.Config.SortDimensions.ValueString()
if plan.Config.Metric != nil {
metric := ExternalMetric{
Type: plan.Config.Metric.Type.ValueString(),
Value: plan.Config.Metric.Value.ValueString(),
}
config.Metric = &metric
}

var metricFilter ExternalConfigMetricFilter
if plan.Config.MetricFilter != nil {
var values []float64
Expand Down Expand Up @@ -838,6 +855,8 @@ func (r *reportResource) Read(ctx context.Context, req resource.ReadRequest, res
state.Config.IncludePromotionalCredits = types.BoolValue(report.Config.IncludePromotionalCredits)
log.Print(state.Config.IncludePromotionalCredits)
state.Config.Layout = types.StringValue(report.Config.Layout)
state.Config.SortGroups = types.StringValue(report.Config.SortGroups)
state.Config.SortDimensions = types.StringValue(report.Config.SortDimensions)
state.Config.TimeInterval = types.StringValue(report.Config.TimeInterval)
log.Print("c1")
if report.Config.TimeRange != nil {
Expand Down Expand Up @@ -1040,6 +1059,8 @@ func (r *reportResource) Update(ctx context.Context, req resource.UpdateRequest,
report.Config.IncludePromotionalCredits = false
}
report.Config.Layout = plan.Config.Layout.ValueString()
report.Config.SortGroups = plan.Config.SortGroups.ValueString()
report.Config.SortDimensions = plan.Config.SortDimensions.ValueString()
if plan.Config.Metric != nil {
externalMetric := ExternalMetric{
Type: plan.Config.Metric.Type.ValueString(),
Expand Down Expand Up @@ -1142,6 +1163,8 @@ func (r *reportResource) Update(ctx context.Context, req resource.UpdateRequest,
plan.Config.DisplayValues = types.StringValue(reportResponse.Config.DisplayValues)
plan.Config.IncludePromotionalCredits = types.BoolValue(reportResponse.Config.IncludePromotionalCredits)
plan.Config.Layout = types.StringValue(reportResponse.Config.Layout)
plan.Config.SortGroups = types.StringValue(reportResponse.Config.SortGroups)
plan.Config.SortDimensions = types.StringValue(reportResponse.Config.SortDimensions)
plan.Config.TimeInterval = types.StringValue(reportResponse.Config.TimeInterval)
if plan.Config.TimeRange != nil {
plan.Config.TimeRange = &TimeSettingsModel{
Expand Down
49 changes: 0 additions & 49 deletions test.json

This file was deleted.

0 comments on commit 92e6df5

Please sign in to comment.