Skip to content

Commit

Permalink
feat(DDS): import DDS resource, unit test and document
Browse files Browse the repository at this point in the history
  • Loading branch information
Zippo-Wang committed Nov 16, 2023
1 parent df09970 commit 2b54fee
Show file tree
Hide file tree
Showing 13 changed files with 1,526 additions and 27 deletions.
116 changes: 116 additions & 0 deletions docs/data-sources/dds_instances.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
---
subcategory: "Document Database Service (DDS)"
---

# g42cloud_dds_instances

Use this data source to get the list of DDS instances.

## Example Usage

```hcl
variable "vpc_id" {}
variable "subnet_id" {}
data "g42cloud_dds_instances" "test" {
name = "test_name"
mode = "Sharding"
vpc_id = var.vpc_id
subnet_id = var.subnet_id
}
```

## Argument Reference

The following arguments are supported:

* `region` - (Optional, String) Specifies the region in which to query the data source.
If omitted, the provider-level region will be used.

* `name` - (Optional, String) Specifies the DB instance name.

* `mode` - (Optional, String) Specifies the mode of the database instance.

* `vpc_id` - (Optional, String) Specifies the VPC ID.

* `subnet_id` - (Optional, String) Specifies the subnet Network ID.

## Attribute Reference

In addition to all arguments above, the following attributes are exported:

* `id` - The resource ID.

* `instances` - Indicates the list of DDS instances.
The [instances](#dds_instances) object structure is documented below.

<a name="dds_instances"></a>
The `instances` block supports:

* `id` - Indicates the ID of the instance.

* `name` - Indicates the DB instance name.

* `ssl` - Indicates whether to enable or disable SSL.

* `port` - Indicates the database port number. The port range is 2100 to 9500.

* `datastore` - Indicates database information.
The [datastore](#dds_datastore) object structure is documented below.

* `backup_strategy` - Indicates the database information.
The [backup_strategy](#dds_backup_strategy) object structure is documented below.

* `vpc_id` - Indicates the VPC ID

* `subnet_id` - Indicates the subnet Network ID.

* `security_group_id` - Indicates the security group ID of the DDS instance.

* `disk_encryption_id` - Indicates the disk encryption ID of the instance.

* `mode` - Specifies the mode of the database instance.

* `db_username` - Indicates the DB Administrator name.

* `status` - Indicates the DB instance status.

* `enterprise_project_id` - Indicates the enterprise project id of the dds instance.

* `nodes` - Indicates the instance nodes information.
The [nodes](#dds_nodes) object structure is documented below.

* `tags` - Indicates the key/value pairs to associate with the DDS instance.

<a name="dds_datastore"></a>
The `datastore` block supports:

* `type` - Indicates the DB engine.

* `version` - Indicates the DB instance version.

* `storage_engine` - Indicates the storage engine of the DB instance.

<a name="dds_backup_strategy"></a>
The `backup_strategy` block supports:

* `start_time` - Indicates the backup time window.

* `keep_days` - Indicates the number of days to retain the generated backup files.

<a name="dds_nodes"></a>
The `nodes` block supports:

* `id` - Indicates the node ID.

* `name` - Indicates the node name.

* `role` - Indicates the node role.

* `type` - Indicates the node type.

* `private_ip` - Indicates the private IP address of a node.

* `public_ip` - Indicates the EIP that has been bound on a node.

* `status` - Indicates the node status.
62 changes: 62 additions & 0 deletions docs/resources/dds_audit_log_policy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
---
subcategory: "Document Database Service (DDS)"
---

# g42cloud_dds_audit_log_policy

Manages a DDS audit log policy resource within G42Cloud.

## Example Usage

```hcl
variable "instance_id" {}
variable "keep_days" {}
resource "g42cloud_dds_audit_log_policy" "test"{
instance_id = var.instance_id
keep_days = var.keep_days
}
```

## Argument Reference

The following arguments are supported:

* `region` - (Optional, String, ForceNew) Specifies the region in which to create the resource.
If omitted, the provider-level region will be used. Changing this parameter will create a new resource.

* `instance_id` - (Required, String, ForceNew) Specifies the ID of the DDS instance.

Changing this parameter will create a new resource.

* `keep_days` - (Required, Int) Specifies the number of days for storing audit logs. The value ranges from 7 to 732.

* `audit_scope` - (Optional, String) Specifies the audit scope.
If this parameter is left blank or set to **all**, all audit log policies are enabled.
You can enter the database or collection name. Use commas (,) to separate multiple databases
or collections. If the name contains a comma (,), add a dollar sign ($) before the comma
to distinguish it from the separators. Enter a maximum of 1024 characters. The value
cannot contain spaces or the following special characters "[]{}():? The dollar sign ($)
can be used only in escape mode.

* `audit_types` - (Optional, List) Specifies the audit type. Value options are **auth**, **insert**, **delete**,
**update**, **query** or **command**.

* `reserve_auditlogs` - (Optional, String) Specifies whether the historical audit logs are
retained when SQL audit is disabled.
+ **true**: indicates that historical audit logs are retained when SQL audit is disabled.(default value)
+ **false**: indicates that existing historical audit logs are deleted when SQL audit is disabled.

## Attribute Reference

In addition to all arguments above, the following attributes are exported:

* `id` - The resource ID.

## Import

The DDS audit log policy can be imported using the instance ID, e.g.:

```bash
$ terraform import g42cloud_dds_audit_log.test <instance_id>
```
88 changes: 88 additions & 0 deletions docs/resources/dds_backup.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
---
subcategory: "Document Database Service (DDS)"
---

# g42cloud_dds_backup

Manages a DDS backup resource within G42Cloud.

## Example Usage

```hcl
variable "dds_instance_id" {}
variable "name" {}
resource "g42cloud_dds_backup" "test"{
instance_id = var.dds_instance_id
name = var.name
}
```

## Argument Reference

The following arguments are supported:

* `region` - (Optional, String, ForceNew) Specifies the region in which to create the resource.
If omitted, the provider-level region will be used. Changing this parameter will create a new resource.

* `instance_id` - (Required, String, ForceNew) Specifies the ID of a DDS instance.

Changing this parameter will create a new resource.

* `name` - (Required, String, ForceNew) Specifies the manual backup name.
The value must be 4 to 64 characters in length and start with a letter (from A to Z or from a to z).
It is case-sensitive and can contain only letters, digits (from 0 to 9), hyphens (-), and underscores (_).

Changing this parameter will create a new resource.

* `description` - (Optional, String, ForceNew) Specifies the manual backup description.

Changing this parameter will create a new resource.

## Attribute Reference

In addition to all arguments above, the following attributes are exported:

* `id` - The resource ID.

* `instance_name` - Indicates the name of a DDS instance.

* `datastore` - Indicates the database version.
The [datastore](#dds_datastore) object structure is documented below.

* `type` - Indicates the backup type. Valid value:
+ **Manual**: indicates manual full backup.

* `begin_time` - Indicates the start time of the backup. The format is yyyy-mm-dd hh:mm:ss. The value is in UTC format.

* `end_time` - Indicates the end time of the backup. The format is yyyy-mm-dd hh:mm:ss. The value is in UTC format.

* `status` - Indicates the backup status. Valid value:
+ **BUILDING**: Backup in progress.
+ **COMPLETED**: Backup completed.
+ **FAILED**: Backup failed.
+ **DISABLED**: Backup being deleted.

* `size` - Indicates the backup size in KB.

<a name="dds_datastore"></a>
The `datastore` block supports:

* `type` - Indicates the DB engine.

* `version` - Indicates the database version. The value can be **4.2**, **4.0**, or **3.4**.

## Timeouts

This resource provides the following timeouts configuration options:

* `create` - Default is 30 minutes.
* `delete` - Default is 10 minutes.

## Import

The DDS backup can be imported using the instance ID and the backup ID separated by a slash, e.g.:

```shell
terraform import g42cloud_dds_backup.test 6fb8b99944c7459da32f751f0edea756br02/0ce123456a00f2591fabc00385ff1234
```
106 changes: 106 additions & 0 deletions docs/resources/dds_database_role.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
---
subcategory: "Document Database Service (DDS)"
---

# g42cloud_dds_database_role

Manages a database role resource within G42Cloud.

## Example Usage

```hcl
variable "instance_id" {}
variable "role_name" {}
variable "db_name" {}
variable "owned_role_name" {}
variable "owned_role_db_name" {}
resource "g42cloud_dds_database_role" "test" {
instance_id = var.instance_id
name = var.role_name
db_name = var.db_name
roles {
name = var.owned_role_name
db_name = var.owned_role_db_name
}
}
```

## Argument Reference

The following arguments are supported:

* `region` - (Optional, String, ForceNew) Specifies the region where the DDS instance is located.
Changing this parameter will create a new role.

* `instance_id` - (Required, String, ForceNew) Specifies the DDS instance ID to which the role belongs.
Changing this parameter will create a new role.

* `name` - (Required, String, ForceNew) Specifies the role name.
The name can contain `1` to `64` characters, only letters, digits, underscores (_), hyphens (-) and dots (.) are
allowed. Changing this parameter will create a new role.

* `db_name` - (Required, String, ForceNew) Specifies the database name to which the role belongs.
The name can contain `1` to `64` characters, only letters, digits and underscores (_) are allowed.
Changing this parameter will create a new role.

-> After a DDS instances is created, the default database is **admin**.

* `roles` - (Optional, List, ForceNew) Specifies the list of roles owned by the current role.
The [roles](#dds_roles) object structure is documented below.
Changing this parameter will create a new role.

<a name="dds_roles"></a>
The `roles` block supports:

* `name` - (Required, String, ForceNew) Specifies the name of role owned by the current role.
The name can contain `1` to `64` characters, only letters, digits, underscores (_), hyphens (-) and dots (.) are
allowed. Changing this parameter will create a new role.

* `db_name` - (Required, String, ForceNew) Specifies the database name to which this owned role belongs.
Changing this parameter will create a new role.

## Attribute Reference

In addition to all arguments above, the following attributes are exported:

* `id` - The resource ID.

* `privileges` - The list of database privileges owned by the current role.
The [privileges](#dds_privileges) object structure is documented below.

* `inherited_privileges` - The list of database privileges owned by the current role, includes all privileges
inherited by owned roles. The [inherited_privileges](#dds_privileges) object structure is documented below.

<a name="dds_privileges"></a>
The `privileges` and `inherited_privileges` block supports:

* `resources` - The details of the resource to which the privilege belongs.
The [resources](#dds_resources) structure is documented below.

* `actions` - The operation permission list.

<a name="dds_resources"></a>
The `resources` block supports:

* `collection` - The database collection type.

* `db_name` - The database name.

## Timeouts

This resource provides the following timeouts configuration options:

* `create` - Default is 2 minutes.
* `delete` - Default is 2 minutes.

## Import

Database roles can be imported using their `id` (combination of `instance_id`, `db_name` and `name`), separated by a
slash (/), e.g.

```shell
terraform import g42cloud_dds_database_role.test &ltinstance_id&gt/&ltdb_name&gt/&ltname&gt
```
Loading

0 comments on commit 2b54fee

Please sign in to comment.