Skip to content

Commit

Permalink
add group limit to read and update
Browse files Browse the repository at this point in the history
  • Loading branch information
dianibar committed Jan 3, 2024
1 parent 52e946c commit f0e135d
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 26 deletions.
43 changes: 25 additions & 18 deletions examples/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand All @@ -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"
Expand Down
56 changes: 48 additions & 8 deletions internal/provider/report_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
})
}
}
}

Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit f0e135d

Please sign in to comment.