Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dbaas support for mysql,pg database #410

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion docs/data-sources/database_uri.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ description: |-
Fetch Exoscale Database https://community.exoscale.com/documentation/dbaas/ connection URI data.
This data source returns database conection details of the default (admin) user only.
URI parts are also available individually for convenience.
Corresponding resource: exoscale_database ../resources/database.md.
Corresponding resource: exoscale_dbaas ../resources/database.md.
---

# exoscale_database_uri (Data Source)
Expand Down
2 changes: 2 additions & 0 deletions docs/resources/database.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
page_title: "exoscale_database Resource - terraform-provider-exoscale"
subcategory: ""
description: |-
❗This resource is deprecated and renamed to exoscale_dbaas, do not use it to create new resources❗
Manage Exoscale Database Services (DBaaS) https://community.exoscale.com/documentation/dbaas/.
---

# exoscale_database (Resource)

❗This resource is deprecated and renamed to exoscale_dbaas, do not use it to create new resources❗
Manage Exoscale [Database Services (DBaaS)](https://community.exoscale.com/documentation/dbaas/).

## Example Usage
Expand Down
173 changes: 173 additions & 0 deletions docs/resources/dbaas.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "exoscale_dbaas Resource - terraform-provider-exoscale"
subcategory: ""
description: |-
Manage Exoscale Database Services (DBaaS) https://community.exoscale.com/documentation/dbaas/.
---

# exoscale_dbaas (Resource)

Manage Exoscale [Database Services (DBaaS)](https://community.exoscale.com/documentation/dbaas/).



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

### Required

- `name` (String) ❗ The name of the database service.
- `plan` (String) The plan of the database service (use the [Exoscale CLI](https://github.com/exoscale/cli/) - `exo dbaas type show <TYPE> --plans` - for reference).
- `type` (String) ❗ The type of the database service (`kafka`, `mysql`, `opensearch`, `pg`, `redis`, `grafana`).
- `zone` (String) ❗ The Exoscale [Zone](https://www.exoscale.com/datacenters/) name.

### Optional

- `grafana` (Block, Optional) *grafana* database service type specific arguments. Structure is documented below. (see [below for nested schema](#nestedblock--grafana))
- `kafka` (Block, Optional) *kafka* database service type specific arguments. Structure is documented below. (see [below for nested schema](#nestedblock--kafka))
- `maintenance_dow` (String) The day of week to perform the automated database service maintenance (`never`, `monday`, `tuesday`, `wednesday`, `thursday`, `friday`, `saturday`, `sunday`).
- `maintenance_time` (String) The time of day to perform the automated database service maintenance (`HH:MM:SS`)
- `mysql` (Block, Optional) *mysql* database service type specific arguments. Structure is documented below. (see [below for nested schema](#nestedblock--mysql))
- `opensearch` (Block, Optional) *opensearch* database service type specific arguments. Structure is documented below. (see [below for nested schema](#nestedblock--opensearch))
- `pg` (Block, Optional) *pg* database service type specific arguments. Structure is documented below. (see [below for nested schema](#nestedblock--pg))
- `redis` (Block, Optional) *redis* database service type specific arguments. Structure is documented below. (see [below for nested schema](#nestedblock--redis))
- `termination_protection` (Boolean) The database service protection boolean flag against termination/power-off.
- `timeouts` (Block, Optional) (see [below for nested schema](#nestedblock--timeouts))

### Read-Only

- `ca_certificate` (String) CA Certificate required to reach a DBaaS service through a TLS-protected connection.
- `created_at` (String) The creation date of the database service.
- `disk_size` (Number) The disk size of the database service.
- `id` (String) The ID of this resource.
- `node_cpus` (Number) The number of CPUs of the database service.
- `node_memory` (Number) The amount of memory of the database service.
- `nodes` (Number) The number of nodes of the database service.
- `state` (String) The current state of the database service.
- `updated_at` (String) The date of the latest database service update.

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

Optional:

- `grafana_settings` (String) Grafana configuration settings in JSON format (`exo dbaas type show grafana --settings=grafana` for reference).
- `ip_filter` (Set of String) A list of CIDR blocks to allow incoming connections from.


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

Optional:

- `enable_cert_auth` (Boolean) Enable certificate-based authentication method.
- `enable_kafka_connect` (Boolean) Enable Kafka Connect.
- `enable_kafka_rest` (Boolean) Enable Kafka REST.
- `enable_sasl_auth` (Boolean) Enable SASL-based authentication method.
- `enable_schema_registry` (Boolean) Enable Schema Registry.
- `ip_filter` (Set of String) A list of CIDR blocks to allow incoming connections from.
- `kafka_connect_settings` (String) Kafka Connect configuration settings in JSON format (`exo dbaas type show kafka --settings=kafka-connect` for reference).
- `kafka_rest_settings` (String) Kafka REST configuration settings in JSON format (`exo dbaas type show kafka --settings=kafka-rest` for reference).
- `kafka_settings` (String) Kafka configuration settings in JSON format (`exo dbaas type show kafka --settings=kafka` for reference).
- `schema_registry_settings` (String) Schema Registry configuration settings in JSON format (`exo dbaas type show kafka --settings=schema-registry` for reference)
- `version` (String) Kafka major version (`exo dbaas type show kafka` for reference; may only be set at creation time).


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

Optional:

- `admin_password` (String, Sensitive) A custom administrator account password (may only be set at creation time).
- `admin_username` (String) A custom administrator account username (may only be set at creation time).
- `backup_schedule` (String) The automated backup schedule (`HH:MM`).
- `ip_filter` (Set of String) A list of CIDR blocks to allow incoming connections from.
- `mysql_settings` (String) MySQL configuration settings in JSON format (`exo dbaas type show mysql --settings=mysql` for reference).
- `version` (String) MySQL major version (`exo dbaas type show mysql` for reference; may only be set at creation time).


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

Optional:

- `dashboards` (Block, Optional) OpenSearch Dashboards settings (see [below for nested schema](#nestedblock--opensearch--dashboards))
- `fork_from_service` (String) ❗ Service name
- `index_pattern` (Block List) (can be used multiple times) Allows you to create glob style patterns and set a max number of indexes matching this pattern you want to keep. Creating indexes exceeding this value will cause the oldest one to get deleted. You could for example create a pattern looking like 'logs.?' and then create index logs.1, logs.2 etc, it will delete logs.1 once you create logs.6. Do note 'logs.?' does not apply to logs.10. Note: Setting max_index_count to 0 will do nothing and the pattern gets ignored. (see [below for nested schema](#nestedblock--opensearch--index_pattern))
- `index_template` (Block, Optional) Template settings for all new indexes (see [below for nested schema](#nestedblock--opensearch--index_template))
- `ip_filter` (Set of String) Allow incoming connections from this list of CIDR address block, e.g. `["10.20.0.0/16"]
- `keep_index_refresh_interval` (Boolean) Aiven automation resets index.refresh_interval to default value for every index to be sure that indices are always visible to search. If it doesn't fit your case, you can disable this by setting up this flag to true.
- `max_index_count` (Number) Maximum number of indexes to keep (Minimum value is `0`)
- `recovery_backup_name` (String) ❗ Name of a backup to recover from
- `settings` (String) OpenSearch-specific settings, in json. e.g.`jsonencode({thread_pool_search_size: 64})`. Use `exo x get-dbaas-settings-opensearch` to get a list of available settings.
- `version` (String) ❗ OpenSearch major version (`exo dbaas type show opensearch` for reference)

<a id="nestedblock--opensearch--dashboards"></a>
### Nested Schema for `opensearch.dashboards`

Optional:

- `enabled` (Boolean) Enable or disable OpenSearch Dashboards (default: true).
- `max_old_space_size` (Number) Limits the maximum amount of memory (in MiB) the OpenSearch Dashboards process can use. This sets the max_old_space_size option of the nodejs running the OpenSearch Dashboards. Note: the memory reserved by OpenSearch Dashboards is not available for OpenSearch. (default: 128).
- `request_timeout` (Number) Timeout in milliseconds for requests made by OpenSearch Dashboards towards OpenSearch (default: 30000)


<a id="nestedblock--opensearch--index_pattern"></a>
### Nested Schema for `opensearch.index_pattern`

Optional:

- `max_index_count` (Number) Maximum number of indexes to keep before deleting the oldest one (Minimum value is `0`)
- `pattern` (String) fnmatch pattern
- `sorting_algorithm` (String) `alphabetical` or `creation_date`.


<a id="nestedblock--opensearch--index_template"></a>
### Nested Schema for `opensearch.index_template`

Optional:

- `mapping_nested_objects_limit` (Number) The maximum number of nested JSON objects that a single document can contain across all nested types. This limit helps to prevent out of memory errors when a document contains too many nested objects. (Default is 10000. Minimum value is `0`, maximum value is `100000`.)
- `number_of_replicas` (Number) The number of replicas each primary shard has. (Minimum value is `0`, maximum value is `29`)
- `number_of_shards` (Number) The number of primary shards that an index should have. (Minimum value is `1`, maximum value is `1024`.)



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

Optional:

- `admin_password` (String, Sensitive) A custom administrator account password (may only be set at creation time).
- `admin_username` (String) A custom administrator account username (may only be set at creation time).
- `backup_schedule` (String) The automated backup schedule (`HH:MM`).
- `ip_filter` (Set of String) A list of CIDR blocks to allow incoming connections from.
- `pg_settings` (String) PostgreSQL configuration settings in JSON format (`exo dbaas type show pg --settings=pg` for reference).
- `pgbouncer_settings` (String) PgBouncer configuration settings in JSON format (`exo dbaas type show pg --settings=pgbouncer` for reference).
- `pglookout_settings` (String) pglookout configuration settings in JSON format (`exo dbaas type show pg --settings=pglookout` for reference).
- `version` (String) PostgreSQL major version (`exo dbaas type show pg` for reference; may only be set at creation time).


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

Optional:

- `ip_filter` (Set of String) A list of CIDR blocks to allow incoming connections from.
- `redis_settings` (String) Redis configuration settings in JSON format (`exo dbaas type show redis --settings=redis` for reference).


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

Optional:

- `create` (String) A string that can be [parsed as a duration](https://pkg.go.dev/time#ParseDuration) consisting of numbers and unit suffixes, such as "30s" or "2h45m". Valid time units are "s" (seconds), "m" (minutes), "h" (hours).
- `delete` (String) A string that can be [parsed as a duration](https://pkg.go.dev/time#ParseDuration) consisting of numbers and unit suffixes, such as "30s" or "2h45m". Valid time units are "s" (seconds), "m" (minutes), "h" (hours). Setting a timeout for a Delete operation is only applicable if changes are saved into state before the destroy operation occurs.
- `read` (String) A string that can be [parsed as a duration](https://pkg.go.dev/time#ParseDuration) consisting of numbers and unit suffixes, such as "30s" or "2h45m". Valid time units are "s" (seconds), "m" (minutes), "h" (hours). Read operations occur during any refresh or planning operation when refresh is enabled.
- `update` (String) A string that can be [parsed as a duration](https://pkg.go.dev/time#ParseDuration) consisting of numbers and unit suffixes, such as "30s" or "2h45m". Valid time units are "s" (seconds), "m" (minutes), "h" (hours).

-> The symbol ❗ in an attribute indicates that modifying it, will force the creation of a new resource.


44 changes: 44 additions & 0 deletions docs/resources/dbaas_mysql_database.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "exoscale_dbaas_mysql_database Resource - terraform-provider-exoscale"
subcategory: ""
description: |-
❗ Manage service database for a PostgreSQL Exoscale Database Services (DBaaS) https://community.exoscale.com/documentation/dbaas/.
---

# exoscale_dbaas_mysql_database (Resource)

❗ Manage service database for a PostgreSQL Exoscale [Database Services (DBaaS)](https://community.exoscale.com/documentation/dbaas/).



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

### Required

- `database_name` (String) ❗ The name of the database for this service.
- `service` (String) ❗ The name of the database service.
- `zone` (String) ❗ The Exoscale [Zone](https://www.exoscale.com/datacenters/) name.

### Optional

- `timeouts` (Block, Optional) (see [below for nested schema](#nestedblock--timeouts))

### Read-Only

- `id` (String) The ID of this resource, computed as service/database_name

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

Optional:

- `create` (String) A string that can be [parsed as a duration](https://pkg.go.dev/time#ParseDuration) consisting of numbers and unit suffixes, such as "30s" or "2h45m". Valid time units are "s" (seconds), "m" (minutes), "h" (hours).
- `delete` (String) A string that can be [parsed as a duration](https://pkg.go.dev/time#ParseDuration) consisting of numbers and unit suffixes, such as "30s" or "2h45m". Valid time units are "s" (seconds), "m" (minutes), "h" (hours). Setting a timeout for a Delete operation is only applicable if changes are saved into state before the destroy operation occurs.
- `read` (String) A string that can be [parsed as a duration](https://pkg.go.dev/time#ParseDuration) consisting of numbers and unit suffixes, such as "30s" or "2h45m". Valid time units are "s" (seconds), "m" (minutes), "h" (hours). Read operations occur during any refresh or planning operation when refresh is enabled.
- `update` (String) A string that can be [parsed as a duration](https://pkg.go.dev/time#ParseDuration) consisting of numbers and unit suffixes, such as "30s" or "2h45m". Valid time units are "s" (seconds), "m" (minutes), "h" (hours).

-> The symbol ❗ in an attribute indicates that modifying it, will force the creation of a new resource.


46 changes: 46 additions & 0 deletions docs/resources/dbaas_pg_database.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "exoscale_dbaas_pg_database Resource - terraform-provider-exoscale"
subcategory: ""
description: |-
❗ Manage service database for a PostgreSQL Exoscale Database Services (DBaaS) https://community.exoscale.com/documentation/dbaas/.
---

# exoscale_dbaas_pg_database (Resource)

❗ Manage service database for a PostgreSQL Exoscale [Database Services (DBaaS)](https://community.exoscale.com/documentation/dbaas/).



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

### Required

- `database_name` (String) ❗ The name of the database for this service.
- `service` (String) ❗ The name of the database service.
- `zone` (String) ❗ The Exoscale [Zone](https://www.exoscale.com/datacenters/) name.

### Optional

- `lc_collate` (String) Default string sort order (LC_COLLATE) for PostgreSQL database
- `lc_ctype` (String) Default character classification (LC_CTYPE) for PostgreSQL database
- `timeouts` (Block, Optional) (see [below for nested schema](#nestedblock--timeouts))

### Read-Only

- `id` (String) The ID of this resource, computed as service/database_name

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

Optional:

- `create` (String) A string that can be [parsed as a duration](https://pkg.go.dev/time#ParseDuration) consisting of numbers and unit suffixes, such as "30s" or "2h45m". Valid time units are "s" (seconds), "m" (minutes), "h" (hours).
- `delete` (String) A string that can be [parsed as a duration](https://pkg.go.dev/time#ParseDuration) consisting of numbers and unit suffixes, such as "30s" or "2h45m". Valid time units are "s" (seconds), "m" (minutes), "h" (hours). Setting a timeout for a Delete operation is only applicable if changes are saved into state before the destroy operation occurs.
- `read` (String) A string that can be [parsed as a duration](https://pkg.go.dev/time#ParseDuration) consisting of numbers and unit suffixes, such as "30s" or "2h45m". Valid time units are "s" (seconds), "m" (minutes), "h" (hours). Read operations occur during any refresh or planning operation when refresh is enabled.
- `update` (String) A string that can be [parsed as a duration](https://pkg.go.dev/time#ParseDuration) consisting of numbers and unit suffixes, such as "30s" or "2h45m". Valid time units are "s" (seconds), "m" (minutes), "h" (hours).

-> The symbol ❗ in an attribute indicates that modifying it, will force the creation of a new resource.


5 changes: 4 additions & 1 deletion pkg/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,14 @@ func (p *ExoscaleProvider) DataSources(ctx context.Context) []func() datasource.

func (p *ExoscaleProvider) Resources(ctx context.Context) []func() resource.Resource {
return []func() resource.Resource{
database.NewResource,
database.DeprecatedNewResource,
database.NewServiceResource,
database.NewMysqlUserResource,
database.NewKafkaUserResource,
database.NewOpensearchUserResource,
database.NewPGUserResource,
database.NewPGDatabaseResource,
database.NewMysqlDatabaseResource,
iam.NewResourceOrgPolicy,
iam.NewResourceRole,
iam.NewResourceAPIKey,
Expand Down
12 changes: 6 additions & 6 deletions pkg/resources/database/datasource_uri.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ This data source returns database conection details of the default (admin) user

URI parts are also available individually for convenience.

Corresponding resource: [exoscale_database](../resources/database.md).`
Corresponding resource: [exoscale_dbaas](../resources/database.md).`

// Ensure provider defined types fully satisfy framework interfaces.
var _ datasource.DataSourceWithConfigure = &DataSourceURI{}
Expand Down Expand Up @@ -214,12 +214,12 @@ polling:
return service, nil
}

// waitForDBAASServiceReadyForUsers polls the database service until it is ready to accept user creation
func waitForDBAASServiceReadyForUsers[T any](
// waitForDBAASServiceReadyForFn polls the database service until dbReady evaluates to true
func waitForDBAASServiceReadyForFn[T any](
ctx context.Context,
getService func(context.Context, string) (*T, error),
serviceName string,
usersReady func(*T) bool,
dbReadyFn func(*T) bool,
) (*T, error) {
ticker := time.NewTicker(2 * time.Second)
defer ticker.Stop()
Expand All @@ -233,8 +233,8 @@ polling:
return nil, fmt.Errorf("error polling service status: %w", err)
}

usersReady := usersReady(service)
if usersReady {
dbReady := dbReadyFn(service)
if dbReady {
break polling
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/resources/database/datasource_uri_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func testDataSourceURI(t *testing.T) {
pgUsername := acctest.RandomWithPrefix(testutils.TestUsername)
data := DataSourceURIModel{
ResourceName: "test",
Name: "exoscale_database.test.name",
Name: "exoscale_dbaas.test.name",
Zone: testutils.TestZoneName,
}

Expand Down
21 changes: 21 additions & 0 deletions pkg/resources/database/resource_db.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package database

import (
"github.com/hashicorp/terraform-plugin-framework-timeouts/resource/timeouts"
"github.com/hashicorp/terraform-plugin-framework/types"

v3 "github.com/exoscale/egoscale/v3"
)

type DBResource struct {
client *v3.Client
}

type DBResourceModel struct {
Id types.String `tfsdk:"id"`
Service types.String `tfsdk:"service"`
DatabaseName types.String `tfsdk:"database_name"`
Zone types.String `tfsdk:"zone"`

Timeouts timeouts.Value `tfsdk:"timeouts"`
}
Loading
Loading