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

refactor(postgresql): Update PostgreSQL Resource and Data Source #483

Merged
merged 6 commits into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from 5 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
33 changes: 17 additions & 16 deletions docs/data-sources/postgresql.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ The following example shows how to take PostgreSQL instance ID and obtain the da
data "ncloud_postgresql" "by_id" {
id = 12345
}

data "ncloud_postgresql" "by_name" {
service_name = "example"
}
Expand All @@ -34,33 +35,33 @@ This data source exports the following attributes in addition to the argument ab

* `region_code` - Region code.
* `vpc_no` - The ID of the associated VPC.
* `image_product_code` - The image product code of the PostgreSQL instance.
* `product_code` - Server specifications of the Cloud DB for PostgreSQL instance.
* `image_product_code` - The image product code of the instance.
* `generation_code` - The generation code of the image.
* `engine_version` - The engien version.
* `ha` - Whether using high availability. (`true` or `false`)
* `multi_zone` - Whether using multi zone. (`true` or `false`)
* `data_storage_type` - The type of data storage.
* `is_ha` - Whether using high availability of the specific PostgreSQL.
* `is_multi_zone` - Wheter using multi zone of the specific PostgreSQL.
* `is_storage_encryption` - Wheter data storage encryption is applied.
* `is_backup` - Wheter using backup of the specific PostgreSQL.
* `backup_file_retention_period` - The backup period of the PostgreSQL database.
* `backup_file_storage_count` - Number of backup files kept.
* `backup_time` - The backup time fo the PostgreSQL database.
* `storage_encryption` - Whether using storage encryption. (`true` or `false`)
* `backup` - Whether using backup. (`true` or `false`)
* `backup_file_retention_period` - Backup file retention period.
* `backup_time` - Backup time.
* `port` - Port of PostgreSQL instance.
* `engine_version` - The engien version of the specific PostgreSQL.
* `access_control_group_no_list` - The list of access control group number.
* `postgresql_config_list` - The list of config.
* `postgresql_server_list` - The list of PostgreSQL server instance.
* `server_instance_no` - Server instance number.
* `server_name` - Server name.
* `server_role` - Server role code. M(Primary), H(Secondary)
* `subnet_no` - Number of the associated Subnet.
* `server_role` - Server role code. M(Primary), H(Secondary), S(Read Replica)
* `product_code` - Product code.
* `is_public_subnet` - Public subnet status.
* `zone_code` - Zone code.
* `subnet_no` - Number of the associated Subnet.
* `public_subnet` - Public subnet status. (`true` or `false`)
* `public_domain` - Public domain.
* `private_domain` - Private domain.
* `private_ip` - Private IP.
* `memory_size` - Available memory size.
* `cpu_count` - CPU count.
* `data_storage_size` - Storage size.
* `used_data_storage_size` - Size of data storage in use.
* `cpu_count` - CPU count.
* `memory_size` - Available memory size.
* `uptime` - Running start time.
* `create_date` - Server create date.
* `create_date` - Server create date.
6 changes: 3 additions & 3 deletions docs/data-sources/postgresql_databases.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
subcategory: "PostgresSQL"
subcategory: "PostgreSQL"
---

# Data Source: ncloud_postgresql_databases
Expand Down Expand Up @@ -40,7 +40,7 @@ database_list = {

The following arguments are required:

* `postgresql_instance_no` - (Required) Postgresql Instance No.
* `id` - (Required) Postgresql Instance No.
* `output_file` - (Optional) The name of file that can save data source after running `terraform plan`.
* `filter` - (Optional) Custom filter block as described below.
* `name` - (Required) The name of the field to filter by.
Expand All @@ -53,4 +53,4 @@ This data source exports the following attributes in adddition to the argument a

* `postgresql_database_list` - The list of databases to add.
* `name` - PostgreSQL Databases ID.
* `owner` - User ID to manage the database.
* `owner` - User ID to manage the database.
8 changes: 3 additions & 5 deletions docs/data-sources/postgresql_users.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
subcategory: "PostgresSQL"
subcategory: "PostgreSQL"
---

# Data Source: ncloud_postgresql_users
Expand Down Expand Up @@ -29,7 +29,6 @@ output "user_list" {
}
```


Outputs:
```terraform
user_list = {
Expand All @@ -41,7 +40,7 @@ user_list = {

The following arguments are required:

* `postgresql_instance_no` - (Required) Postgresql Instance No.
* `id` - (Required) Postgresql Instance No.
* `output_file` - (Optional) The name of file that can save data source after running `terraform plan`.
* `filter` - (Optional) Custom filter block as described below.
* `name` - (Required) The name of the field to filter by
Expand All @@ -54,6 +53,5 @@ This data source exports the following attributes in adddition to the argument a

* `postgresql_user_list` - The list of users to add.
* `name` - PostgreSQL User ID.
* `password` - PostgreSQL User Password.
* `client_cidr` - Access Control (CIDR) of the client you want to connect
* `is_replication_role` - Replication Role or not
* `replication_role` - Replication Role or not
66 changes: 37 additions & 29 deletions docs/resources/postgresql.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,29 @@ Provides a PostgreSQL instance resource.
## Example Usage

```terraform
resource "ncloud_vpc" "test" {
ipv4_cidr_block = "10.0.0.0/16"
resource "ncloud_vpc" "vpc" {
name = "post-vpc"
ipv4_cidr_block = "10.0.0.0/16"
}
resource "ncloud_subnet" "test" {
vpc_no = ncloud_vpc.test.vpc_no
subnet = cidrsubnet(ncloud_vpc.test.ipv4_cidr_block, 8, 1)

resource "ncloud_subnet" "subnet" {
vpc_no = ncloud_vpc.vpc.vpc_no
name = "post-subnet"
subnet = cidrsubnet(ncloud_vpc.vpc.ipv4_cidr_block, 8, 1)
zone = "KR-2"
network_acl_no = ncloud_vpc.test.default_network_acl_no
network_acl_no = ncloud_vpc.vpc.default_network_acl_no
subnet_type = "PUBLIC"
}

resource "ncloud_postgresql" "postgresql" {
subnet_no = ncloud_subnet.test.id
service_name = "tf-postgresql"
service_name = "tf-postgresql"
server_name_prefix = "name-prefix"
user_name = "username"
user_password = "password1!"
client_cidr = "0.0.0.0/0"
database_name = "db_name"
user_name = "username"
user_password = "password1!"
vpc_no = ncloud_vpc.vpc.vpc_no
subnet_no = ncloud_subnet.subnet.id
client_cidr = "0.0.0.0/0"
database_name = "db_name"
}
```

Expand All @@ -38,49 +43,52 @@ The following arguments are supported:

* `service_name` - (Required) Service name to create. Only alphanumeric characters, numbers, hyphens (-), and Korean characters are allowed. Min: 3, Max: 30
* `server_name_prefix` - (Required) Server name prefix to create. In order to prevent overlapping host names, random text is added. It must only contain English letters (lowercase), numbers, and hyphens (-). It must start with an English letter and end with an English letter or a number. Min: 3, Max: 20
* `database_name` - (Required) Database name to create. Only English alphabets, numbers and special characters ( \ _ , - ) are allowed and must start with an English alphabet. Min: 1, Max: 30
* `user_name` - (Required) PostgreSQL User ID. Only English alphabets, numbers and special characters ( \ _ , - ) are allowed and must start with an English alphabet. Cannot include User ID. Min: 4, Max: 16
* `user_password` - (Required) PostgreSQL User Password. At least one English alphabet, number and special character must be included. Certain special characters ( ` & + \ " ' / space ) cannot be used. Min: 8, Max: 20
* `vpc_no` - (Required) The ID of the associated Vpc.
* `subnet_no` - (Required) The ID of the associated Subnet.
* `client_cidr` - (Required) Access Control (CIDR) of the client you want to connect to EX) Allow all access: 0.0.0.0/0, Allow specific IP access: 192.168.1.1/32, Allow IP band access: 192.168.1.0/24
* `database_name` - (Required) Database name to create. Only English alphabets, numbers and special characters ( \ _ , - ) are allowed and must start with an English alphabet. Min: 1, Max: 30
* `image_product_code` - (Optional) Image product code to determine the PostgreSQL instance server image specification to create. If not entered, the instance is created for default value. It can be obtained through [`ncloud_postgresql_image_products` data source](../data-sources/postgresql_image_products.md)
* `product_code` - (Optional) Product code to determine the PostgreSQL instance server image specification to create. It can be obtained through [`ncloud_postgresql_products` data source](../data-sources/postgresql_products.md). Default: Minimum specifications(1 memory, 2 cpu)
* `engine_version_code` - (Optional) Postgresql engine version code. If not entered, generate with the default version currently available.
* `engine_version_code` - (Optional) Postgresql engine version code. If not entered, generate with the default version currently available.
* `data_storage_type_code` - (Optional) Data storage type. You can select `SSD|HDD`. Default: SSD
* `is_ha` - (Optional) High-availability (true/false). If high availability is selected, 2 servers including a Secondary server are generated, and additional fees are incurred. If the high availability status `is_ha` is false, `is_multi_zone` and `secondary_subnet_no` parameters are not used. Default: true.
* `is_multi_zone` - (Optional) Multi-zone (true/false). If the high availability status `is_ha` is true, multi-zone can be selected. If multi-zone is selected, Primary server and Secondary server are generated in mutually different zones, providing higher availability. Default: false
* `is_storage_encryption` - (Optional) Whether data storage encryption is applied. If encryption is applied, DB data is encrypted and stored in storage. After Cloud DB for PostgreSQL instance is generated, storage encryption setting cannot be changed. Not available in Neurocloud environment.
* `is_backup` - (Optional) Backup status. If the high availability status `is_ha` is true then the backup setting status is fixed as true. Default: false
* `backup_time` - (Optional, Required if `is_backup` is true and `is_automatic_backup` is false) You can set the time when backup is performed. It must be entered if backup status(is_backup) is true and automatic backup status(is_automatic_backup) is false. EX) 01:15
* `backup_file_retention_period` - (Optional) Backups are performed on a daily basis, and backup files are stored in a separate backup storage. Charges are based on the storage space used. Default: 1 (1 day)
* `storage_encryption` - (Optional) Whether data storage encryption is applied. If encryption is applied, DB data is encrypted and stored in storage. After Cloud DB for PostgreSQL instance is generated, storage encryption setting cannot be changed. Not available in Neurocloud and `gov` site.
* `ha` - (Optional) High-availability (true/false). If high availability is selected, 2 servers including a Secondary server are generated, and additional fees are incurred. If the high availability status `ha` is false, `multi_zone` and `secondary_subnet_no` parameters are not used. Default: true.
* `multi_zone` - (Optional) Multi-zone (true/false). If the high availability status `ha` is true, multi-zone can be selected. If multi-zone is selected, Primary server and Secondary server are generated in mutually different zones, providing higher availability. Not available in Neurocloud and `gov` site. Default: false
* `secondary_subnet_no` - (Optional, Required if `multi_zone` is true) `secondary_subnet_no` must be different from the Primary server's subnet and zone. And must be the same Public or Private. You can get it through the `getCloudPostgresqlTargetSubnetList` action. Not available in Neurocloud and `gov` site.
* `backup` - (Optional) Backup status (true/false). If the high availability status `ha` is true then the backup setting status is fixed as true. Default: true
* `backup_file_retention_period` - (Optional) Backups are performed on a daily basis, and backup files are stored in a separate backup storage. Charges are based on the storage space used. Default: 1 (1 day). Min: 1, Max: 30
* `backup_time` - (Optional, Required if `backup` is true and `automatic_backup` is false) You can set the time when backup is performed. It must be entered if backup status(backup) is true and automatic backup status(automatic_backup) is false. EX) 01:15
* `backup_file_storage_count` - (Optional) Number of backup files kept. Min: 1, Max: 30
* `is_backup_file_compression` - (Optional) Whether to compress backup files. Default: true
* `is_automatic_backup` - (Optional) Select wheter to have backup times set automatically. If `is_automatic_backup` is true, `backup_time` cannot be entered. Default: true
* `backup_file_compression` - (Optional) Whether to compress backup files (true/false). Default: true
* `automatic_backup` - (Optional) Select wheter to have backup times set automatically (true/false). If `automatic_backup` is true, `backup_time` cannot be entered. Default: true
* `port` - (Optional) TCP port to access the Cloud DB for PostgreSQL instance. Default: 5432, Min: 10000, Max: 20000
* `secondary_subnet_no` - (Optional, Required if `is_multi_zone` is true) `secondary_subnet_no` must be different from the Primary server's subnet and zone. And must be the same Public or Private. You can get it through the `getCloudPostgresqlTargetSubnetList` action.

## Attributes Reference

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

* `id` - PostgreSQL Instance Number.
* `region_code` - Region code.
* `vpc_no` - The ID of the associated Vpc.
* `generation_code` - The generation code of the image.
* `access_control_group_no_list` - The ID list of the associated Access Control Group.
* `postgresql_config_list` - The list of config.
* `postgresql_server_list` - The list of the PostgreSQL server.
* `server_instance_no` - Server instance number.
* `server_name` - Server name.
* `server_role` - Server role code. M(Primary), H(Secondary), S(Read Replica)
* `zone_code` - Zone code.
* `product_code` - Product code.
* `is_public_subnet` - Public subnet status.
* `zone_code` - Zone code.
* `subnet_no` - Number of the associated Subnet.
* `public_subnet` - Public subnet status. (`true` or `false`)
* `public_domain` - Public domain.
* `private_domain` - Private domain.
* `private_ip` - Private IP.
* `memory_size` - Available memory size.
* `cpu_count` - CPU count.
* `data_storage_size` - Storage size.
* `used_data_storage_size` - Size of data storage in use.
* `cpu_count` - CPU count.
* `memory_size` - Available memory size.
* `uptime` - Running start time.
* `create_date` - Server create date.

Expand All @@ -103,4 +111,4 @@ import {
to = ncloud_postgresql.rsc_name
id = "12345"
}
```
```
48 changes: 22 additions & 26 deletions docs/resources/postgresql_databases.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,48 +11,49 @@ Provides a PostgreSQL Database list resource.
## Example Usage

```terraform
resource "ncloud_vpc" "test" {
resource "ncloud_vpc" "vpc" {
ipv4_cidr_block = "10.0.0.0/16"
}

resource "ncloud_subnet" "test" {
vpc_no = ncloud_vpc.test.vpc_no
subnet = cidrsubnet(ncloud_vpc.test.ipv4_cidr_block, 8, 1)
resource "ncloud_subnet" "subnet" {
vpc_no = ncloud_vpc.vpc.vpc_no
subnet = cidrsubnet(ncloud_vpc.vpc.ipv4_cidr_block, 8, 1)
zone = "KR-2"
network_acl_no = ncloud_vpc.test.default_network_acl_no
network_acl_no = ncloud_vpc.vpc.default_network_acl_no
subnet_type = "PUBLIC"
}

resource "ncloud_postgresql" "postgresql" {
subnet_no = ncloud_subnet.test.id
service_name = "tf-postgresql"
vpc_no = ncloud_vpc.vpc.vpc_no
subnet_no = ncloud_subnet.subnet.id
service_name = "tf-postgresql"
server_name_prefix = "name-prefix"
user_name = "username"
user_password = "password1!"
client_cidr = "0.0.0.0/0"
database_name = "db_name"
user_name = "username"
user_password = "password1!"
client_cidr = "0.0.0.0/0"
database_name = "db_name"
}

resource "ncloud_postgresql_users" "postgresql_users" {
postgresql_instance_no = ncloud_postgresql.postgresql.postgresql_instance_no
id = ncloud_postgresql.postgresql.id
postgresql_user_list = [
{
name = "test1",
password = "t123456789!",
client_cidr = "0.0.0.0/0",
is_replication_role = "false"
replication_role = "false"
},
{
name = "test2",
password = "t123456789!",
client_cidr = "0.0.0.0/0",
is_replication_role = "false"
replication_role = "false"
}
]
}

resource "ncloud_postgresql_databases" "postgresql_databases" {
postgresql_instance_no = ncloud_postgresql.postgresql.postgresql_instance_no
id = ncloud_postgresql.postgresql.id
postgresql_database_list = [
{
name = "testdb1",
Expand All @@ -69,33 +70,28 @@ resource "ncloud_postgresql_databases" "postgresql_databases" {
## Argument Reference
The following arguments are supported:

* `postgresql_instance_no` - (Required) The ID of the associated Postgresql Instance.
* `id` - (Required) The ID of the associated Postgresql Instance.
* `postgresql_database_list` - The list of databases to add.
* `name` - (Required) Database name to create. Only English alphabets, numbers and special characters ( \ _ , - ) are allowed and must start with an English alphabet. Min: 1, Max: 30
* `owner` - (Required) User ID to manage the database.

## Attribute Reference
In addition to all arguments above, the following attributes are exported

* `id` - Postgresql Database List number.(Postgresql Instance number)

## Import

### `terraform import` command

* PostgreSQL Database can be imported using the `id`. For example:
* PostgreSQL Database can be imported using the `id`:`name`:`name`:... . For example:

```console
$ terraform import ncloud_postgresql_databases.rsc_name 12345
$ terraform import ncloud_postgresql_databases.rsc_name 12345:name1:name2
```

### `import` block

* In Terraform v1.5.0 and later, use an [`import` block](https://developer.hashicorp.com/terraform/language/import) to import PostgreSQL Database using the `id`. For example:
* In Terraform v1.5.0 and later, use an [`import` block](https://developer.hashicorp.com/terraform/language/import) to import PostgreSQL Database using the `id`:`name`:`name`:... . For example:

```terraform
import {
to = ncloud_postgresql_databases.rsc_name
id = "12345"
id = "12345:name1:name2"
}
```
```
Loading