Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 86 additions & 0 deletions docs/data-sources/volume_automation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "stackit_volume_automation Data Source - stackit"
subcategory: ""
description: |-
Volume automation datasource schema. Must have a region specified in the provider configuration.
~> This datasource is in beta and may be subject to breaking changes in the future. Use with caution. See our guide https://registry.terraform.io/providers/stackitcloud/stackit/latest/docs/guides/opting_into_beta_resources for how to opt-in to use beta resources.
---

# stackit_volume_automation (Data Source)

Volume automation datasource schema. Must have a `region` specified in the provider configuration.

~> This datasource is in beta and may be subject to breaking changes in the future. Use with caution. See our [guide](https://registry.terraform.io/providers/stackitcloud/stackit/latest/docs/guides/opting_into_beta_resources) for how to opt-in to use beta resources.

## Example Usage

```terraform
data "stackit_volume_automation" "example" {
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
automation_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
}
```

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

### Required

- `automation_id` (String) ID of the volume automation.
- `project_id` (String) STACKIT Project ID to which the volume automation is associated.

### Optional

- `region` (String) The resource region. If not defined, the provider region is used.

### Read-Only

- `description` (String) The volume automation description.
- `id` (String) Terraform's internal resource identifier. It is structured as "`project_id`,`region`,`automation_id`".
- `input` (Attributes) Configuration input for the volume automation. Exactly one of the nested attributes must be set. (see [below for nested schema](#nestedatt--input))
- `name` (String) The volume automation name.
- `template_id` (String) ID of the automation template this volume automation is based on.
- `triggers` (Attributes) Triggers that determine when the automation runs. (see [below for nested schema](#nestedatt--triggers))

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

Read-Only:

- `volume_recovery_point_management` (Attributes) Configuration for automated volume recovery point (snapshot) management. (see [below for nested schema](#nestedatt--input--volume_recovery_point_management))

<a id="nestedatt--input--volume_recovery_point_management"></a>
### Nested Schema for `input.volume_recovery_point_management`

Read-Only:

- `inherit_volume_labels` (Boolean) Whether recovery points inherit the labels of the volume they were created from. Defaults to `false`.
- `recovery_point_labels` (Map of String) Labels to attach to created recovery points.
- `snapshot_retention_policy` (Attributes) Defines how long created recovery points (snapshots) are retained. (see [below for nested schema](#nestedatt--input--volume_recovery_point_management--snapshot_retention_policy))
- `volume_label_selector` (String) Label selector used to select the volumes this automation applies to.

<a id="nestedatt--input--volume_recovery_point_management--snapshot_retention_policy"></a>
### Nested Schema for `input.volume_recovery_point_management.snapshot_retention_policy`

Read-Only:

- `kind` (String) The retention policy kind. Valid values are: `count`, `indefinitely`.
- `value` (Number) Number of recovery points to retain. Required if `kind` is `count`, must not be set otherwise.




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

Read-Only:

- `schedule` (Attributes) Runs the automation on a recurring schedule. (see [below for nested schema](#nestedatt--triggers--schedule))

<a id="nestedatt--triggers--schedule"></a>
### Nested Schema for `triggers.schedule`

Read-Only:

- `rrule` (String) An `rrule` (Recurrence Rule) is a standardized string format used in iCalendar (RFC 5545) to define repeating events, and you can generate one by using a dedicated library or by using online generator tools to specify parameters like frequency, interval, and end dates.
126 changes: 126 additions & 0 deletions docs/resources/volume_automation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "stackit_volume_automation Resource - stackit"
subcategory: ""
description: |-
Volume automation resource schema. Must have a region specified in the provider configuration.
~> This resource is in beta and may be subject to breaking changes in the future. Use with caution. See our guide https://registry.terraform.io/providers/stackitcloud/stackit/latest/docs/guides/opting_into_beta_resources for how to opt-in to use beta resources.
---

# stackit_volume_automation (Resource)

Volume automation resource schema. Must have a `region` specified in the provider configuration.

~> This resource is in beta and may be subject to breaking changes in the future. Use with caution. See our [guide](https://registry.terraform.io/providers/stackitcloud/stackit/latest/docs/guides/opting_into_beta_resources) for how to opt-in to use beta resources.

## Example Usage

```terraform
resource "stackit_volume_automation" "example" {
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
template_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
name = "example-volume-automation"
description = "Creates daily volume snapshots and keeps the last 7."
input = {
volume_recovery_point_management = {
inherit_volume_labels = true
recovery_point_labels = {
"created-by" = "terraform"
}
volume_label_selector = "backup=daily"
snapshot_retention_policy = {
kind = "count"
value = 4
}
}
}
triggers = {
schedule = {
rrule = "DTSTART;TZID=Europe/Sofia:20200803T023000 RRULE:FREQ=DAILY;INTERVAL=1"
}
}
}
```

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

### Required

- `project_id` (String) STACKIT Project ID to which the volume automation is associated.
- `template_id` (String) ID of the automation template this volume automation is based on.

### Optional

- `description` (String) The volume automation description.
- `input` (Attributes) Configuration input for the volume automation. Exactly one of the nested attributes must be set. (see [below for nested schema](#nestedatt--input))
- `name` (String) The volume automation name.
- `region` (String) The resource region. If not defined, the provider region is used.
- `triggers` (Attributes) Triggers that determine when the automation runs. (see [below for nested schema](#nestedatt--triggers))

### Read-Only

- `automation_id` (String) ID of the volume automation.
- `id` (String) Terraform's internal resource identifier. It is structured as "`project_id`,`region`,`automation_id`".

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

Optional:

- `volume_recovery_point_management` (Attributes) Configuration for automated volume recovery point (snapshot) management. (see [below for nested schema](#nestedatt--input--volume_recovery_point_management))

<a id="nestedatt--input--volume_recovery_point_management"></a>
### Nested Schema for `input.volume_recovery_point_management`

Required:

- `snapshot_retention_policy` (Attributes) Defines how long created recovery points (snapshots) are retained. (see [below for nested schema](#nestedatt--input--volume_recovery_point_management--snapshot_retention_policy))

Optional:

- `inherit_volume_labels` (Boolean) Whether recovery points inherit the labels of the volume they were created from. Defaults to `false`.
- `recovery_point_labels` (Map of String) Labels to attach to created recovery points.
- `volume_label_selector` (String) Label selector used to select the volumes this automation applies to.

<a id="nestedatt--input--volume_recovery_point_management--snapshot_retention_policy"></a>
### Nested Schema for `input.volume_recovery_point_management.snapshot_retention_policy`

Required:

- `kind` (String) The retention policy kind. Valid values are: `count`, `indefinitely`.

Optional:

- `value` (Number) Number of recovery points to retain. Required if `kind` is `count`, must not be set otherwise.




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

Optional:

- `schedule` (Attributes) Runs the automation on a recurring schedule. (see [below for nested schema](#nestedatt--triggers--schedule))

<a id="nestedatt--triggers--schedule"></a>
### Nested Schema for `triggers.schedule`

Required:

- `rrule` (String) An `rrule` (Recurrence Rule) is a standardized string format used in iCalendar (RFC 5545) to define repeating events, and you can generate one by using a dedicated library or by using online generator tools to specify parameters like frequency, interval, and end dates.

## Import

Import is supported using the following syntax:

In Terraform v1.5.0 and later, the [` + "`" + `import` + "`" + ` block](https://developer.hashicorp.com/terraform/language/import) can be used with the ` + "`" + `id` + "`" + ` attribute, for example:

```terraform
# Only use the import statement, if you want to import an existing volume automation resource
import {
to = stackit_volume_automation.import-example
id = "${var.project_id},${var.region},${var.automation_id}"
}
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
data "stackit_volume_automation" "example" {
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
automation_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Only use the import statement, if you want to import an existing volume automation resource
import {
to = stackit_volume_automation.import-example
id = "${var.project_id},${var.region},${var.automation_id}"
}
24 changes: 24 additions & 0 deletions examples/resources/stackit_volume_automation/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
resource "stackit_volume_automation" "example" {
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
template_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
name = "example-volume-automation"
description = "Creates daily volume snapshots and keeps the last 7."
input = {
volume_recovery_point_management = {
inherit_volume_labels = true
recovery_point_labels = {
"created-by" = "terraform"
}
volume_label_selector = "backup=daily"
snapshot_retention_policy = {
kind = "count"
value = 4
}
}
}
triggers = {
schedule = {
rrule = "DTSTART;TZID=Europe/Sofia:20200803T023000 RRULE:FREQ=DAILY;INTERVAL=1"
}
}
}
10 changes: 10 additions & 0 deletions stackit/internal/conversion/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,16 @@ func StringValueToPointer(s basetypes.StringValue) *string {
return new(s.ValueString())
}

// StringPointerValueNullIfEmpty converts a string pointer to types.String, treating an empty
// string as null. Some APIs return "" instead of omitting unset optional fields, which would
// otherwise mismatch a null config for Optional, non-Computed attributes.
func StringPointerValueNullIfEmpty(s *string) types.String {
if s == nil || *s == "" {
return types.StringNull()
}
return types.StringValue(*s)
}

Comment on lines +109 to +118

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

types.StringPointerValue() can be used instead. It does the same thing and comes directly from the framework

// StringValueToPointer converts basetypes.StringValue to a pointer to enum.
// It returns nil if the value is null or unknown.
func StringValueToEnumPointer[T ~string](s basetypes.StringValue) *T {
Expand Down
31 changes: 31 additions & 0 deletions stackit/internal/conversion/conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,37 @@ func TestStringValueToPointer(t *testing.T) {
}
}

func TestStringPointerValueNullIfEmpty(t *testing.T) {
tests := []struct {
name string
arg *string
want basetypes.StringValue
}{
{
name: "value",
arg: new("abc"),
want: basetypes.NewStringValue("abc"),
},
{
name: "nil",
arg: nil,
want: basetypes.NewStringNull(),
},
{
name: "empty string treated as null",
arg: new(""),
want: basetypes.NewStringNull(),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := StringPointerValueNullIfEmpty(tt.arg); !reflect.DeepEqual(got, tt.want) {
t.Errorf("StringPointerValueNullIfEmpty() = %v, want %v", got, tt.want)
}
})
}
}

func TestStringValueToEnumPointer(t *testing.T) {
type args struct {
s basetypes.StringValue
Expand Down
Loading
Loading