Skip to content

Commit

Permalink
Add backuppolicy resource and data sources (#54)
Browse files Browse the repository at this point in the history
This change adds the backuppolicy resource for managing backup policies
via the NuoDB DBaaS REST API, the backuppolicy data source for obtaining
the state of an existing backup policy, and the backuppolicies data
source for listing existing backup policies.

Other changes:
- Update the set of REST resources and models that we generate Golang
  code for using oapi-codegen, which exposed a bug in oapi-codegen
  (oapi-codegen/oapi-codegen#1614). The
  fix-generated.sh script implements a workaround for that bug.
- Strip ANSI color codes and remove special formatting and line-wrapping
  from Error and Warning messages to allow asserts to check for the
  presence of substrings.
- Change the examples tests to only run `terraform validate` on the
  examples, rather than `terraform plan` or `terraform apply`. This
  allows us to test the examples without a server, which avoids
  introducing dependencies on the REST server supporting a particular
  resource or data source.
  • Loading branch information
adriansuarez authored May 23, 2024
1 parent 90702f5 commit 8841acc
Show file tree
Hide file tree
Showing 30 changed files with 8,378 additions and 2,460 deletions.
2 changes: 1 addition & 1 deletion deploy/external/env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ export NUODB_CP_URL_BASE="$DBAAS_API_ENDPOINT"
export CONTAINER_SCHEDULING_ENABLED="true"
export WEBHOOKS_ENABLED="true"
export ORGANIZATION_BOUND_USER="true"
export TESTARGS="-short -tags shared_env"
export TESTARGS="-tags shared_env"
EOF
1 change: 0 additions & 1 deletion deploy/minikube/env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ cd "$(dirname "$0")"
export KUBECONFIG
cat <<EOF
export KUBECONFIG="$KUBECONFIG"
export TESTARGS="-short"
EOF

# Print common K8s environment variables
Expand Down
64 changes: 64 additions & 0 deletions docs/data-sources/backuppolicies.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "nuodbaas_backuppolicies Data Source - nuodbaas"
subcategory: ""
description: |-
Data source for listing NuoDB backup policies created using the DBaaS Control Plane
---

# nuodbaas_backuppolicies (Data Source)

Data source for listing NuoDB backup policies created using the DBaaS Control Plane

## Example Usage

```terraform
# Data source that returns the fully-qualified names of all backup policies
data "nuodbaas_backuppolicies" "policy_list" {}
# Data source that returns the fully-qualified names of backup policies within an organization
data "nuodbaas_backuppolicies" "org_policy_list" {
filter = {
organization = "org"
}
}
# Data source that returns the fully-qualified names of backup policies satisfying label requirements
data "nuodbaas_backuppolicies" "label_policy_list" {
filter = {
labels = ["withkey", "key=expected", "key!=unexpected", "!withoutkey"]
}
}
```

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

### Optional

- `filter` (Attributes) Filters to apply to policies (see [below for nested schema](#nestedatt--filter))

### Read-Only

- `policies` (Attributes List) The list of policies that satisfy the filter requirements (see [below for nested schema](#nestedatt--policies))

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

Optional:

- `labels` (List of String) List of filters to apply based on labels, which are composed using `AND`. Acceptable filter expressions are:
* `key` - Only return items that have label with specified key
* `key=value` - Only return items that have label with specified key set to value
* `!key` - Only return items that do _not_ have label with specified key
* `key!=value` - Only return items that do _not_ have label with specified key set to value
- `organization` (String) The organization to filter policies on


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

Read-Only:

- `name` (String) The name of the policy
- `organization` (String) The organization the policy belongs to
80 changes: 80 additions & 0 deletions docs/data-sources/backuppolicy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "nuodbaas_backuppolicy Data Source - nuodbaas"
subcategory: ""
description: |-
Data source for exposing information about NuoDB backup policies created using the DBaaS Control Plane
---

# nuodbaas_backuppolicy (Data Source)

Data source for exposing information about NuoDB backup policies created using the DBaaS Control Plane

## Example Usage

```terraform
# Data source that returns the attributes of a specific backup policy
data "nuodbaas_backuppolicy" "policy_details" {
organization = "org"
name = "pol"
}
```

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

### Required

- `name` (String) The name of the backup policy
- `organization` (String) The organization that the backup policy belongs to

### Read-Only

- `frequency` (String) The frequency to schedule backups at, in cron format
- `labels` (Map of String) User-defined labels attached to the resource that can be used for filtering
- `properties` (Attributes) (see [below for nested schema](#nestedatt--properties))
- `retention` (Attributes) (see [below for nested schema](#nestedatt--retention))
- `selector` (Attributes) (see [below for nested schema](#nestedatt--selector))
- `status` (Attributes) (see [below for nested schema](#nestedatt--status))
- `suspended` (Boolean) Whether backups from the policy are suspended

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

Read-Only:

- `propagate_database_labels` (Boolean) Whether to propagate the user-defined labels from the matching database to backup resources created by this policy
- `propagate_policy_labels` (Boolean) Whether to propagate the user-defined labels from the backup policy to backup resources created by this policy


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

Read-Only:

- `daily` (Number) The number of daily backups to retain
- `hourly` (Number) The number of hourly backups to retain
- `monthly` (Number) The number of monthly backups to retain
- `weekly` (Number) The number of weekly backups to retain
- `yearly` (Number) The number of yearly backups to retain


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

Read-Only:

- `labels` (Map of String) The user-defined labels to filter databases on
- `scope` (String) The scope that the backup policy applies to
- `slas` (List of String) The SLAs to filter databases on
- `tiers` (List of String) The tiers to filter databases on


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

Read-Only:

- `last_missed_schedule_time` (String) The time that backups were last missed by this policy
- `last_schedule_time` (String) The time that backups were last taken by this policy
- `next_schedule_time` (String) The time that backups are next scheduled by this policy
130 changes: 130 additions & 0 deletions docs/resources/backuppolicy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "nuodbaas_backuppolicy Resource - nuodbaas"
subcategory: ""
description: |-
Resource for managing NuoDB backup policies created using the DBaaS Control Plane
---

# nuodbaas_backuppolicy (Resource)

Resource for managing NuoDB backup policies created using the DBaaS Control Plane

## Example Usage

```terraform
# A backup policy with minimal configuration
resource "nuodbaas_backuppolicy" "basic" {
organization = "org"
name = "basic"
frequency = "@weekly"
selector = {
scope = "org"
}
}
# A backup policy with explicit configuration for various attributes
resource "nuodbaas_backuppolicy" "pol" {
organization = "org"
name = "pol"
labels = {
"provisioned-by" : "terraform"
}
frequency = "@daily"
selector = {
scope = "org"
slas = ["qa", "prod"]
tiers = ["n0.small", "n1.small"]
labels = {
"rpo" : "1d"
}
}
retention = {
hourly = 24
daily = 7
weekly = 4
monthly = 12
yearly = 3
}
suspended = false
properties = {
propagate_policy_labels = true
propagate_database_labels = true
}
}
```

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

### Required

- `frequency` (String) The frequency to schedule backups at, in cron format
- `name` (String) The name of the backup policy
- `organization` (String) The organization that the backup policy belongs to
- `selector` (Attributes) (see [below for nested schema](#nestedatt--selector))

### Optional

- `labels` (Map of String) User-defined labels attached to the resource that can be used for filtering
- `properties` (Attributes) (see [below for nested schema](#nestedatt--properties))
- `retention` (Attributes) (see [below for nested schema](#nestedatt--retention))
- `suspended` (Boolean) Whether backups from the policy are suspended

### Read-Only

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

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

Required:

- `scope` (String) The scope that the backup policy applies to

Optional:

- `labels` (Map of String) The user-defined labels to filter databases on
- `slas` (List of String) The SLAs to filter databases on
- `tiers` (List of String) The tiers to filter databases on


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

Optional:

- `propagate_database_labels` (Boolean) Whether to propagate the user-defined labels from the matching database to backup resources created by this policy
- `propagate_policy_labels` (Boolean) Whether to propagate the user-defined labels from the backup policy to backup resources created by this policy


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

Optional:

- `daily` (Number) The number of daily backups to retain
- `hourly` (Number) The number of hourly backups to retain
- `monthly` (Number) The number of monthly backups to retain
- `weekly` (Number) The number of weekly backups to retain
- `yearly` (Number) The number of yearly backups to retain


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

Read-Only:

- `last_missed_schedule_time` (String) The time that backups were last missed by this policy
- `last_schedule_time` (String) The time that backups were last taken by this policy
- `next_schedule_time` (String) The time that backups are next scheduled by this policy

## Import

Import is supported using the following syntax:

```shell
# An existing backup policy can be imported by specifying the organization
# and policy name, separated by "/"
terraform import nuodbaas_backuppolicy.pol org/pol
```
2 changes: 1 addition & 1 deletion docs/resources/project.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,5 +104,5 @@ Import is supported using the following syntax:
```shell
# An existing project can be imported by specifying the organization
# and project name, separated by "/"
terraform import nuodbaas_project.nuodb org/proj
terraform import nuodbaas_project.proj org/proj
```
16 changes: 16 additions & 0 deletions examples/data-sources/nuodbaas_backuppolicies/data-source.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Data source that returns the fully-qualified names of all backup policies
data "nuodbaas_backuppolicies" "policy_list" {}

# Data source that returns the fully-qualified names of backup policies within an organization
data "nuodbaas_backuppolicies" "org_policy_list" {
filter = {
organization = "org"
}
}

# Data source that returns the fully-qualified names of backup policies satisfying label requirements
data "nuodbaas_backuppolicies" "label_policy_list" {
filter = {
labels = ["withkey", "key=expected", "key!=unexpected", "!withoutkey"]
}
}
5 changes: 5 additions & 0 deletions examples/data-sources/nuodbaas_backuppolicy/data-source.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Data source that returns the attributes of a specific backup policy
data "nuodbaas_backuppolicy" "policy_details" {
organization = "org"
name = "pol"
}
Loading

0 comments on commit 8841acc

Please sign in to comment.