Skip to content

Commit

Permalink
feat: PC-11815 add budget adjustments terraform support (#175)
Browse files Browse the repository at this point in the history
## Motivation

Add support for the new `BudgetAdjustment` kind.

## Release Notes

New BudgetAdjustment kind which allows customers to schedule recurring
future events that should be excluded from the Error Budget calculations
in their SLOs. This PR introduces new `budget_adjustment` resource.

---------

Co-authored-by: kubaceg <jakub.cegielka@nobl9.com>
  • Loading branch information
kubaceg and kubaceg committed May 14, 2024
1 parent d1b226d commit 41cde93
Show file tree
Hide file tree
Showing 10 changed files with 687 additions and 1 deletion.
2 changes: 2 additions & 0 deletions cspell.yaml
Expand Up @@ -26,6 +26,7 @@ ignorePaths:
- bin/**
words:
- apdex
- bymonthday
- dbslo
- dynatrace
- endef
Expand All @@ -46,6 +47,7 @@ words:
- opentsdb
- plantuml
- promql
- rrule
- securego
- sloctl
- slos
Expand Down
96 changes: 96 additions & 0 deletions 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/features/budget-adjustment
---

# nobl9_budget_adjustment (Resource)

The budget adjustment feature allows you to define future periods where planned maintenance, releases, and similar activities won't affect your budget in specific SLOs.

For more details, refer to the [Budget adjustment configuration documentation](https://docs.nobl9.com/features/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 generated by tfplugindocs -->
## Schema

### Required

- `duration` (String) The duration of the budget adjustment event. The expected value for this field is a string formatted as a time duration. The duration must be defined with a precision of 1 minute. Example: `1h10m`
- `first_event_start` (String) The time at which the first event is scheduled to start. The expected value must be a string representing the date and time 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.

<a id="nestedblock--filters"></a>
### Nested Schema for `filters`

Required:

- `slos` (Block Set, Min: 1) (see [below for nested schema](#nestedblock--filters--slos))

<a id="nestedblock--filters--slos"></a>
### 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))

<a id="nestedblock--filters--slos--slo"></a>
### 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)
32 changes: 32 additions & 0 deletions 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"
}
}
}
}
2 changes: 1 addition & 1 deletion go.mod
Expand Up @@ -9,6 +9,7 @@ require (
github.com/hashicorp/terraform-plugin-sdk/v2 v2.33.0
github.com/nobl9/nobl9-go v0.81.0
github.com/stretchr/testify v1.9.0
github.com/teambition/rrule-go v1.8.2
)

require (
Expand Down Expand Up @@ -71,7 +72,6 @@ require (
github.com/posener/complete v1.2.3 // indirect
github.com/shopspring/decimal v1.3.1 // indirect
github.com/spf13/cast v1.5.0 // indirect
github.com/teambition/rrule-go v1.8.2 // indirect
github.com/vmihailenco/msgpack v4.0.4+incompatible // indirect
github.com/vmihailenco/msgpack/v5 v5.4.1 // indirect
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
Expand Down
1 change: 1 addition & 0 deletions nobl9/provider.go
Expand Up @@ -109,6 +109,7 @@ func Provider() *schema.Provider {
"nobl9_project": resourceProject(),
"nobl9_role_binding": resourceRoleBinding(),
"nobl9_slo": resourceSLO(),
"nobl9_budget_adjustment": budgetAdjustment(),
},

ConfigureContextFunc: providerConfigure,
Expand Down

0 comments on commit 41cde93

Please sign in to comment.