-
Notifications
You must be signed in to change notification settings - Fork 0
/
data-migration-mysql-mmy.tf
135 lines (123 loc) · 4.35 KB
/
data-migration-mysql-mmy.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# Infrastructure for Yandex Cloud Managed Service for MySQL cluster and Virtual Machine.
#
# RU: https://cloud.yandex.ru/docs/managed-mysql/tutorials/data-migration
# EN: https://cloud.yandex.com/en/docs/managed-mysql/tutorials/data-migration
#
# Set the following settings:
locals {
zone_a_v4_cidr_blocks = "10.1.0.0/24" # Set the CIDR block for subnet in the ru-central1-a availability zone.
# Managed Service for MySQL cluster.
target_mysql_version = "" # Set the MySQL version. It must be the same or higher than the version in the source cluster.
target_sql_mode = "" # Set the MySQL SQL mode. It must be the same as in the source cluster.
target_db_name = "" # Set the target cluster database name.
target_user = "" # Set the target cluster username.
target_password = "" # Set the target cluster password.
# (Optional) Virtual Machine.
vm_image_id = "" # Set a public image ID from https://cloud.yandex.com/en/docs/compute/operations/images-with-pre-installed-software/get-list.
vm_username = "" # Set a username for VM. Images with Ubuntu Linux use the username `ubuntu` by default.
vm_public_key = "" # Set a full path to SSH public key.
}
resource "yandex_vpc_network" "network" {
description = "Network for the Managed Service for MySQL cluster and VM"
name = "network"
}
resource "yandex_vpc_subnet" "subnet-a" {
description = "Subnet in the ru-central1-a availability zone"
name = "subnet-a"
zone = "ru-central1-a"
network_id = yandex_vpc_network.network.id
v4_cidr_blocks = [local.zone_a_v4_cidr_blocks]
}
resource "yandex_vpc_security_group" "security-group-mysql" {
description = "Security group for the Managed Service for MySQL cluster"
network_id = yandex_vpc_network.network.id
ingress {
description = "Allow connections to the cluster from the Internet"
protocol = "TCP"
port = 3306
v4_cidr_blocks = ["0.0.0.0/0"]
}
}
# If you use VM for connection to the cluster, uncomment these lines.
#resource "yandex_vpc_security_group" "security-group-vm" {
# description = "Security group for VM"
# network_id = yandex_vpc_network.network.id
#
# ingress {
# description = "Allow SSH connections for VM from the Internet"
# protocol = "TCP"
# port = 22
# v4_cidr_blocks = ["0.0.0.0/0"]
# }
#
# egress {
# description = "Allow outgoing connections to any required resource"
# protocol = "ANY"
# from_port = 0
# to_port = 65535
# v4_cidr_blocks = ["0.0.0.0/0"]
# }
#}
resource "yandex_mdb_mysql_cluster" "mysql-cluster" {
description = "Managed Service for MySQL cluster"
name = "mysql-cluster"
environment = "PRODUCTION"
network_id = yandex_vpc_network.network.id
version = local.target_mysql_version
security_group_ids = [yandex_vpc_security_group.security-group-mysql.id]
resources {
resource_preset_id = "s2.micro" # 2 vCPU, 8 GB RAM
disk_type_id = "network-hdd"
disk_size = 10 # GB
}
mysql_config = {
sql_mode = local.target_sql_mode
}
host {
zone = "ru-central1-a"
subnet_id = yandex_vpc_subnet.subnet-a.id
assign_public_ip = true # Required for connection from the Internet. For a method without intermediate VM.
}
database {
name = local.target_db_name
}
user {
name = local.target_user
password = local.target_password
permission {
database_name = local.target_db_name
roles = ["ALL"]
}
}
}
# If you use VM for connection to the cluster, uncomment these lines.
#resource "yandex_compute_instance" "vm-linux" {
# description = "Virtual Machine in Yandex Compute Cloud"
# name = "vm-linux"
# platform_id = "standard-v3" # Intel Ice Lake
#
# resources {
# cores = 2
# memory = 2 # GB
# }
#
# boot_disk {
# initialize_params {
# image_id = local.vm_image_id
# }
# }
#
# network_interface {
# subnet_id = yandex_vpc_subnet.subnet-a.id
# nat = true # Required for connection from the Internet.
#
# security_group_ids = [
# yandex_vpc_security_group.security-group-mysql.id,
# yandex_vpc_security_group.security-group-vm.id
# ]
# }
#
# metadata = {
# ssh-keys = "local.vm_username:${file(local.vm_public_key)}" # Username and SSH public key full path.
# }
#}