Skip to content

Commit

Permalink
WIP: Add backup_config resource
Browse files Browse the repository at this point in the history
Note that this commit is still a work in progress as the final SDK
changes required for its use are not deployed yet.
  • Loading branch information
fantapop committed Oct 22, 2024
1 parent 4a4444b commit 5a50b99
Show file tree
Hide file tree
Showing 15 changed files with 1,342 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

### Added

- The new [cockroach_backup_config](https://registry.terraform.io/providers/cockroachdb/cockroach/latest/docs/resources/backup_config) resource adds support for configuring [cluster backups](https://www.cockroachlabs.com/docs/cockroachcloud/managed-backups).

## [1.9.0] - 2024-10-07

- Added support for skipping [Innovation
Expand Down
127 changes: 127 additions & 0 deletions docs/resources/backup_config.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "cockroach_backup_config Resource - terraform-provider-cockroach"
subcategory: ""
description: |-
The backup settings for a cluster.
Each cluster has backup settings that determine if backups are enabled,
how frequently they are taken, and how long they are retained for.
The cockroach_backup_config resource allows you to manage backup
settings. It's important to note that the existence, or lack of this resource
does not indicate whether a backup configuration exists or not. If
the cockroach_backup_config resource exists, it indicates that Terraform is
managing the backup configuration.
As a result, removing the resource from the Terraform configuration will not
affect the settings in the backup configuration.
retention_days Edit Restrictions
retention_days can only be set once. It is necessary to open a
support ticket to modify the setting again. For this reason, consider the
following when managing the value in Terraform:
* (Optional) Refrain from including retention_days in the Terraform resource to
rely on server-side management of the value instead.
* If the initial value for retention_days in
the cockroach_backup_config resource is the default value (i.e. 30), it will be
possible to modify the retention setting one more time.
* If the initial value set for retention_days in
the cockroach_backup_config resource is not the default, it will not be
possible to modify the retention setting again. Further modifications will
require a support ticket.
Changing the value of retention_days after using your one change will be a
multi-step operation. Here are two workflows that will work. Both of these
options assume you already have a cockroach_backup_config resource
that can no longer be updated:
Change it and then open a ticket before applying:
Update retention_days to the new value in Terraform.Before applying the run, contact support to change the retention_days to the new value.Apply the changes in Terraform. A Terraform READ operation will complete,
recognize the existing value, and update the tf state.Temporarily remove management of the resource from Terraform, update it via
ticket, and then add it back.
Remove management of retention_days from the Terraform resourceRun the apply. Nothing will change but Terraform is no longer managing that value.Open a support ticket to update retention_days to the new value.(Optional) Add retention_days back to the Terraform config with the
new value and apply the no-op update.
---

# cockroach_backup_config (Resource)

The backup settings for a cluster.

Each cluster has backup settings that determine if backups are enabled,
how frequently they are taken, and how long they are retained for.
The `cockroach_backup_config` resource allows you to manage backup
settings. It's important to note that the existence, or lack of this resource
does not indicate whether a backup configuration exists or not. If
the `cockroach_backup_config` resource exists, it indicates that Terraform is
managing the backup configuration.

As a result, removing the resource from the Terraform configuration will not
affect the settings in the backup configuration.

### `retention_days` Edit Restrictions

`retention_days` can only be set once. It is necessary to open a
support ticket to modify the setting again. For this reason, consider the
following when managing the value in Terraform:
* (Optional) Refrain from including `retention_days` in the Terraform resource to
rely on server-side management of the value instead.
* If the initial value for `retention_days` in
the `cockroach_backup_config` resource is the default value (i.e. 30), it will be
possible to modify the retention setting one more time.
* If the initial value set for `retention_days` in
the `cockroach_backup_config` resource is not the default, it will not be
possible to modify the retention setting again. Further modifications will
require a support ticket.

Changing the value of `retention_days` after using your one change will be a
multi-step operation. Here are two workflows that will work. Both of these
options assume you already have a `cockroach_backup_config` resource
that can no longer be updated:

* Change it and then open a ticket before applying:
1. Update `retention_days` to the new value in Terraform.
1. Before applying the run, contact support to change the `retention_days` to the new value.
1. Apply the changes in Terraform. A Terraform READ operation will complete,
recognize the existing value, and update the tf state.
* Temporarily remove management of the resource from Terraform, update it via
ticket, and then add it back.
1. Remove management of `retention_days` from the Terraform resource
1. Run the apply. Nothing will change but Terraform is no longer managing that value.
1. Open a support ticket to update `retention_days` to the new value.
1. (Optional) Add `retention_days` back to the Terraform config with the
new value and apply the no-op update.

## Example Usage

```terraform
resource "cockroach_backup_config" "backed_up_cluster" {
id = cockroach_cluster.backed_up_cluster.id
enabled = true
frequence_minutes = 60
retention_days = 30
}
resource "cockroach_backup_config" "no_backups_cluster" {
id = cockroach_cluster.no_backups_cluster.id
enabled = false
}
```

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

### Required

- `enabled` (Boolean) Indicates whether backups are enabled. If set to false, no backups will be created.
- `id` (String) Cluster ID.

### Optional

- `frequency_minutes` (Number) The frequency of backups in minutes. Valid values are [5, 10, 15, 30, 60, 240, 1440]
- `retention_days` (Number) The number of days to retain backups for. Valid values are [2, 7, 30, 90, 365]. Can only be set once, further changes require opening a support ticket. [See more](#retention_days-edit-restrictions).

## Import

Import is supported using the following syntax:

```shell
# format <resource> <cluster id>
terraform import cockroach_backup_config.backed_up_cluster 1f69fdd2-600a-4cfc-a9ba-16995df0d77d
```
2 changes: 2 additions & 0 deletions examples/resources/cockroach_backup_config/import.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# format <resource> <cluster id>
terraform import cockroach_backup_config.backed_up_cluster 1f69fdd2-600a-4cfc-a9ba-16995df0d77d
11 changes: 11 additions & 0 deletions examples/resources/cockroach_backup_config/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
resource "cockroach_backup_config" "backed_up_cluster" {
id = cockroach_cluster.backed_up_cluster.id
enabled = true
frequence_minutes = 60
retention_days = 30
}

resource "cockroach_backup_config" "no_backups_cluster" {
id = cockroach_cluster.no_backups_cluster.id
enabled = false
}
Loading

0 comments on commit 5a50b99

Please sign in to comment.