Skip to content

Commit

Permalink
Add backup resource and data sources (#57)
Browse files Browse the repository at this point in the history
This change adds backup resource and data sources to manage and inspect
backups for the NuoDB DBaaS Control Plane.
  • Loading branch information
adriansuarez authored May 29, 2024
1 parent a6f522d commit 75208d2
Show file tree
Hide file tree
Showing 23 changed files with 1,185 additions and 96 deletions.
65 changes: 65 additions & 0 deletions docs/data-sources/backup.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "nuodbaas_backup Data Source - nuodbaas"
subcategory: ""
description: |-
Data source for exposing information about NuoDB backups created using the DBaaS Control Plane
---

# nuodbaas_backup (Data Source)

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

## Example Usage

```terraform
# Data source that returns the attributes of a specific backup
data "nuodbaas_backup" "backup_details" {
organization = nuodbaas_backup.backup.organization
project = nuodbaas_backup.backup.project
database = nuodbaas_backup.backup.database
name = nuodbaas_backup.backup.name
}
```

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

### Required

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

### Read-Only

- `import_source` (Attributes) (see [below for nested schema](#nestedatt--import_source))
- `labels` (Map of String) User-defined labels attached to the resource that can be used for filtering
- `status` (Attributes) (see [below for nested schema](#nestedatt--status))

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

Read-Only:

- `backup_handle` (String) The existing backup handle to import
- `backup_plugin` (String) The plugin used to create the backup to import


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

Read-Only:

- `backup_handle` (String) The handle for the backup
- `backup_plugin` (String) The plugin used to manage the backup
- `created_by_policy` (String) The fully-qualified name of the backup policy that the backup was created by
- `creation_time` (String) The time that the backup was taken
- `message` (String) Message summarizing the state of the backup
- `ready_to_use` (Boolean) Whether the backup is ready to be used to restore a database
- `state` (String) The state of the backup:
* `Pending` - The backup is pending completion
* `Succeeded` - The backup completed successfully and is available for use
* `Failed` - The backup failed and is unusable
* `Deleting` - The backup has been marked for deletion, which is in progress
5 changes: 2 additions & 3 deletions docs/data-sources/backuppolicy.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ Data source for exposing information about NuoDB backup policies created using t
```terraform
# Data source that returns the attributes of a specific backup policy
data "nuodbaas_backuppolicy" "policy_details" {
organization = "org"
name = "pol"
depends_on = [nuodbaas_backuppolicy.pol]
organization = nuodbaas_backuppolicy.pol.organization
name = nuodbaas_backuppolicy.pol.name
}
```

Expand Down
86 changes: 86 additions & 0 deletions docs/data-sources/backups.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: "nuodbaas_backups Data Source - nuodbaas"
subcategory: ""
description: |-
Data source for listing NuoDB backups created using the DBaaS Control Plane
---

# nuodbaas_backups (Data Source)

Data source for listing NuoDB backups created using the DBaaS Control Plane

## Example Usage

```terraform
# Data source that returns the fully-qualified names of all backups
data "nuodbaas_backups" "backup_list" {}
# Data source that returns the fully-qualified names of backups within an organization
data "nuodbaas_backups" "org_backup_list" {
filter = {
organization = "org"
}
}
# Data source that returns the fully-qualified names of backups within a project
data "nuodbaas_backups" "proj_backup_list" {
filter = {
organization = "org"
project = "proj"
}
}
# Data source that returns the fully-qualified names of backups within a database
data "nuodbaas_backups" "db_backup_list" {
filter = {
organization = "org"
project = "proj"
database = "db"
}
}
# Data source that returns the fully-qualified names of backups satisfying label requirements
data "nuodbaas_backups" "label_backup_list" {
filter = {
labels = ["withkey", "key=expected", "key!=unexpected", "!withoutkey"]
}
}
```

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

### Optional

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

### Read-Only

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

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

Optional:

- `database` (String) The database to filter backups on. If specified, the project must also be specified.
- `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 backups on
- `project` (String) The project to filter backups on. If specified, the organization must also be specified.


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

Read-Only:

- `database` (String) The database the backup belongs to
- `name` (String) The name of the backup
- `organization` (String) The organization the backup belongs to
- `project` (String) The project the backup belongs to
7 changes: 3 additions & 4 deletions docs/data-sources/database.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@ Data source for exposing information about NuoDB databases created using the DBa
```terraform
# Data source that returns the attributes of a specific database
data "nuodbaas_database" "database_details" {
organization = "org"
project = "proj"
name = "db"
depends_on = [nuodbaas_database.db]
organization = nuodbaas_database.db.organization
project = nuodbaas_database.db.project
name = nuodbaas_database.db.name
}
```

Expand Down
5 changes: 2 additions & 3 deletions docs/data-sources/project.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ Data source for exposing information about NuoDB projects created using the DBaa
```terraform
# Data source that returns the attributes of a specific project
data "nuodbaas_project" "project_details" {
organization = "org"
name = "proj"
depends_on = [nuodbaas_project.proj]
organization = nuodbaas_project.proj.organization
name = nuodbaas_project.proj.name
}
```

Expand Down
86 changes: 86 additions & 0 deletions docs/resources/backup.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: "nuodbaas_backup Resource - nuodbaas"
subcategory: ""
description: |-
Resource for managing NuoDB backups created using the DBaaS Control Plane
---

# nuodbaas_backup (Resource)

Resource for managing NuoDB backups created using the DBaaS Control Plane

## Example Usage

```terraform
# A backup referencing an existing backup handle
resource "nuodbaas_backup" "backup" {
organization = nuodbaas_database.db.organization
project = nuodbaas_database.db.project
database = nuodbaas_database.db.name
name = "backup"
labels = {
latest = "true"
purpose = "test"
}
import_source = {
backup_handle = "backup"
backup_plugin = "embedded.cp.nuodb.com"
}
}
```

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

### Required

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

### Optional

- `import_source` (Attributes) (see [below for nested schema](#nestedatt--import_source))
- `labels` (Map of String) User-defined labels attached to the resource that can be used for filtering

### Read-Only

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

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

Required:

- `backup_handle` (String) The existing backup handle to import
- `backup_plugin` (String) The plugin used to create the backup to import


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

Read-Only:

- `backup_handle` (String) The handle for the backup
- `backup_plugin` (String) The plugin used to manage the backup
- `created_by_policy` (String) The fully-qualified name of the backup policy that the backup was created by
- `creation_time` (String) The time that the backup was taken
- `message` (String) Message summarizing the state of the backup
- `ready_to_use` (Boolean) Whether the backup is ready to be used to restore a database
- `state` (String) The state of the backup:
* `Pending` - The backup is pending completion
* `Succeeded` - The backup completed successfully and is available for use
* `Failed` - The backup failed and is unusable
* `Deleting` - The backup has been marked for deletion, which is in progress

## Import

Import is supported using the following syntax:

```shell
# An existing backup can be imported by specifying the organization,
# project name, database name, and backup name separated by "/"
terraform import nuodbaas_backup.backup org/proj/db/backup
```
7 changes: 7 additions & 0 deletions examples/data-sources/nuodbaas_backup/data-source.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Data source that returns the attributes of a specific backup
data "nuodbaas_backup" "backup_details" {
organization = nuodbaas_backup.backup.organization
project = nuodbaas_backup.backup.project
database = nuodbaas_backup.backup.database
name = nuodbaas_backup.backup.name
}
5 changes: 2 additions & 3 deletions examples/data-sources/nuodbaas_backuppolicy/data-source.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Data source that returns the attributes of a specific backup policy
data "nuodbaas_backuppolicy" "policy_details" {
organization = "org"
name = "pol"
depends_on = [nuodbaas_backuppolicy.pol]
organization = nuodbaas_backuppolicy.pol.organization
name = nuodbaas_backuppolicy.pol.name
}
34 changes: 34 additions & 0 deletions examples/data-sources/nuodbaas_backups/data-source.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Data source that returns the fully-qualified names of all backups
data "nuodbaas_backups" "backup_list" {}


# Data source that returns the fully-qualified names of backups within an organization
data "nuodbaas_backups" "org_backup_list" {
filter = {
organization = "org"
}
}

# Data source that returns the fully-qualified names of backups within a project
data "nuodbaas_backups" "proj_backup_list" {
filter = {
organization = "org"
project = "proj"
}
}

# Data source that returns the fully-qualified names of backups within a database
data "nuodbaas_backups" "db_backup_list" {
filter = {
organization = "org"
project = "proj"
database = "db"
}
}

# Data source that returns the fully-qualified names of backups satisfying label requirements
data "nuodbaas_backups" "label_backup_list" {
filter = {
labels = ["withkey", "key=expected", "key!=unexpected", "!withoutkey"]
}
}
7 changes: 3 additions & 4 deletions examples/data-sources/nuodbaas_database/data-source.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Data source that returns the attributes of a specific database
data "nuodbaas_database" "database_details" {
organization = "org"
project = "proj"
name = "db"
depends_on = [nuodbaas_database.db]
organization = nuodbaas_database.db.organization
project = nuodbaas_database.db.project
name = nuodbaas_database.db.name
}
5 changes: 2 additions & 3 deletions examples/data-sources/nuodbaas_project/data-source.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Data source that returns the attributes of a specific project
data "nuodbaas_project" "project_details" {
organization = "org"
name = "proj"
depends_on = [nuodbaas_project.proj]
organization = nuodbaas_project.proj.organization
name = nuodbaas_project.proj.name
}
3 changes: 3 additions & 0 deletions examples/resources/nuodbaas_backup/import.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# An existing backup can be imported by specifying the organization,
# project name, database name, and backup name separated by "/"
terraform import nuodbaas_backup.backup org/proj/db/backup
15 changes: 15 additions & 0 deletions examples/resources/nuodbaas_backup/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# A backup referencing an existing backup handle
resource "nuodbaas_backup" "backup" {
organization = nuodbaas_database.db.organization
project = nuodbaas_database.db.project
database = nuodbaas_database.db.name
name = "backup"
labels = {
latest = "true"
purpose = "test"
}
import_source = {
backup_handle = "backup"
backup_plugin = "embedded.cp.nuodb.com"
}
}
Loading

0 comments on commit 75208d2

Please sign in to comment.