From f0e135ddc7a81b5941e53432149ceb730014aee2 Mon Sep 17 00:00:00 2001 From: Diana Barreto Date: Wed, 3 Jan 2024 11:25:23 +1000 Subject: [PATCH] add group limit to read and update --- examples/main.tf | 43 ++++++++++++--------- internal/provider/report_resource.go | 56 ++++++++++++++++++++++++---- 2 files changed, 73 insertions(+), 26 deletions(-) diff --git a/examples/main.tf b/examples/main.tf index d0eb126..56bc6c7 100644 --- a/examples/main.tf +++ b/examples/main.tf @@ -8,21 +8,21 @@ terraform { } resource "doit_report" "my-report" { - name = "test_new_provider" + name = "test-pod-1.cs.playgrounds.doit.com" + description = "Playground usage for sg-pod-1.cs. Autogenerated by Arbiter. DO NOT MODIFY!" config = { metric = { type = "basic" value = "cost" } - include_promotional_credits = false + aggregation = "total" advanced_analysis = { trending_up = false trending_down = false not_trending = false forecast = false } - aggregation = "total" - time_interval = "month" + time_interval = "day" dimensions = [ { id = "year" @@ -32,13 +32,14 @@ resource "doit_report" "my-report" { id = "month" type = "datetime" } - ] + ] time_range = { mode = "last" - amount = 12 + amount = 7 include_current = true - unit = "month" - } + unit = "day" + } + include_promotional_credits = false filters = [ { inverse = false @@ -53,20 +54,26 @@ resource "doit_report" "my-report" { { id = "BSQZmvX6hvuKGPDHX7R3" type = "attribution_group" + limit = { + value = 3 + sort = "a_to_z" + metric = { + type = "basic" + value = "cost" + } + } }, { id = "cloud_provider" type = "fixed" - } - ] - group = [ - { - id = "BSQZmvX6hvuKGPDHX7R3" - type = "attribution_group" - }, - { - id = "cloud_provider" - type = "fixed" + limit = { + value = 10 + sort = "a_to_z" + metric = { + type = "basic" + value = "cost" + } + } } ] layout = "table" diff --git a/internal/provider/report_resource.go b/internal/provider/report_resource.go index 8f85878..76c8b95 100644 --- a/internal/provider/report_resource.go +++ b/internal/provider/report_resource.go @@ -865,10 +865,28 @@ func (r *reportResource) Read(ctx context.Context, req resource.ReadRequest, res if report.Config.Group != nil { state.Config.Group = []GroupModel{} for _, group := range report.Config.Group { - state.Config.Group = append(state.Config.Group, GroupModel{ - Id: types.StringValue(group.Id), - Type: types.StringValue(group.Type), - }) + limit := LimitModel{} + if group.Limit != nil { + metric := ExternalMetricModel{ + Type: types.StringValue(group.Limit.Metric.Type), + Value: types.StringValue(group.Limit.Metric.Value), + } + limit = LimitModel{ + Metric: &metric, + Sort: types.StringValue(group.Limit.Sort), + Value: types.Int64Value(group.Limit.Value), + } + state.Config.Group = append(state.Config.Group, GroupModel{ + Id: types.StringValue(group.Id), + Type: types.StringValue(group.Type), + Limit: &limit, + }) + } else { + state.Config.Group = append(state.Config.Group, GroupModel{ + Id: types.StringValue(group.Id), + Type: types.StringValue(group.Type), + }) + } } } @@ -1132,10 +1150,32 @@ func (r *reportResource) Update(ctx context.Context, req resource.UpdateRequest, if plan.Config.Group != nil { plan.Config.Group = []GroupModel{} for _, group := range reportResponse.Config.Group { - plan.Config.Group = append(plan.Config.Group, GroupModel{ - Id: types.StringValue(group.Id), - Type: types.StringValue(group.Type), - }) + limit := LimitModel{} + if group.Limit != nil { + metric := ExternalMetricModel{} + if group.Limit.Metric != nil { + metric = ExternalMetricModel{ + Type: types.StringValue(group.Limit.Metric.Type), + Value: types.StringValue(group.Limit.Metric.Value), + } + } + limit = LimitModel{ + Metric: &metric, + Sort: types.StringValue(group.Limit.Sort), + Value: types.Int64Value(group.Limit.Value), + } + plan.Config.Group = append(plan.Config.Group, GroupModel{ + Id: types.StringValue(group.Id), + Type: types.StringValue(group.Type), + Limit: &limit, + }) + } else { + plan.Config.Group = append(plan.Config.Group, GroupModel{ + Id: types.StringValue(group.Id), + Type: types.StringValue(group.Type), + }) + } + } } if plan.Config.Splits != nil {