Skip to content

Commit

Permalink
Merge pull request #47 from vantage-sh/andy/budgets
Browse files Browse the repository at this point in the history
Budgets Resource and Data Source
  • Loading branch information
whereandy authored Apr 16, 2024
2 parents 62de8ef + 770308e commit 730d8d6
Show file tree
Hide file tree
Showing 14 changed files with 3,578 additions and 16 deletions.
56 changes: 56 additions & 0 deletions docs/data-sources/budgets.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "vantage_budgets Data Source - terraform-provider-vantage"
subcategory: ""
description: |-
---

# vantage_budgets (Data Source)





<!-- schema generated by tfplugindocs -->
## Schema

### Read-Only

- `budgets` (Attributes List) (see [below for nested schema](#nestedatt--budgets))

<a id="nestedatt--budgets"></a>
### Nested Schema for `budgets`

Read-Only:

- `budget_alert_tokens` (List of String) The tokens of the BudgetAlerts associated with the Budget.
- `cost_report_token` (String) The token of the Report associated with the Budget.
- `created_at` (String) The date and time, in UTC, the Budget was created. ISO 8601 Formatted.
- `name` (String) The name of the Budget.
- `performance` (Attributes List) The historical performance of the Budget. (see [below for nested schema](#nestedatt--budgets--performance))
- `periods` (Attributes List) The budget periods associated with the Budget. (see [below for nested schema](#nestedatt--budgets--periods))
- `token` (String)
- `user_token` (String) The token for the User who created this Budget.
- `workspace_token` (String) The token for the Workspace the Budget is a part of.

<a id="nestedatt--budgets--performance"></a>
### Nested Schema for `budgets.performance`

Read-Only:

- `actual` (String) The date and time, in UTC, the Budget was created. ISO 8601 Formatted.
- `amount` (String) The amount of the Budget Period as a string to ensure precision.
- `date` (String) The date and time, in UTC, the Budget was created. ISO 8601 Formatted.


<a id="nestedatt--budgets--periods"></a>
### Nested Schema for `budgets.periods`

Read-Only:

- `amount` (String) The amount of the Budget Period as a string to ensure precision.
- `end_at` (String) The date and time, in UTC, the Budget was created. ISO 8601 Formatted.
- `start_at` (String) The date and time, in UTC, the Budget was created. ISO 8601 Formatted.


58 changes: 58 additions & 0 deletions docs/resources/budget.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "vantage_budget Resource - terraform-provider-vantage"
subcategory: ""
description: |-
---

# vantage_budget (Resource)





<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `name` (String) The name of the Budget.

### Optional

- `cost_report_token` (String) The CostReport token.
- `periods` (Attributes List) The periods for the Budget. The start_at and end_at must be iso8601 formatted e.g. YYYY-MM-DD. (see [below for nested schema](#nestedatt--periods))
- `workspace_token` (String) The token of the Workspace to add the Budget to.

### Read-Only

- `budget_alert_tokens` (List of String) The tokens of the BudgetAlerts associated with the Budget.
- `created_at` (String) The date and time, in UTC, the Budget was created. ISO 8601 Formatted.
- `performance` (Attributes List) The historical performance of the Budget. (see [below for nested schema](#nestedatt--performance))
- `token` (String) The token of the budget
- `user_token` (String) The token for the User who created this Budget.

<a id="nestedatt--periods"></a>
### Nested Schema for `periods`

Required:

- `amount` (Number) The amount of the period.
- `start_at` (String) The start date of the period.

Optional:

- `end_at` (String) The end date of the period.


<a id="nestedatt--performance"></a>
### Nested Schema for `performance`

Read-Only:

- `actual` (String) The date and time, in UTC, the Budget was created. ISO 8601 Formatted.
- `amount` (String) The amount of the Budget Period as a string to ensure precision.
- `date` (String) The date and time, in UTC, the Budget was created. ISO 8601 Formatted.


39 changes: 28 additions & 11 deletions examples/cost_report/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ resource "vantage_cost_report" "demo_report" {
filter = "costs.provider = 'kubernetes'"
saved_filter_tokens = [vantage_saved_filter.demo_filter.token]
title = "Demo Report"
}
}
resource "vantage_dashboard" "demo_dashboard" {
widget_tokens = [vantage_cost_report.demo_report.token]
title = "Demo Dashboard"
Expand All @@ -54,27 +54,27 @@ resource "vantage_access_grant" "demo_access_grant" {
}

locals {
metrics_csv = csvdecode(file("${path.module}/metrics.csv"))
metrics_csv = csvdecode(file("${path.module}/metrics.csv"))
sorted_dates = distinct(reverse(sort(local.metrics_csv[*].date)))
sorted_metrics = flatten(
[for value in local.sorted_dates:
[ for elem in local.metrics_csv:
elem if value == elem.date
]
])
[for value in local.sorted_dates :
[for elem in local.metrics_csv :
elem if value == elem.date
]
])
}

resource "vantage_business_metric" "demo_metric2" {
title = "Demo Metric"
title = "Demo Metric"
cost_report_tokens_with_metadata = [
{
cost_report_token = vantage_cost_report.demo_report.token
unit_scale = "per_hundred"
unit_scale = "per_hundred"
}
]

values = [for row in local.sorted_metrics : {
date = row.date
date = row.date
amount = row.amount
}]
}
Expand All @@ -84,6 +84,23 @@ data "vantage_business_metrics" "demo2" {}
output "business_metrics" {
value = data.vantage_business_metrics.demo2
}




resource "vantage_budget" "demo_budget" {
name = "Demo Budget"
cost_report_token = vantage_cost_report.demo_report.token
periods = [
{
start_at = "2023-12-01"
end_at = "2024-01-01"
amount = 1000
}
]
}

data "vantage_budgets" "demo" {}

output "budgets" {
value = data.vantage_budgets.demo
}
5 changes: 5 additions & 0 deletions examples/data_sources/budgets.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
data "vantage_budgets" "all" {}

output "all_budgets" {
value = data.vantage_budgets.all
}
11 changes: 11 additions & 0 deletions examples/resources/vantage_budget/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
resource "vantage_budget" "demo_budget" {
name = "Demo Budget"
cost_report_token = vantage_cost_report.demo_report.token
periods = [
{
start_at = "2023-12-01"
end_at = "2024-01-01"
amount = 1000
}
]
}
30 changes: 29 additions & 1 deletion generator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,26 @@ resources:
description: The token of the report alert
aliases:
anomaly_notification_token: token

budget:
create:
path: /budgets
method: POST
read:
path: /budgets/{budget_token}
method: GET
update:
path: /budgets/{budget_token}
method: PUT
delete:
path: /budgets/{budget_token}
method: DELETE
schema:
attributes:
overrides:
token:
description: The token of the budget
aliases:
budget_token: token
business_metric:
create:
path: /business_metrics
Expand All @@ -44,6 +63,15 @@ resources:
aliases:
business_metric_token: token
data_sources:
budgets:
read:
path: /budgets
method: GET
schema:
ignores:
- limit
- links
- page
business_metrics:
read:
path: /business_metrics
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
github.com/hashicorp/terraform-plugin-docs v0.14.1
github.com/hashicorp/terraform-plugin-framework v1.5.0
github.com/hashicorp/terraform-plugin-testing v1.6.0
github.com/vantage-sh/vantage-go v0.0.19
github.com/vantage-sh/vantage-go v0.0.21
)

require (
Expand Down Expand Up @@ -54,7 +54,7 @@ require (
github.com/hashicorp/terraform-json v0.18.0 // indirect
github.com/hashicorp/terraform-plugin-framework-validators v0.12.0
github.com/hashicorp/terraform-plugin-go v0.20.0
github.com/hashicorp/terraform-plugin-log v0.9.0 // indirect
github.com/hashicorp/terraform-plugin-log v0.9.0
github.com/hashicorp/terraform-plugin-sdk/v2 v2.30.0 // indirect
github.com/hashicorp/terraform-registry-address v0.2.3 // indirect
github.com/hashicorp/terraform-svchost v0.1.1 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,8 @@ github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
github.com/vantage-sh/vantage-go v0.0.19 h1:4XrUBY80pjjlb24KVxBa0VfESowLNONzgdHdBA84wWA=
github.com/vantage-sh/vantage-go v0.0.19/go.mod h1:MsSI4gX/Wvkzo9kqWphZfE6puolmnbHcXSaoGkDCmXg=
github.com/vantage-sh/vantage-go v0.0.21 h1:jnJn5voUjQIyIZyE7Rpo7D4zcTBgrsgOWSkW+QrZMFg=
github.com/vantage-sh/vantage-go v0.0.21/go.mod h1:MsSI4gX/Wvkzo9kqWphZfE6puolmnbHcXSaoGkDCmXg=
github.com/vmihailenco/msgpack v3.3.3+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk=
github.com/vmihailenco/msgpack v4.0.4+incompatible h1:dSLoQfGFAo3F6OoNhwUmLwVgaUXK79GlxNBwueZn0xI=
github.com/vmihailenco/msgpack v4.0.4+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk=
Expand Down
Loading

0 comments on commit 730d8d6

Please sign in to comment.