Skip to content

Commit

Permalink
feat: Add mysql users service (#444)
Browse files Browse the repository at this point in the history
* feat: add mysql users service

* docs: correct name size

* refactor: remove annotation

* docs: add data source output

* feat: add update and remove reverse

* fix: change check 5001017 func

* chore: remove print
  • Loading branch information
dusdjhyeon authored Sep 27, 2024
1 parent be36e0c commit 82109ad
Show file tree
Hide file tree
Showing 8 changed files with 1,136 additions and 2 deletions.
59 changes: 59 additions & 0 deletions docs/data-sources/mysql_users.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
---
subcategory: "MySQL"
---

# Data Source: ncloud_mysql_users

Get a list of MySQL users.

~> **NOTE:** This only supports VPC environments.

## Example Usage

```terraform
data "ncloud_mysql_users" "all" {
id = 12345
filter {
name = "name"
values = ["test-user1"]
}
output_file = "users.json"
}
output "user_list" {
values = {
for user in data.ncloud_mysql_users.all.mysql_user_list:
user.name => user.host_ip
}
}
```

Outputs:
```terraform
user_list = {
"test-user1": "192.168.0.1"
}
```

## Argument Reference

The following arguments are required:

* `id` - (Required) Mysql Users number. Either `id` or `mysql_instance_no` must be provided.
* `mysql_instance_no` - (Required) Mysql Instance No, either `id` or `mysql_instance_no` must be provided.
* `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
* `vlaues` - (Required) Set of values that are accepted for the given field.
* `regex` - (Optional) is `values` treated as a regular expression.

## Attributes Reference

This data source exports the following attributes in addition to the argument above:

* `mysql_user_list` - The list of users to add .
* `name` - MySQL User ID.
* `password` - MySQL User Password.
* `host_ip` - MySQL user host.
* `authority` - MySQL User Authority.
4 changes: 2 additions & 2 deletions docs/resources/mysql.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ resource "ncloud_mysql" "mysql" {

The following arguments are supported:

* `service_name` - (Required) Service name to create. Only English alphabets, numbers, dash ( - ) and Korean letters can be entered. Min: 3, Max: 20
* `server_name_prefix` - (Required) Server name prefix 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: 30
* `service_name` - (Required) Service name to create. Only English alphabets, numbers, dash ( - ) and Korean letters can be entered. Min: 3, Max: 30
* `server_name_prefix` - (Required) Server name prefix 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: 20
* `user_name` - (Required) MySQL User ID. Only English alphabets, numbers and special characters ( \ _ , - ) are allowed and must start with an English alphabet. Min: 4, Max: 16
* `user_password` - (Required) MySQL 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
* `host_ip` - (Required) MySQL user host. ex) Overall connection permitted: %, Connection by specific IPs permitted: 1.1.1.1, IP band connection permitted: 1.1.1.%
Expand Down
89 changes: 89 additions & 0 deletions docs/resources/mysql_users.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
---
subcategory: "MySQL"
---

# Resource: ncloud_mysql_users

Provides a MySQL User list resource.

~> **NOTE:** This resource only supports VPC environment.

## Example Usage

```terraform
resource "ncloud_vpc" "test_vpc" {
ipv4_cidr_block = "10.5.0.0/16"
}
resource "ncloud_subnet" "test_subnet" {
vpc_no = ncloud_vpc.test_vpc.vpc_no
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_mysql" "mysql" {
subnet_no = ncloud_subnet.test_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_users" "mysql_users" {
mysql_instance_no = ncloud_mysql.mysql.id
mysql_user_list = [
{
name = "test1",
password = "t123456789!",
host_ip = "%%",
authority = "READ"
},
{
name = "test2",
password = "t123456789!",
host_ip = "%%",
authority = "DDL"
}
]
}
```

## Argument Reference
The following arguments are supported:

* `mysql_instance_no` - (Required) The ID of the associated Mysql Instance.
* `mysql_user_list` - The list of users to add .
* `name` - (Required) MySQL User ID. Only English alphabets, numbers and special characters ( \ _ , - ) are allowed and must start with an English alphabet. Min: 4, Max: 16
* `password` - (Required) MySQL 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
* `host_ip` - (Required) MySQL user host. ex) Overall connection permitted: %, Connection by specific IPs permitted: 1.1.1.1, IP band connection permitted: 1.1.1.%
* `authority` - (Required) MySQL User Authority. You can select `READ|CRUD|DDL`.

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

* `id` - Mysql User List number.(Mysql Instance number)

## Import

### `terraform import` command

* MySQL User can be imported using the `id`. For example:

```console
$ terraform import ncloud_mysql_users.rsc_name 12345
```

### `import` block

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

```terraform
import {
to = ncloud_mysql_users.rsc_name
id = "12345"
}
```
2 changes: 2 additions & 0 deletions internal/provider/fwprovider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ func (p *fwprovider) DataSources(ctx context.Context) []func() datasource.DataSo
dataSources = append(dataSources, mysql.NewMysqlDataSource)
dataSources = append(dataSources, mysql.NewMysqlImageProductsDataSource)
dataSources = append(dataSources, mysql.NewMysqlProductsDataSource)
dataSources = append(dataSources, mysql.NewMysqlUsersDataSource)
dataSources = append(dataSources, mongodb.NewMongoDbDataSource)
dataSources = append(dataSources, mongodb.NewMongoDbProductsDataSource)
dataSources = append(dataSources, mongodb.NewMongoDbImageProductsDataSource)
Expand Down Expand Up @@ -124,6 +125,7 @@ func (p *fwprovider) Resources(ctx context.Context) []func() resource.Resource {
resources = append(resources, server.NewLoginKeyResource)
resources = append(resources, server.NewInitScriptResource)
resources = append(resources, mysql.NewMysqlResource)
resources = append(resources, mysql.NewMysqlUsersResource)
resources = append(resources, mysql.NewMysqlRecoveryResource)
resources = append(resources, mysql.NewMysqlSlaveResource)
resources = append(resources, mongodb.NewMongoDbResource)
Expand Down
Loading

0 comments on commit 82109ad

Please sign in to comment.