From 0dacb049b435de7b257d616ad1b22bc15ac05de8 Mon Sep 17 00:00:00 2001 From: kubaceg Date: Mon, 26 Feb 2024 17:02:58 +0100 Subject: [PATCH] PC-11815 add budget adjustments terraform support --- Makefile | 2 +- README.md | 2 +- docs/index.md | 2 +- docs/resources/budget_adjustment.md | 96 +++++++++++++++++++ examples/provider/provider.tf | 2 +- .../nobl9_budget_adjustment/resource.tf | 32 +++++++ nobl9/resource_budgetadjustment.go | 12 ++- nobl9/resource_budgetadjustment_test.go | 18 ++-- templates/resources/budget_adjustment.md.tmpl | 23 +++++ 9 files changed, 174 insertions(+), 15 deletions(-) create mode 100644 docs/resources/budget_adjustment.md create mode 100644 examples/resources/nobl9_budget_adjustment/resource.tf create mode 100644 templates/resources/budget_adjustment.md.tmpl diff --git a/Makefile b/Makefile index 72e4f335..46cdd7b8 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ NAMESPACE=nobl9 NAME=nobl9 BIN_DIR=./bin BINARY=$(BIN_DIR)/terraform-provider-$(NAME) -VERSION=0.23.0 +VERSION=0.24.0 BUILD_FLAGS="-X github.com/nobl9/terraform-provider-nobl9/nobl9.Version=$(VERSION)" OS_ARCH?=linux_amd64 diff --git a/README.md b/README.md index 367f82d9..994128a4 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ terraform { required_providers { nobl9 = { source = "nobl9/nobl9" - version = "0.23.0" + version = "0.24.0" } } } diff --git a/docs/index.md b/docs/index.md index 1a6a8a06..2c2a3115 100644 --- a/docs/index.md +++ b/docs/index.md @@ -37,7 +37,7 @@ terraform { required_providers { nobl9 = { source = "nobl9/nobl9" - version = "0.23.0" + version = "0.24.0" } } } diff --git a/docs/resources/budget_adjustment.md b/docs/resources/budget_adjustment.md new file mode 100644 index 00000000..f91f3ffa --- /dev/null +++ b/docs/resources/budget_adjustment.md @@ -0,0 +1,96 @@ +--- +page_title: "nobl9_budget_adjustment Resource - terraform-provider-nobl9" +description: |- + Budget adjustment configuration documentation https://docs.nobl9.com/yaml-guide#budget-adjustment +--- + +# nobl9_budget_adjustment (Resource) + +An **Budget Adjustment** some description + +For more details, refer to the [Budget adjustment configuration documentation](https://docs.nobl9.com/yaml-guide#budget-adjustment). + +## Example Usage + +Here's an example of Budget Adjustment resource configuration: + +```terraform +resource "nobl9_budget_adjustment" "single-budget-adjustment-event" { + name = "single-budget-adjustment-event" + display_name = "Single Budget Adjustment Event" + first_event_start = "2022-01-01T00:00:00Z" + duration = "1h" + description = "Single budget adjustment event" + filters { + slos { + slo { + name = "my-slo" + project = "default" + } + } + } +} + +resource "nobl9_budget_adjustment" "recurring-budget-adjustment-event" { + name = "recurring-budget-adjustment-event" + display_name = "Recurring Budget Adjustment Event" + first_event_start = "2022-01-01T16:00:00Z" + duration = "1h" + rrule = "FREQ=WEEKLY" + description = "Recurring budget adjustment event" + filters { + slos { + slo { + name = "my-slo" + project = "default" + } + } + } +} +``` + + +## Schema + +### Required + +- `duration` (String) The duration of the budget adjustment event. The expected value is a string in time duration string format. Duration must be defined with 1 minute precision.Example: `1h10m` +- `first_event_start` (String) The time of the first event start. The expected value is a string with date in RFC3339 format. Example: `2022-12-31T00:00:00Z` +- `name` (String) Unique name of the resource, must conform to the naming convention from [DNS RFC1123](https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names). + +### Optional + +- `description` (String) Optional description of the resource. Here, you can add details about who is responsible for the integration (team/owner) or the purpose of creating it. +- `display_name` (String) User-friendly display name of the resource. +- `filters` (Block Set) Filters are used to select SLOs for the budget adjustment event. (see [below for nested schema](#nestedblock--filters)) +- `rrule` (String) The recurrence rule for the budget adjustment event. The expected value is a string in RRULE format. Example: `FREQ=MONTHLY;BYMONTHDAY=1` + +### Read-Only + +- `id` (String) The ID of this resource. + + +### Nested Schema for `filters` + +Required: + +- `slos` (Block Set, Min: 1) (see [below for nested schema](#nestedblock--filters--slos)) + + +### Nested Schema for `filters.slos` + +Required: + +- `slo` (Block List, Min: 1) SLO where budget adjustment event will be applied. (see [below for nested schema](#nestedblock--filters--slos--slo)) + + +### Nested Schema for `filters.slos.slo` + +Required: + +- `name` (String) Unique name of the resource, must conform to the naming convention from [DNS RFC1123](https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names). +- `project` (String) Name of the Nobl9 project the resource sits in, must conform to the naming convention from [DNS RFC1123](https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names). + +## Useful Links + +[Budget Adjustment configuration | Nobl9 Documentation](https://docs.nobl9.com/yaml-guide#budget-adjustment) diff --git a/examples/provider/provider.tf b/examples/provider/provider.tf index 7d308732..13d692d2 100644 --- a/examples/provider/provider.tf +++ b/examples/provider/provider.tf @@ -2,7 +2,7 @@ terraform { required_providers { nobl9 = { source = "nobl9/nobl9" - version = "0.23.0" + version = "0.24.0" } } } diff --git a/examples/resources/nobl9_budget_adjustment/resource.tf b/examples/resources/nobl9_budget_adjustment/resource.tf new file mode 100644 index 00000000..6628d698 --- /dev/null +++ b/examples/resources/nobl9_budget_adjustment/resource.tf @@ -0,0 +1,32 @@ +resource "nobl9_budget_adjustment" "single-budget-adjustment-event" { + name = "single-budget-adjustment-event" + display_name = "Single Budget Adjustment Event" + first_event_start = "2022-01-01T00:00:00Z" + duration = "1h" + description = "Single budget adjustment event" + filters { + slos { + slo { + name = "my-slo" + project = "default" + } + } + } +} + +resource "nobl9_budget_adjustment" "recurring-budget-adjustment-event" { + name = "recurring-budget-adjustment-event" + display_name = "Recurring Budget Adjustment Event" + first_event_start = "2022-01-01T16:00:00Z" + duration = "1h" + rrule = "FREQ=WEEKLY" + description = "Recurring budget adjustment event" + filters { + slos { + slo { + name = "my-slo" + project = "default" + } + } + } +} \ No newline at end of file diff --git a/nobl9/resource_budgetadjustment.go b/nobl9/resource_budgetadjustment.go index f7c5ec05..d7bd7bad 100644 --- a/nobl9/resource_budgetadjustment.go +++ b/nobl9/resource_budgetadjustment.go @@ -61,8 +61,9 @@ func schemaBudgetAdjustment() map[string]*schema.Schema { "Example: `FREQ=MONTHLY;BYMONTHDAY=1`", }, "filters": { - Type: schema.TypeSet, - Optional: true, + Type: schema.TypeSet, + Optional: true, + Description: "Filters are used to select SLOs for the budget adjustment event.", Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "slos": { @@ -71,9 +72,10 @@ func schemaBudgetAdjustment() map[string]*schema.Schema { Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "slo": { - Type: schema.TypeList, - MinItems: 1, - Required: true, + Type: schema.TypeList, + MinItems: 1, + Required: true, + Description: "SLO where budget adjustment event will be applied.", Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "name": schemaName(), diff --git a/nobl9/resource_budgetadjustment_test.go b/nobl9/resource_budgetadjustment_test.go index 493cef58..6969a806 100644 --- a/nobl9/resource_budgetadjustment_test.go +++ b/nobl9/resource_budgetadjustment_test.go @@ -53,29 +53,35 @@ resource "nobl9_budget_adjustment" "%s" { } func testBudgetAdjustmentRecurringEvent(name string) string { - return fmt.Sprintf(` -resource "nobl9_budget_adjustment" "%s" { + return fmt.Sprintf(`resource "nobl9_budget_adjustment" "%s" { name = "%s" first_event_start = "2022-01-01T00:00:00Z" duration = "1h" + rrule = "FREQ=MONTHLY;BYMONTHDAY=1" filters { slos { slo { - name = "ratio-slo" - project = "default" + name = "cloudwatch-ratio-slo" + project = "cloudwatch" + } + slo { + name = "cloudwatch-ratio-slo2" + project = "cloudwatch" } } } -} -`, name, name) +}`, name, name) } func testBudgetAdjustmentRecurringEventMultipleSlo(name string) string { return fmt.Sprintf(` resource "nobl9_budget_adjustment" "%s" { name = "%s" + display_name = "Recurring budget adjustment for the first day of the month." first_event_start = "2022-01-01T00:00:00Z" + description = "Recurring budget adjustment for the first day of the month." duration = "1h" + rrule = "FREQ=MONTHLY;BYMONTHDAY=1" filters { slos { slo { diff --git a/templates/resources/budget_adjustment.md.tmpl b/templates/resources/budget_adjustment.md.tmpl new file mode 100644 index 00000000..47945375 --- /dev/null +++ b/templates/resources/budget_adjustment.md.tmpl @@ -0,0 +1,23 @@ +--- +page_title: "{{.Name}} {{.Type}} - {{.ProviderName}}" +description: |- +{{ .Description | plainmarkdown | trimspace | prefixlines " " }} +--- + +# {{.Name}} ({{.Type}}) + +An **Budget Adjustment** some description + +For more details, refer to the {{ .Description | trimspace }}. + +## Example Usage + +Here's an example of Budget Adjustment resource configuration: + +{{ tffile (printf "examples/resources/%s/resource.tf" .Name)}} + +{{ .SchemaMarkdown | trimspace }} + +## Useful Links + +[Budget Adjustment configuration | Nobl9 Documentation](https://docs.nobl9.com/yaml-guide#budget-adjustment)