diff --git a/docs/index.md b/docs/index.md index 82da00a..105f2d3 100644 --- a/docs/index.md +++ b/docs/index.md @@ -17,7 +17,7 @@ terraform { required_providers { doit = { source = "doitintl/doit" - version = "0.5.0" + version = "0.7.0" } } } diff --git a/docs/resources/report.md b/docs/resources/report.md index 8d2dc9d..b1d10dd 100644 --- a/docs/resources/report.md +++ b/docs/resources/report.md @@ -124,7 +124,7 @@ Optional: ### Nested Schema for `config.dimensions` -Optional: +Required: - `id` (String) - `type` (String) @@ -135,24 +135,27 @@ Optional: Required: +- `id` (String) What field we are filtering on +- `type` (String) - `values` (List of String) What values to filter on or exclude Optional: -- `id` (String) What field we are filtering on - `inverse` (Boolean) If set, exclude the values -- `type` (String) ### Nested Schema for `config.group` -Optional: +Required: - `id` (String) -- `limit` (Attributes) (see [below for nested schema](#nestedatt--config--group--limit)) - `type` (String) +Optional: + +- `limit` (Attributes) (see [below for nested schema](#nestedatt--config--group--limit)) + ### Nested Schema for `config.group.limit` @@ -165,7 +168,7 @@ Optional: ### Nested Schema for `config.group.limit.value` -Optional: +Required: - `type` (String) - `value` (String) @@ -176,7 +179,7 @@ Optional: ### Nested Schema for `config.metric` -Optional: +Required: - `type` (String) - `value` (String) For basic metrics the value can be one of: ["cost", "usage", "savings" @@ -188,17 +191,14 @@ If using custom metrics, the value must refer to an existing custom or calculate Required: -- `values` (List of Number) - -Optional: - - `metric` (Attributes) (see [below for nested schema](#nestedatt--config--metric_filter--metric)) - `operator` (String) +- `values` (List of Number) ### Nested Schema for `config.metric_filter.metric` -Optional: +Required: - `type` (String) - `value` (String) @@ -208,19 +208,19 @@ Optional: ### Nested Schema for `config.splits` -Optional: +Required: - `id` (String) - `include_origin` (Boolean) - `mode` (String) - `origin` (Attributes) (see [below for nested schema](#nestedatt--config--splits--origin)) - `targets` (Attributes List) (see [below for nested schema](#nestedatt--config--splits--targets)) -- `type` (String) +- `type` (String) Type of the split.The only supported value at the moment: "attribution_group" ### Nested Schema for `config.splits.origin` -Optional: +Required: - `id` (String) - `type` (String) @@ -229,19 +229,23 @@ Optional: ### Nested Schema for `config.splits.targets` -Optional: +Required: - `id` (String) - `type` (String) +- `value` (Number) Percent of the target, represented in float format. E.g. 30% is 0.3. Must be set only if Split Mode is custom ### Nested Schema for `config.time_range` +Required: + +- `mode` (String) + Optional: - `amount` (Number) - `include_current` (Boolean) -- `mode` (String) - `unit` (String) diff --git a/examples/main.tf b/examples/main.tf index 7078766..09a844c 100644 --- a/examples/main.tf +++ b/examples/main.tf @@ -8,7 +8,7 @@ terraform { } resource "doit_report" "my-report" { - name = "test-pod-1.cs.playgrounds.doit.com" + name = "test-pod-1.cs.playgrounds.doit.com" description = "Playground usage for sg-pod-1.cs. Autogenerated by Arbiter. DO NOT MODIFY!" config = { metric = { @@ -36,12 +36,12 @@ resource "doit_report" "my-report" { amount = 7 include_current = true unit = "day" - } + } include_promotional_credits = false filters = [ { - id = "attribution" - type = "attribution" + id = "attribution" + type = "attribution" values = [ "1CE699ZdwN5CRBw0tInY" ] @@ -52,24 +52,24 @@ resource "doit_report" "my-report" { id = "BSQZmvX6hvuKGPDHX7R3" type = "attribution_group" limit = { - value = 3 - sort = "a_to_z" - metric = { - type = "basic" - value = "cost" - } + value = 3 + sort = "a_to_z" + metric = { + type = "basic" + value = "cost" + } } }, { id = "cloud_provider" type = "fixed" limit = { - value = 10 - sort = "a_to_z" - metric = { - type = "basic" - value = "cost" - } + value = 10 + sort = "a_to_z" + metric = { + type = "basic" + value = "cost" + } } } ] diff --git a/examples/provider/provider.tf b/examples/provider/provider.tf index 981bdf4..92b6fc2 100644 --- a/examples/provider/provider.tf +++ b/examples/provider/provider.tf @@ -2,7 +2,7 @@ terraform { required_providers { doit = { source = "doitintl/doit" - version = "0.5.0" + version = "0.7.0" } } } diff --git a/internal/provider/report_resource.go b/internal/provider/report_resource.go index 76c8b95..6e6dc29 100644 --- a/internal/provider/report_resource.go +++ b/internal/provider/report_resource.go @@ -11,6 +11,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/resource/schema" "github.com/hashicorp/terraform-plugin-framework/resource/schema/booldefault" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/int64default" "github.com/hashicorp/terraform-plugin-framework/resource/schema/objectdefault" "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringdefault" "github.com/hashicorp/terraform-plugin-framework/types" @@ -240,18 +241,26 @@ func (r *reportResource) Schema(_ context.Context, _ resource.SchemaRequest, res "forecast": schema.BoolAttribute{ Description: "Advanced analysis toggles. Each of these can be set independently", Optional: true, + Computed: true, + Default: booldefault.StaticBool(false), }, "not_trending": schema.BoolAttribute{ Description: "", Optional: true, + Computed: true, + Default: booldefault.StaticBool(false), }, "trending_down": schema.BoolAttribute{ Description: "", Optional: true, + Computed: true, + Default: booldefault.StaticBool(false), }, "trending_up": schema.BoolAttribute{ Description: "", Optional: true, + Computed: true, + Default: booldefault.StaticBool(false), }, }, Description: "", @@ -262,10 +271,14 @@ func (r *reportResource) Schema(_ context.Context, _ resource.SchemaRequest, res "aggregation": schema.StringAttribute{ Description: "", Optional: true, + Default: stringdefault.StaticString("total"), + Computed: true, }, "currency": schema.StringAttribute{ Description: "", Optional: true, + Default: stringdefault.StaticString("USD"), + Computed: true, }, "dimensions": schema.ListNestedAttribute{ Description: "", @@ -274,11 +287,11 @@ func (r *reportResource) Schema(_ context.Context, _ resource.SchemaRequest, res Attributes: map[string]schema.Attribute{ "id": schema.StringAttribute{ Description: "", - Optional: true, + Required: true, }, "type": schema.StringAttribute{ Description: "", - Optional: true, + Required: true, }, }, }, @@ -286,6 +299,8 @@ func (r *reportResource) Schema(_ context.Context, _ resource.SchemaRequest, res "display_values": schema.StringAttribute{ Description: "", Optional: true, + Default: stringdefault.StaticString("actuals_only"), + Computed: true, }, "filters": schema.ListNestedAttribute{ Description: "The filters to use in this report", @@ -294,15 +309,17 @@ func (r *reportResource) Schema(_ context.Context, _ resource.SchemaRequest, res Attributes: map[string]schema.Attribute{ "id": schema.StringAttribute{ Description: "What field we are filtering on", - Optional: true, + Required: true, }, "inverse": schema.BoolAttribute{ Description: "If set, exclude the values", Optional: true, + Computed: true, + Default: booldefault.StaticBool(false), }, "type": schema.StringAttribute{ Description: "", - Optional: true, + Required: true, }, "values": schema.ListAttribute{ Description: "What values to filter on or exclude", @@ -319,11 +336,11 @@ func (r *reportResource) Schema(_ context.Context, _ resource.SchemaRequest, res Attributes: map[string]schema.Attribute{ "id": schema.StringAttribute{ Description: "", - Optional: true, + Required: true, }, "type": schema.StringAttribute{ Description: "", - Optional: true, + Required: true, }, "limit": schema.SingleNestedAttribute{ Attributes: map[string]schema.Attribute{ @@ -331,11 +348,11 @@ func (r *reportResource) Schema(_ context.Context, _ resource.SchemaRequest, res Attributes: map[string]schema.Attribute{ "type": schema.StringAttribute{ Description: "", - Optional: true, + Required: true, }, "value": schema.StringAttribute{ Description: "", - Optional: true, + Required: true, }, }, Description: "", @@ -344,10 +361,14 @@ func (r *reportResource) Schema(_ context.Context, _ resource.SchemaRequest, res "sort": schema.StringAttribute{ Description: "", Optional: true, + Default: stringdefault.StaticString(""), + Computed: true, }, "value": schema.Int64Attribute{ Description: "", Optional: true, + Default: int64default.StaticInt64(0), + Computed: true, }, }, Description: "", @@ -366,17 +387,19 @@ func (r *reportResource) Schema(_ context.Context, _ resource.SchemaRequest, res "layout": schema.StringAttribute{ Description: "", Optional: true, + Default: stringdefault.StaticString("stacked_column_chart"), + Computed: true, }, "metric": schema.SingleNestedAttribute{ Attributes: map[string]schema.Attribute{ "type": schema.StringAttribute{ Description: "", - Optional: true, + Required: true, }, "value": schema.StringAttribute{ Description: "For basic metrics the value can be one of: [\"cost\", \"usage\", \"savings\" \n" + "If using custom metrics, the value must refer to an existing custom or calculated metric id ", - Optional: true, + Required: true, }, }, Description: "", @@ -388,19 +411,19 @@ func (r *reportResource) Schema(_ context.Context, _ resource.SchemaRequest, res Attributes: map[string]schema.Attribute{ "type": schema.StringAttribute{ Description: "", - Optional: true, + Required: true, }, "value": schema.StringAttribute{ Description: "", - Optional: true, + Required: true, }, }, Description: "", - Optional: true, + Required: true, }, "operator": schema.StringAttribute{ Description: "", - Optional: true, + Required: true, }, "values": schema.ListAttribute{ Description: "", @@ -418,46 +441,50 @@ func (r *reportResource) Schema(_ context.Context, _ resource.SchemaRequest, res Attributes: map[string]schema.Attribute{ "id": schema.StringAttribute{ Description: "", - Optional: true, + Required: true, }, "include_origin": schema.BoolAttribute{ Description: "", - Optional: true, + Required: true, }, "type": schema.StringAttribute{ - Description: "", - Optional: true, + Description: "Type of the split.The only supported value at the moment: \"attribution_group\"", + Required: true, }, "mode": schema.StringAttribute{ Description: "", - Optional: true, + Required: true, }, "origin": schema.SingleNestedAttribute{ Attributes: map[string]schema.Attribute{ "id": schema.StringAttribute{ Description: "", - Optional: true, + Required: true, }, "type": schema.StringAttribute{ Description: "", - Optional: true, + Required: true, }, }, Description: "", - Optional: true, + Required: true, }, "targets": schema.ListNestedAttribute{ Description: "", - Optional: true, + Required: true, NestedObject: schema.NestedAttributeObject{ Attributes: map[string]schema.Attribute{ "id": schema.StringAttribute{ Description: "", - Optional: true, + Required: true, }, "type": schema.StringAttribute{ Description: "", - Optional: true, + Required: true, + }, + "value": schema.Float64Attribute{ + Description: "Percent of the target, represented in float format. E.g. 30% is 0.3. Must be set only if Split Mode is custom", + Required: true, }, }, }, @@ -468,24 +495,32 @@ func (r *reportResource) Schema(_ context.Context, _ resource.SchemaRequest, res "time_interval": schema.StringAttribute{ Description: "", Optional: true, + Default: stringdefault.StaticString("day"), + Computed: true, }, "time_range": schema.SingleNestedAttribute{ Attributes: map[string]schema.Attribute{ "amount": schema.Int64Attribute{ Description: "", Optional: true, + Default: int64default.StaticInt64(0), + Computed: true, }, "include_current": schema.BoolAttribute{ Description: "", Optional: true, + Default: booldefault.StaticBool(false), + Computed: true, }, "mode": schema.StringAttribute{ Description: "", - Optional: true, + Required: true, }, "unit": schema.StringAttribute{ Description: "", Optional: true, + Default: stringdefault.StaticString("day"), + Computed: true, }, }, Description: "", @@ -1013,15 +1048,19 @@ func (r *reportResource) Update(ctx context.Context, req resource.UpdateRequest, report.Config.Metric = &externalMetric } - if report.Config.MetricFilter != nil { + if plan.Config.MetricFilter != nil { metricFilter := ExternalConfigMetricFilter{} - report.Config.MetricFilter.Operator = plan.Config.MetricFilter.Operator.ValueString() - report.Config.MetricFilter.Metric.Type = plan.Config.MetricFilter.Metric.Type.ValueString() - report.Config.MetricFilter.Metric.Value = plan.Config.MetricFilter.Metric.Value.ValueString() - report.Config.MetricFilter.Values = []float64{} + metricFilter.Operator = plan.Config.MetricFilter.Operator.ValueString() + if plan.Config.MetricFilter.Metric != nil { + metricFilter.Metric = &ExternalMetric{} + metricFilter.Metric.Type = plan.Config.MetricFilter.Metric.Type.ValueString() + metricFilter.Metric.Value = plan.Config.MetricFilter.Metric.Value.ValueString() + } + values := []float64{} for _, value := range plan.Config.MetricFilter.Values { - report.Config.MetricFilter.Values = append(report.Config.MetricFilter.Values, value.ValueFloat64()) + values = append(values, value.ValueFloat64()) } + metricFilter.Values = values report.Config.MetricFilter = &metricFilter } report.Config.Splits = []ExternalSplit{} @@ -1049,14 +1088,20 @@ func (r *reportResource) Update(ctx context.Context, req resource.UpdateRequest, } esplit.Id = split.Id.ValueString() esplit.IncludeOrigin = split.IncludeOrigin.ValueBool() + esplit.Mode = split.Mode.ValueString() + esplit.Type = split.Type.ValueString() report.Config.Splits = append(report.Config.Splits, esplit) } report.Config.TimeInterval = plan.Config.TimeInterval.ValueString() - if report.Config.TimeRange != nil { - report.Config.TimeRange.Amount = plan.Config.TimeRange.Amount.ValueInt64() - report.Config.TimeRange.IncludeCurrent = plan.Config.TimeRange.IncludeCurrent.ValueBool() - report.Config.TimeRange.Mode = plan.Config.TimeRange.Mode.ValueString() - report.Config.TimeRange.Unit = plan.Config.TimeRange.Unit.ValueString() + log.Println("report.Config.TimeRange") + log.Println("report.Config.TimeRange") + if plan.Config.TimeRange != nil { + report.Config.TimeRange = &TimeSettings{ + Amount: plan.Config.TimeRange.Amount.ValueInt64(), + IncludeCurrent: plan.Config.TimeRange.IncludeCurrent.ValueBool(), + Mode: plan.Config.TimeRange.Mode.ValueString(), + Unit: plan.Config.TimeRange.Unit.ValueString(), + } } // Update existing report _, err := r.client.UpdateReport(state.Id.ValueString(), report) @@ -1081,7 +1126,6 @@ func (r *reportResource) Update(ctx context.Context, req resource.UpdateRequest, // Update resource state with updated items and timestamp plan.Id = types.StringValue(reportResponse.Id) - plan.Id = types.StringValue(reportResponse.Id) plan.Description = types.StringValue(reportResponse.Description) plan.Name = types.StringValue(reportResponse.Name) plan.LastUpdated = types.StringValue(time.Now().Format(time.RFC850))