- Create a Managed MySQL cluster with predefined number of DB hosts
- Create a list of users and databases with permissions
- Easy to use in other resources via outputs
At first you need to create VPC network with three subnets!
MySQL module requires a following input variables:
- VPC network id
- VPC network subnets ids
- MySQL hosts definitions - a list of maps with DB host name, zone name and subnet id.
- Databases - a list of databases with database name
- Users - a list users with a list of grants to databases.
Notes:
users
variable defines a list of separate db users with apermissions
list, which indicates to a list of databases and grants for each of them. Default grant is the "ALL_PRIVILEGES". The user may also haveglobal_permissions
without any database permissions.- Database
mysql_config
parameter might be null, in this case default values will be used.
See examples section
- Install YC CLI
- Add environment variables for terraform auth in Yandex.Cloud
export YC_TOKEN=$(yc iam create-token)
export YC_CLOUD_ID=$(yc config get cloud-id)
export YC_FOLDER_ID=$(yc config get folder-id)
export TF_VAR_network_id=_vpc id here_
Name | Version |
---|---|
terraform | >= 1.0.0 |
random | > 3.3 |
yandex | > 0.8 |
Name | Version |
---|---|
random | 3.5.1 |
yandex | 0.89.0 |
No modules.
Name | Type |
---|---|
random_password.password | resource |
yandex_mdb_mysql_cluster.this | resource |
yandex_mdb_mysql_database.database | resource |
yandex_mdb_mysql_user.user | resource |
yandex_client_config.client | data source |
Name | Description | Type | Default | Required |
---|---|---|---|---|
access_policy | Access policy from other services to the MySQL cluster. | object({ |
{} |
no |
backup_retain_period_days | (Optional) The period in days during which backups are stored. | number |
null |
no |
backup_window_start | (Optional) Time to start the daily backup, in the UTC timezone. | object({ |
null |
no |
databases | A list of MySQL databases. Required values: - name - The name of the database. |
list(object({ |
[] |
no |
deletion_protection | Inhibits deletion of the cluster. | bool |
false |
no |
description | MySQL cluster description | string |
"Managed MySQL cluster" |
no |
disk_size | Disk size for hosts | number |
20 |
no |
disk_type | Disk type for hosts | string |
"network-ssd" |
no |
environment | Environment type: PRODUCTION or PRESTABLE | string |
"PRODUCTION" |
no |
folder_id | Folder id that contains the MySQL cluster | string |
null |
no |
hosts_definition | A list of MySQL hosts. | list(object({ |
[] |
no |
labels | A set of label pairs to assing to the MySQL cluster. | map(any) |
{} |
no |
maintenance_window | (Optional) Maintenance policy of the MySQL cluster. - type - (Required) Type of maintenance window. Can be either ANYTIME or WEEKLY. A day and hour of window need to be specified with weekly window. - day - (Optional) Day of the week (in DDD format). Allowed values: "MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN" - hour - (Optional) Hour of the day in UTC (in HH format). Allowed value is between 0 and 23. |
object({ |
{ |
no |
mysql_config | A map of MySQL cluster configuration. Details info in a 'MySQL cluster settings' of official documentation. Link: https://registry.terraform.io/providers/yandex-cloud/yandex/latest/docs/resources/mdb_mysql_cluster#mysql-config |
map(any) |
null |
no |
mysql_version | MySQL version | string |
"8.0" |
no |
name | Name of MySQL cluster | string |
"mysql-cluster" |
no |
network_id | MySQL cluster network id | string |
n/a | yes |
performance_diagnostics | (Optional) MySQL cluster performance diagnostics settings. | object({ |
{} |
no |
resource_preset_id | Preset for hosts | string |
"s2.micro" |
no |
restore_parameters | The cluster will be created from the specified backup. NOTES: - backup_id must be specified to create a new MySQL cluster from a backup. - Time format is 'yyyy-mm-ddThh:mi:ss', where T is a delimeter, e.g. "2022-02-22T11:33:44". |
object({ |
null |
no |
security_groups_ids_list | A list of security group IDs to which the MySQL cluster belongs | list(string) |
[] |
no |
users | This is a list for additional MySQL users with own permissions. Required values: - name - The name of the user. - password - (Optional) The user's password. If it's omitted a random password will be generated - authentication_plugin - (Optional) User authn method. The default value could be set via the 'mysql_config.default_authentication_plugin' variable. - global_permissions - (Optional) A list of the user's global_permissions. Default empty. - connection_limits - (Optional) The object with user connection limits { max_questions_per_hour, max_updates_per_hour, max_connections_per_hour, max_user_connections }. Default unlimited. - permissions - (Optional) A list of objects { databases_name, grants[] } for an access. 'roles' is a optional list of permissions, the default values is ["ALL"] |
list(object({ |
[] |
no |
Name | Description |
---|---|
cluster_fqdns_list | MySQL cluster nodes FQDN list |
cluster_host_names_list | MySQL cluster host name |
cluster_id | MySQL cluster ID |
cluster_name | MySQL cluster name |
connection_step_1 | 1 step - Install certificate |
connection_step_2 | How connect to MySQL cluster? 1. Install certificate mkdir --parents ~/.mysql && \ curl -fsL 'https://storage.yandexcloud.net/cloud-certs/CA.pem' -o ~/.mysql/root.crt && \ chmod 0600 ~/.mysql/root.crt 2. Run connection string from the output value, for example mysql --host=rc1a-ud9hj90vwqkw05js.mdb.yandexcloud.net \ --port=3306 \ --ssl-ca=~/.mysql/root.crt \ --ssl-mode=VERIFY_IDENTITY \ --user=test1-owner \ --password \ test1 |
databases | A list of databases names. |
users_data | A list of users with passwords. |