-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathredis-cluster-sharded-and-vm-for-php.tf
More file actions
165 lines (137 loc) · 5.29 KB
/
redis-cluster-sharded-and-vm-for-php.tf
File metadata and controls
165 lines (137 loc) · 5.29 KB
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# Infrastructure for sharded Yandex Managed Service for Valkey™ cluster and Virtual Machine in Yandex Compute Cloud
#
# RU: https://cloud.yandex.ru/docs/managed-valkey/tutorials/valkey-as-php-sessions-storage
# EN: https://cloud.yandex.com/en/docs/managed-valkey/tutorials/valkey-as-php-sessions-storage
#
# Set the following settings:
locals {
# The following settings are to be specified by the user. Change them as you wish.
# Settings for the Yandex Managed Service for Valkey™ cluster
password = "" # Password for the Yandex Managed Service for Valkey™ cluster
# Settings for the VM in Compute Cloud
image_id = "" # Public image ID for the VM in Compute Cloud. See: https://cloud.yandex.com/en/docs/compute/operations/images-with-pre-installed-software/get-list.
vm_username = "" # Username to connect to the VM in Compute Cloud via SSH. For Ubuntu images `ubuntu` username is used by default.
vm_ssh_key_path = "" # Full path to the SSH public key for the VM in Compute Cloud. Example: "~/.ssh/key.pub".
# The following settings are predefined. Change them only if necessary.
# Settings for the Network infrastructure
zone_a_v4_cidr_blocks = "10.1.0.0/16" # CIDR block for the subnet in the ru-central1-a availability zone
zone_b_v4_cidr_blocks = "10.2.0.0/16" # CIDR block for the subnet in the ru-central1-b availability zone
zone_d_v4_cidr_blocks = "10.3.0.0/16" # CIDR block for the subnet in the ru-central1-d availability zone
# Settings for the Yandex Managed Service for Valkey™ cluster
version = "7.2-valkey" # Version of the Yandex Managed Service for Valkey™
}
resource "yandex_vpc_network" "redis-and-vm-network" {
description = "Network for the Yandex Managed Service for Valkey cluster and VM in Compute Cloud"
name = "redis-and-vm-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.redis-and-vm-network.id
v4_cidr_blocks = [local.zone_a_v4_cidr_blocks]
}
resource "yandex_vpc_subnet" "subnet-b" {
description = "Subnet in the ru-central1-b availability zone"
name = "subnet-b"
zone = "ru-central1-b"
network_id = yandex_vpc_network.redis-and-vm-network.id
v4_cidr_blocks = [local.zone_b_v4_cidr_blocks]
}
resource "yandex_vpc_subnet" "subnet-d" {
description = "Subnet in the ru-central1-d availability zone"
name = "subnet-d"
zone = "ru-central1-d"
network_id = yandex_vpc_network.redis-and-vm-network.id
v4_cidr_blocks = [local.zone_d_v4_cidr_blocks]
}
resource "yandex_vpc_default_security_group" "redis-and-vm-security-group" {
description = "Security group for the Yandex Managed Service for Valkey cluster and VM in Compute Cloud"
network_id = yandex_vpc_network.redis-and-vm-network.id
ingress {
description = "Allow incoming HTTP connections from the Internet"
protocol = "TCP"
port = 80
v4_cidr_blocks = ["0.0.0.0/0"]
}
ingress {
description = "Allow incoming HTTPS connections from the Internet"
protocol = "TCP"
port = 443
v4_cidr_blocks = ["0.0.0.0/0"]
}
ingress {
description = "Allow incoming connections to cluster from the Internet"
protocol = "TCP"
port = 6379
v4_cidr_blocks = ["0.0.0.0/0"]
}
ingress {
description = "Allow incoming SSH connections to 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_redis_cluster_v2" "redis-cluster" {
description = "Yandex Managed Service for Valkey cluster"
name = "valkey-cluster"
environment = "PRODUCTION"
network_id = yandex_vpc_network.redis-and-vm-network.id
security_group_ids = [yandex_vpc_default_security_group.redis-and-vm-security-group.id]
sharded = true
config = {
password = local.password
version = local.version
}
resources = {
resource_preset_id = "hm2.nano"
disk_type_id = "network-ssd"
disk_size = 16 # GB
}
hosts = {
host1 = {
zone = "ru-central1-a"
subnet_id = yandex_vpc_subnet.subnet-a.id
shard_name = "shard1"
}
host2 = {
zone = "ru-central1-b"
subnet_id = yandex_vpc_subnet.subnet-b.id
shard_name = "shard2"
}
host3 = {
zone = "ru-central1-d"
subnet_id = yandex_vpc_subnet.subnet-d.id
shard_name = "shard3"
}
}
}
resource "yandex_compute_instance" "lamp-vm" {
description = "Virtual Machine in Compute Cloud"
name = "lamp-vm"
platform_id = "standard-v3" # Intel Ice Lake
resources {
cores = 2
memory = 2 # GB
}
boot_disk {
initialize_params {
image_id = local.image_id
}
}
network_interface {
subnet_id = yandex_vpc_subnet.subnet-a.id
nat = true # Required for connection from the Internet
}
metadata = {
ssh-keys = "${local.vm_username}:${file(local.vm_ssh_key_path)}"
}
}