Skip to content

Terraform module to manage a MySQL cluster resources within the Yandex.Cloud.

License

Notifications You must be signed in to change notification settings

terraform-yacloud-modules/terraform-yandex-mdb-mysql

Repository files navigation

Yandex Cloud MySQL Terraform module

Terraform module which creates Yandex Cloud Managed Service for MySQL resources.

Example

# Full example
module "mysql" {
  source           = "../../modules/mysql"
  network_id       = module.vpc.vpc_id
  ha               = true
  count_ha         = 3
  subnet_zones     = module.vpc.private_zones
  subnet_id        = module.vpc.private_subnets_id
  assign_public_ip = false
  name             = "cluster-mysql"
  environment      = "PRESTABLE"
  version_sql      = "8.0"

  resource_preset_id = "b1.medium"
  disk_type_id       = "network-ssd"
  disk_size          = 10

  labels = {
    created_by = "terraform_mysql_module"
  }

  attach_security_group_ids = [module.sg_private.id]

  deletion_protection = false

  mysql_config = {
    sql_mode                      = "ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION"
    max_connections               = 100
    default_authentication_plugin = "MYSQL_NATIVE_PASSWORD"
    innodb_print_all_deadlocks    = true
  }

  maintenance_window = {
    type = "ANYTIME"
  }

  backup_window_start = {
    hours   = 23
    minutes = 59
  }

  access = {
    web_sql = true
  }

  performance_diagnostics = {
    enabled                      = true
    sessions_sampling_interval   = 30
    statements_sampling_interval = 90
  }

}

# Minimal example
module "mysql" {
  source           = "../../modules/mysql"
  network_id       = module.vpc.vpc_id
  subnet_zones     = module.vpc.private_zones
  name             = "cluster-mysql"
}

Requirements

Name Version
terraform >= 1.5.0
yandex >= 0.110, < 1.0

Providers

Name Version
yandex >= 0.110, < 1.0

Modules

No modules.

Resources

Name Type
yandex_mdb_mysql_cluster.mysql resource
yandex_vpc_security_group.mysql resource
yandex_client_config.client data source

Inputs

Name Description Type Default Required
access (Optional) The access block support. If not specified then does not make any changes.
data_lens - (Optional) Allow access for Yandex DataLens.
web_sql - (Optional) Allows access for SQL queries in the management console.
data_transfer - (Optional) Allow access for DataTransfer
access = {
web_sql = true
}
object({
data_lens = optional(bool)
web_sql = optional(bool)
data_transfer = optional(bool)
})
null no
allow_ingress_v4_cidr_blocks (Optional) The allowed list of addresses for accessing the database on port 3306. Default [ "0.0.0.0"/0 ] list(string)
[
"0.0.0.0/0"
]
no
assign_public_ip (Optional) Sets whether the host should get a public IP address. It can be changed on the fly only when name is set. bool false no
attach_security_group_ids (Optional) Attach an additional security group. list(string) null 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.
object({
hours = optional(number)
minutes = optional(number)
})
null no
count_ha (Optional) Number of hosts in a high availability cluster number 3 no
deletion_protection (Optional) Protection against cluster deletion bool false no
description (Optional) Description of the MySQL cluster. string "terraform-created" no
disk_size (Optional) Volume of the storage available to a MySQL host, in gigabytes. Default '10'. https://yandex.cloud/ru/docs/managed-mysql/concepts/limits number 10 no
disk_type_id (Optional) Type of the storage of MySQL hosts. Default 'network-ssd' string "network-ssd" no
environment (Optional) Deployment environment of the MySQL cluster string "PRODUCTION" no
folder_id https://cloud.yandex.ru/docs/resource-manager/operations/folder/get-id string null no
ha (Optional) High availability cluster? bool false no
labels (Optional) Set of key/value label pairs to assign. map(string)
{
"created_by": "terraform_mysql_module"
}
no
maintenance_window (Optional) Time to start the daily backup, in the UTC.
object({
type = optional(string)
day = optional(string)
hour = optional(number)
})
{
"day": null,
"hour": null,
"type": "ANYTIME"
}
no
mysql_config (Optional) MySQL cluster config. Detail info in https://terraform-provider.yandexcloud.net/Resources/mdb_mysql_cluster.html#mysql-config
object({
sql_mode = optional(string)
max_connections = optional(number)
default_authentication_plugin = optional(string)
innodb_print_all_deadlocks = optional(bool)
})
null no
name (Required) Name of the MySQL cluster. Provided by the client when the cluster is created. string "cluster-mysql" no
network_id (Required) ID of the network, to which the MySQL cluster belongs. string n/a yes
performance_diagnostics (Optional) The performance_diagnostics block supports.
enabled - Enable performance diagnostics
sessions_sampling_interval - Interval (in seconds) for my_stat_activity sampling Acceptable values are 1 to 86400, inclusive.
statements_sampling_interval - Interval (in seconds) for my_stat_statements sampling Acceptable values are 1 to 86400, inclusive.

performance_diagnostics = {
enabled = true
sessions_sampling_interval = 30
statements_sampling_interval = 90
}
object({
enabled = optional(bool)
sessions_sampling_interval = optional(number)
statements_sampling_interval = optional(number)
})
null no
resource_preset_id (Optional) The ID of the preset for computational resources available to a MySQL host. Default 's1.micro' string "s1.micro" no
restore (Optional) Time to start the daily backup, in the UTC. The structure is documented below.
backup_id - (Required, ForceNew) Backup ID. The cluster will be created from the specified backup.
time - (Optional, ForceNew) Timestamp of the moment to which the MySQL cluster should be restored. (Format: "2006-01-02T15:04:05" - UTC). When not set, current time is used.
restore = {
backup_id = "c9qj2tns23432471d9qha:stream_20210122T141717Z"
time = "2021-01-23T15:04:05"
}
object({
backup_id = string
time = optional(string)
})
null no
subnet_id (Optional) The ID of the subnets, to which the host belongs. The subnet must be a part of the network to which the cluster belongs. list(string) null no
subnet_zones (Optional) Zones name of the network, to which the MySQL cluster belongs. list(string)
[
"ru-central1-a"
]
no
version_sql (Optional) Version of the MySQL cluster. Default '8.0' string "8.0" no

Outputs

Name Description
db_info Full information about the cluster
hosts_fqdn List of server FQDN
hosts_name List of server names
id cluster ID
name cluster name