Skip to content

Commit

Permalink
fix(mysql): Fix import error and minor errors on recovery and slave (#…
Browse files Browse the repository at this point in the history
…489)

* refactor(mysql): Update Mysql resource and data source

* fix(mysql_recovery): Fix import and minor errors

* fix(mysql_slave): Fix import and minor errors
  • Loading branch information
youngmn authored Dec 10, 2024
1 parent c30502e commit 9936d69
Show file tree
Hide file tree
Showing 9 changed files with 535 additions and 365 deletions.
74 changes: 45 additions & 29 deletions docs/resources/mysql_recovery.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,39 +6,39 @@ subcategory: "MySQL"

Provides a MySQL recovery resource.

~> **NOTE:** This resource only supports VPC environment.
~> **NOTE:** This resource only supports VPC environment. Only one server related resource (ncloud_mysql_slave, ncloud_mysql_recovery) can be created or deleted at a time.

## Example Usage

```terraform
resource "ncloud_vpc" "test_vpc" {
name = "%[1]s"
ipv4_cidr_block = "10.5.0.0/16"
resource "ncloud_vpc" "vpc" {
name = "mysql-vpc"
ipv4_cidr_block = "10.5.0.0/16"
}
resource "ncloud_subnet" "test_subnet" {
vpc_no = ncloud_vpc.test_vpc.vpc_no
name = "%[1]s"
subnet = "10.5.0.0/24"
zone = "KR-2"
network_acl_no = ncloud_vpc.test_vpc.default_network_acl_no
subnet_type = "PUBLIC"
resource "ncloud_subnet" "subnet" {
vpc_no = ncloud_vpc.vpc.vpc_no
name = "mysql-subnet"
subnet = "10.5.0.0/24"
zone = "KR-2"
network_acl_no = ncloud_vpc.vpc.default_network_acl_no
subnet_type = "PUBLIC"
}
resource "ncloud_mysql" "mysql" {
subnet_no = data.ncloud_subnet.test_subnet.id
service_name = "%[1]s"
server_name_prefix = "testprefix"
user_name = "testusername"
user_password = "t123456789!a"
host_ip = "192.168.0.1"
database_name = "test_db"
subnet_no = data.ncloud_subnet.subnet.id
service_name = "tf-mysql"
server_name_prefix = "testprefix"
user_name = "testusername"
user_password = "t123456789!a"
host_ip = "192.168.0.1"
database_name = "test_db"
}
resource "ncloud_mysql_recovery" "mysql_recovery" {
mysql_instance_no = ncloud_mysql.mysql.id
recovery_server_name = "test-recovery"
file_name = "20210722"
mysql_instance_no = ncloud_mysql.mysql.id
recovery_server_name = "test-recovery"
file_name = "20210722"
}
```

Expand All @@ -47,33 +47,49 @@ resource "ncloud_mysql_recovery" "mysql_recovery" {
The following arguments are supported:

* `mysql_instance_no` - (Required) the ID of the associated Mysql Instance.
* `subnet_no` - (Optional, Required if `is_multi_zone` of MySQL Instance is true) The ID of the associate Subnet.
* `recovery_server_name` (Required) Recovery server name to create. In order to prevent overlapping host names, random text is added. Can comprise only lower-case English alphabets, numbers and dash ( - ). The first letter must be an English alphabet and the last letter must be an English alphabet or a number. Min: 3, Max: 25
* `file_name` - (Optional, One of `file_name` and `recovery_time` is required) The name of backup file. If you enter `file_name`, ignore the entry of `recovery_time`.
* `recovery_time` - (Optional, One of `file_name` and `recovery_time` is required) The time of recovery. If you enter `recovery_time`, ignore the entry of `file_name`.
* `subnet_no` - (Optional, Required if `is_multi_zone` of MySQL Instance is true) The ID of the associate Subnet. Not available in Neurocloud and `gov` site.
* `file_name` - (Optional, One of `file_name` and `recovery_time` is required) The name of backup file.
* `recovery_time` - (Optional, One of `file_name` and `recovery_time` is required) The time of recovery.

## Attribute Reference

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

* `id` - MySQL Recovery Server Instance Number.
* `mysql_server_list` - The list of the MySQL server.
* `server_instance_no` - Server instance number.
* `server_name` - Server name.
* `server_role` - Server role code. ex) M(Master), H(Standby Master)
* `zone_code` - Zone code.
* `subnet_no` - The ID of the associated Subnet.
* `product_code` - Product code.
* `is_public_subnet` - Public subnet status.
* `private_domain` - Private domain.
* `public_domain` - Public domain.
* `memory_size` - Available memory size.
* `cpu_count` - CPU count.
* `data_storage_size` - Storage size.
* `used_data_storage_size` - Size of data storage in use.
* `uptime` - Running start time.
* `create_date` - Server create date.

# Import

### `terraform import` command

* MySQL Recovery can be imported using the `id`. For example:
* MySQL Recovery can be imported using the `mysql_instance_no`:`id`. For example:
```console
$ terraform import ncloud_mysql_recovery.rsc_name 12345
$ terraform import ncloud_mysql_recovery.rsc_name 12345:24678
```

### `import` block

* In terraform v1.5.0 and later, use an [`import` block](https://developer.hashicorp.com/terraform/language/import) to import MySQL Recovery 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 MySQL Recovery using the `mysql_instance_no`:`id`. For example:

```terraform
import {
to = ncloud_mysql_recovery.rsc_name
id = "12345"
id = "12345:24678"
}
```
```
66 changes: 41 additions & 25 deletions docs/resources/mysql_slave.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,37 @@ subcategory: "MySQL"

Provides a MySQL slave resource.

~> **NOTE:** This resource only supports VPC environment.
~> **NOTE:** This resource only supports VPC environment. Only one server related resource (ncloud_mysql_slave, ncloud_mysql_recovery) can be created or deleted at a time.

## Example Usage

```terraform
resource "ncloud_vpc" "test_vpc" {
name = "%[1]s"
ipv4_cidr_block = "10.5.0.0/16"
resource "ncloud_vpc" "vpc" {
name = "mysql-vpc"
ipv4_cidr_block = "10.5.0.0/16"
}
resource "ncloud_subnet" "test_subnet" {
vpc_no = ncloud_vpc.test_vpc.vpc_no
name = "%[1]s"
subnet = "10.5.0.0/24"
zone = "KR-2"
network_acl_no = ncloud_vpc.test_vpc.default_network_acl_no
subnet_type = "PUBLIC"
resource "ncloud_subnet" "subnet" {
vpc_no = ncloud_vpc.vpc.vpc_no
name = "mysql-subnet"
subnet = "10.5.0.0/24"
zone = "KR-2"
network_acl_no = ncloud_vpc.vpc.default_network_acl_no
subnet_type = "PUBLIC"
}
resource "ncloud_mysql" "mysql" {
subnet_no = data.ncloud_subnet.test_subnet.id
service_name = "%[1]s"
server_name_prefix = "testprefix"
user_name = "testusername"
user_password = "t123456789!a"
host_ip = "192.168.0.1"
database_name = "test_db"
subnet_no = data.ncloud_subnet.subnet.id
service_name = "tf-mysql"
server_name_prefix = "testprefix"
user_name = "testusername"
user_password = "t123456789!a"
host_ip = "192.168.0.1"
database_name = "test_db"
}
resource "ncloud_mysql_slave" "mysql_slave" {
mysql_instance_no = ncloud_mysql.mysql.id
mysql_instance_no = ncloud_mysql.mysql.id
}
```

Expand All @@ -45,30 +45,46 @@ resource "ncloud_mysql_slave" "mysql_slave" {
The following arguments are supported:

* `mysql_instance_no` - (Required) the ID of the associated Mysql Instance.
* `subnet_no` - (Optional, Required if `is_multi_zone` of MySQL Instance is true) The ID of the associate Subnet.
* `subnet_no` - (Optional, Required if `is_multi_zone` of MySQL Instance is true) The ID of the associate Subnet. Not available in Neurocloud and `gov` site.

## Attribute Reference

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

* `id` - MySQL Slave Server Instance Number.
* `mysql_server_list` - The list of the MySQL server.
* `server_instance_no` - Server instance number.
* `server_name` - Server name.
* `server_role` - Server role code. ex) M(Master), H(Standby Master)
* `zone_code` - Zone code.
* `subnet_no` - The ID of the associated Subnet.
* `product_code` - Product code.
* `is_public_subnet` - Public subnet status.
* `private_domain` - Private domain.
* `public_domain` - Public domain.
* `memory_size` - Available memory size.
* `cpu_count` - CPU count.
* `data_storage_size` - Storage size.
* `used_data_storage_size` - Size of data storage in use.
* `uptime` - Running start time.
* `create_date` - Server create date.

# Import

### `terraform import` command

* MySQL Slave can be imported using the `id`. For example:
* MySQL Slave can be imported using the `mysql_instance_no`:`id`. For example:
```console
$ terraform import ncloud_mysql_slave.rsc_name 12345
$ terraform import ncloud_mysql_slave.rsc_name 12345:24678
```

### `import` block

* In terraform v1.5.0 and later, use an [`import` block](https://developer.hashicorp.com/terraform/language/import) to import MySQL Slave 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 MySQL Slave using the `mysql_instance_no`:`id`. For example:

```terraform
import {
to = ncloud_mysql_slave.rsc_name
id = "12345"
id = "12345:24678"
}
```
```
Loading

0 comments on commit 9936d69

Please sign in to comment.