Skip to content
This repository was archived by the owner on May 16, 2025. It is now read-only.

Commit e60e7e4

Browse files
YCDOCIO-3558: Updated Terraform manifests (#255)
* YCDOCIO-3558: Updated Terraform manifests * YCDOCIO-3558: Grammatical edits
1 parent 0730e07 commit e60e7e4

File tree

2 files changed

+110
-77
lines changed

2 files changed

+110
-77
lines changed

tutorials/terraform/sqoop/clusters-mysql-data-proc-and-vm.tf

Lines changed: 58 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,28 @@
1-
# Infrastructure for the Yandex Cloud Managed Service for MySQL® cluster.
1+
# Infrastructure for the Yandex Cloud Managed Service for MySQL® cluster, Data Proc cluster, and Virtual Machine
22
#
3-
# RU: https://cloud.yandex.ru/docs/managed-mysql/tutorials/sqoop
3+
# RU: https://yandex.cloud/ru/docs/managed-mysql/tutorials/sqoop
4+
# EN: https://yandex.cloud/en/docs/managed-mysql/tutorials/sqoop
45
#
5-
# Set the configuration of the Managed Service for MySQL® cluster, Managed Service for Data Proc cluster, and Virtual machine:
6+
# Set the configuration of the Managed Service for MySQL® cluster, Managed Service for Data Proc cluster, and Virtual Machine:
67
locals {
7-
folder_id = "" # Your folder ID.
8-
network_id = "" # Network ID for the Managed Service for MySQL® cluster, Data Proc cluster, and VM.
9-
subnet_id = "" # Subnet ID (enable NAT for this subnet).
10-
storage_sa_id = "" # Service account ID for creating a bucket in Object Storage.
11-
data_proc_sa = "" # Set a Data Proc service account name. It must be unique in the folder.
12-
my_cluster_version = "8.0" # Set the MySQL® version: 5.7 or 8.0.
13-
my_cluster_db = "db1" # Set a database name.
14-
my_cluster_username = "user1" # Set a database owner name.
15-
my_cluster_password = "" # Set a database owner password.
16-
vm_image_id = "" # Set a public image ID from https://cloud.yandex.com/en/docs/compute/operations/images-with-pre-installed-software/get-list.
17-
vm_username = "" # Set a username for VM. Images with Ubuntu Linux use the username `ubuntu` by default.
18-
vm_public_key = "" # Set a full path to the SSH public key for VM.
19-
bucket_name = "" # Set an Object Storage bucket name. It must be unique throughout Object Storage.
20-
dp_public_key = "" # Set a full path to SSH public key for the Data Proc Cluster.
8+
folder_id = "" # Your folder ID
9+
network_id = "" # Network ID for the Managed Service for MySQL® cluster, Data Proc cluster, and VM
10+
subnet_id = "" # Subnet ID (enable NAT for this subnet)
11+
storage_sa_id = "" # Service account ID for creating a bucket in Object Storage
12+
data_proc_sa = "" # Data Proc service account name. It must be unique in the folder.
13+
my_cluster_version = "8.0" # MySQL® version: 5.7 or 8.0
14+
my_cluster_db = "db1" # Database name
15+
my_cluster_username = "user1" # Database owner's name
16+
my_cluster_password = "" # Database owner's password
17+
vm_image_id = "" # Public image ID from https://yandex.cloud/en/docs/compute/operations/images-with-pre-installed-software/get-list
18+
vm_username = "" # Username for VM. Images with Ubuntu Linux use the `ubuntu` username by default.
19+
vm_public_key = "" # Full path to the SSH public key for VM
20+
bucket_name = "" # Object Storage bucket name. It must be unique throughout Object Storage.
21+
dp_public_key = "" # Full path to the SSH public key for the Data Proc Cluster
2122
}
2223

24+
# Security groups for the Managed Service for MySQL® cluster, Data Proc cluster, and VM
25+
2326
resource "yandex_vpc_security_group" "cluster-security-group" {
2427
description = "Security group for the Managed Service for MySQL® cluster"
2528
network_id = local.network_id
@@ -80,12 +83,14 @@ resource "yandex_vpc_security_group" "data-proc-security-group" {
8083
}
8184
}
8285

86+
# The service account for the Data Proc cluster
87+
8388
resource "yandex_iam_service_account" "data-proc-sa" {
8489
description = "Service account to manage the Data Proc cluster"
8590
name = local.data_proc_sa
8691
}
8792

88-
# Assign the `dataproc.agent` role to the service account.
93+
# Assign the `dataproc.agent` role to the service account
8994
resource "yandex_resourcemanager_folder_iam_binding" "dataproc-agent" {
9095
folder_id = local.folder_id
9196
role = "dataproc.agent"
@@ -94,7 +99,7 @@ resource "yandex_resourcemanager_folder_iam_binding" "dataproc-agent" {
9499
]
95100
}
96101

97-
# Assign the `dataproc.provisioner` role to the service account.
102+
# Assign the `dataproc.provisioner` role to the service account
98103
resource "yandex_resourcemanager_folder_iam_binding" "dataproc-provisioner" {
99104
folder_id = local.folder_id
100105
role = "dataproc.provisioner"
@@ -103,7 +108,7 @@ resource "yandex_resourcemanager_folder_iam_binding" "dataproc-provisioner" {
103108
]
104109
}
105110

106-
# Assign the `monitoring-viewer` role to the service account.
111+
# Assign the `monitoring-viewer` role to the service account
107112
resource "yandex_resourcemanager_folder_iam_binding" "monitoring-viewer" {
108113
folder_id = local.folder_id
109114
role = "monitoring.viewer"
@@ -112,7 +117,7 @@ resource "yandex_resourcemanager_folder_iam_binding" "monitoring-viewer" {
112117
]
113118
}
114119

115-
# Assign the `storage.viewer` role to the service account.
120+
# Assign the `storage.viewer` role to the service account
116121
resource "yandex_resourcemanager_folder_iam_binding" "bucket-viewer" {
117122
folder_id = local.folder_id
118123
role = "storage.viewer"
@@ -121,7 +126,7 @@ resource "yandex_resourcemanager_folder_iam_binding" "bucket-viewer" {
121126
]
122127
}
123128

124-
# Assign the `storage.uploader` role to the service account.
129+
# Assign the `storage.uploader` role to the service account
125130
resource "yandex_resourcemanager_folder_iam_binding" "bucket-uploader" {
126131
folder_id = local.folder_id
127132
role = "storage.uploader"
@@ -130,6 +135,8 @@ resource "yandex_resourcemanager_folder_iam_binding" "bucket-uploader" {
130135
]
131136
}
132137

138+
# Infrastructure for the Managed Service for MySQL cluster
139+
133140
resource "yandex_mdb_mysql_cluster" "mysql-cluster" {
134141
description = "Managed Service for MySQL® cluster"
135142
name = "mysql-cluster"
@@ -144,25 +151,34 @@ resource "yandex_mdb_mysql_cluster" "mysql-cluster" {
144151
disk_size = "10" # GB
145152
}
146153

147-
database {
148-
name = local.my_cluster_db
149-
}
150-
151-
user {
152-
name = local.my_cluster_username
153-
password = local.my_cluster_password
154-
permission {
155-
database_name = local.my_cluster_db
156-
roles = ["ALL"]
157-
}
158-
}
159-
160154
host {
161155
zone = "ru-central1-a"
162156
subnet_id = local.subnet_id
163157
}
164158
}
165159

160+
# Database of the Managed Service for MySQL cluster
161+
resource "yandex_mdb_mysql_database" "db1" {
162+
cluster_id = yandex_mdb_mysql_cluster.mysql-cluster.id
163+
name = local.my_cluster_db
164+
}
165+
166+
# User of the Managed Service for MySQL cluster
167+
resource "yandex_mdb_mysql_user" "user1" {
168+
cluster_id = yandex_mdb_mysql_cluster.mysql-cluster.id
169+
name = local.my_cluster_username
170+
password = local.my_cluster_password
171+
permission {
172+
database_name = yandex_mdb_mysql_database.db1.name
173+
roles = ["ALL"]
174+
}
175+
depends_on = [
176+
yandex_mdb_mysql_database.db1
177+
]
178+
}
179+
180+
# VM infrastructure
181+
166182
resource "yandex_compute_instance" "vm-linux" {
167183
description = "Virtual Machine in Yandex Compute Cloud"
168184
name = "vm-linux"
@@ -182,7 +198,7 @@ resource "yandex_compute_instance" "vm-linux" {
182198

183199
network_interface {
184200
subnet_id = local.subnet_id
185-
nat = true # Required for connection from the Internet.
201+
nat = true # Required for connection from the Internet
186202

187203
security_group_ids = [
188204
yandex_vpc_security_group.vm-security-group.id,
@@ -191,12 +207,14 @@ resource "yandex_compute_instance" "vm-linux" {
191207
}
192208

193209
metadata = {
194-
ssh-keys = "${local.vm_username}:${file(local.vm_public_key)}" # Username and SSH public key full path.
210+
ssh-keys = "${local.vm_username}:${file(local.vm_public_key)}" # Username and the SSH public key full path
195211
}
196212
}
197213

214+
# Infrastructure for the Object Storage bucket
215+
198216
resource "yandex_iam_service_account_static_access_key" "bucket-key" {
199-
description = "Object Storage bucket static key"
217+
description = "Static key for the Object Storage bucket"
200218
service_account_id = local.storage_sa_id
201219
}
202220

@@ -207,6 +225,8 @@ resource "yandex_storage_bucket" "storage-bucket" {
207225
secret_key = yandex_iam_service_account_static_access_key.bucket-key.secret_key
208226
}
209227

228+
# Infrastructure for the Data Proc cluster
229+
210230
resource "yandex_dataproc_cluster" "my-dp-cluster" {
211231
description = "Data Proc cluster"
212232
depends_on = [yandex_resourcemanager_folder_iam_binding.dataproc-agent]

tutorials/terraform/sqoop/clusters-postgresql-data-proc-and-vm.tf

Lines changed: 52 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,28 @@
1-
# Infrastructure for the Yandex Cloud Managed Service for PostgreSQL cluster.
1+
# Infrastructure for the Yandex Cloud Managed Service for PostgreSQL cluster, Data Proc cluster, and Virtual Machine
22
#
3-
# RU: https://cloud.yandex.ru/docs/managed-postgresql/tutorials/sqoop
3+
# RU: https://yandex.cloud/ru/docs/managed-postgresql/tutorials/sqoop
4+
# EN: https://yandex.cloud/en/docs/managed-postgresql/tutorials/sqoop
45
#
5-
# Set the configuration of the Managed Service for PostgreSQL cluster, Managed Service for Data Proc cluster, and Virtual machine:
6+
# Set the configuration of the Managed Service for PostgreSQL cluster, Managed Service for Data Proc cluster, and Virtual Machine:
67
locals {
7-
folder_id = "" # Your folder ID.
8-
network_id = "" # Network ID for the Managed Service for PostgreSQL cluster, Data Proc cluster, and VM.
9-
subnet_id = "" # Subnet ID (enable NAT for this subnet).
10-
storage_sa_id = "" # Service account ID for creating a bucket in Object Storage.
11-
data_proc_sa = "" # Set a Data Proc service account name. It must be unique in the folder.
12-
pg_cluster_version = "14" # Set the PostgreSQL version.See the complete list of supported versions in https://cloud.yandex.com/en/docs/managed-postgresql/.
13-
pg_cluster_db = "db1" # Set a database name.
14-
pg_cluster_username = "user1" # Set a database owner name.
15-
pg_cluster_password = "" # Set a database owner password.
16-
vm_image_id = "" # Set a public image ID from https://cloud.yandex.com/en/docs/compute/operations/images-with-pre-installed-software/get-list.
17-
vm_username = "" # Set a username for VM. Images with Ubuntu Linux use the username `ubuntu` by default.
18-
vm_public_key = "" # Set a full path to the SSH public key for VM.
19-
bucket_name = "" # Set an Object Storage bucket name. It must be unique throughout Object Storage.
20-
dp_public_key = "" # Set a full path to SSH public key for the Data Proc Cluster.
8+
folder_id = "" # Your folder ID
9+
network_id = "" # Network ID for the Managed Service for PostgreSQL cluster, Data Proc cluster, and VM
10+
subnet_id = "" # Subnet ID (enable NAT for this subnet)
11+
storage_sa_id = "" # Service account ID for creating a bucket in Object Storage
12+
data_proc_sa = "" # Data Proc service account name. It must be unique in the folder.
13+
pg_cluster_version = "14" # PostgreSQL version. See the complete list of supported versions in https://yandex.cloud/en/docs/managed-postgresql/.
14+
pg_cluster_db = "db1" # Database name
15+
pg_cluster_username = "user1" # Database owner's name
16+
pg_cluster_password = "" # Database owner's password
17+
vm_image_id = "" # Public image ID from https://yandex.cloud/en/docs/compute/operations/images-with-pre-installed-software/get-list
18+
vm_username = "" # Username for VM. Images with Ubuntu Linux use the `ubuntu` username by default.
19+
vm_public_key = "" # Full path to the SSH public key for VM
20+
bucket_name = "" # Object Storage bucket name. It must be unique throughout Object Storage.
21+
dp_public_key = "" # Full path to the SSH public key for the Data Proc Cluster
2122
}
2223

24+
# Security groups for the Managed Service for PostgreSQL cluster, Data Proc cluster, and VM
25+
2326
resource "yandex_vpc_security_group" "cluster-security-group" {
2427
description = "Security group for the Managed Service for PostgreSQL cluster"
2528
network_id = local.network_id
@@ -80,12 +83,14 @@ resource "yandex_vpc_security_group" "data-proc-security-group" {
8083
}
8184
}
8285

86+
# The service account for the Data Proc cluster
87+
8388
resource "yandex_iam_service_account" "data-proc-sa" {
8489
description = "Service account to manage the Data Proc cluster"
8590
name = local.data_proc_sa
8691
}
8792

88-
# Assign the `dataproc.agent` role to the service account.
93+
# Assign the `dataproc.agent` role to the service account
8994
resource "yandex_resourcemanager_folder_iam_binding" "dataproc-agent" {
9095
folder_id = local.folder_id
9196
role = "dataproc.agent"
@@ -94,7 +99,7 @@ resource "yandex_resourcemanager_folder_iam_binding" "dataproc-agent" {
9499
]
95100
}
96101

97-
# Assign the `dataproc.provisioner` role to the service account.
102+
# Assign the `dataproc.provisioner` role to the service account
98103
resource "yandex_resourcemanager_folder_iam_binding" "dataproc-provisioner" {
99104
folder_id = local.folder_id
100105
role = "dataproc.provisioner"
@@ -103,7 +108,7 @@ resource "yandex_resourcemanager_folder_iam_binding" "dataproc-provisioner" {
103108
]
104109
}
105110

106-
# Assign the `monitoring-viewer` role to the service account.
111+
# Assign the `monitoring-viewer` role to the service account
107112
resource "yandex_resourcemanager_folder_iam_binding" "monitoring-viewer" {
108113
folder_id = local.folder_id
109114
role = "monitoring.viewer"
@@ -112,7 +117,7 @@ resource "yandex_resourcemanager_folder_iam_binding" "monitoring-viewer" {
112117
]
113118
}
114119

115-
# Assign the `storage.viewer` role to the service account.
120+
# Assign the `storage.viewer` role to the service account
116121
resource "yandex_resourcemanager_folder_iam_binding" "bucket-viewer" {
117122
folder_id = local.folder_id
118123
role = "storage.viewer"
@@ -121,7 +126,7 @@ resource "yandex_resourcemanager_folder_iam_binding" "bucket-viewer" {
121126
]
122127
}
123128

124-
# Assign the `storage.uploader` role to the service account.
129+
# Assign the `storage.uploader` role to the service account
125130
resource "yandex_resourcemanager_folder_iam_binding" "bucket-uploader" {
126131
folder_id = local.folder_id
127132
role = "storage.uploader"
@@ -130,6 +135,8 @@ resource "yandex_resourcemanager_folder_iam_binding" "bucket-uploader" {
130135
]
131136
}
132137

138+
# Infrastructure for the Managed Service for PostgreSQL cluster
139+
133140
resource "yandex_mdb_postgresql_cluster" "postgresql-cluster" {
134141
description = "Managed Service for PostgreSQL cluster"
135142
name = "postgresql-cluster"
@@ -146,26 +153,28 @@ resource "yandex_mdb_postgresql_cluster" "postgresql-cluster" {
146153
}
147154
}
148155

149-
database {
150-
name = local.pg_cluster_db
151-
owner = local.pg_cluster_username
152-
}
153-
154-
user {
155-
name = local.pg_cluster_username
156-
password = local.pg_cluster_password
157-
158-
permission {
159-
database_name = local.pg_cluster_db
160-
}
161-
}
162-
163156
host {
164157
zone = "ru-central1-a"
165158
subnet_id = local.subnet_id
166159
}
167160
}
168161

162+
# Database of the Managed Service for PostgreSQL cluster
163+
resource "yandex_mdb_postgresql_database" "db1" {
164+
cluster_id = yandex_mdb_postgresql_cluster.postgresql-cluster.id
165+
name = local.pg_cluster_db
166+
owner = yandex_mdb_postgresql_user.user1.name
167+
}
168+
169+
# User of the Managed Service for PostgreSQL cluster
170+
resource "yandex_mdb_postgresql_user" "user1" {
171+
cluster_id = yandex_mdb_postgresql_cluster.postgresql-cluster.id
172+
name = local.pg_cluster_username
173+
password = local.pg_cluster_password
174+
}
175+
176+
# VM infrastructure
177+
169178
resource "yandex_compute_instance" "vm-linux" {
170179
description = "Virtual Machine in Yandex Compute Cloud"
171180
name = "vm-linux"
@@ -185,7 +194,7 @@ resource "yandex_compute_instance" "vm-linux" {
185194

186195
network_interface {
187196
subnet_id = local.subnet_id
188-
nat = true # Required for connection from the Internet.
197+
nat = true # Required for connection from the Internet
189198

190199
security_group_ids = [
191200
yandex_vpc_security_group.vm-security-group.id,
@@ -194,12 +203,14 @@ resource "yandex_compute_instance" "vm-linux" {
194203
}
195204

196205
metadata = {
197-
ssh-keys = "${local.vm_username}:${file(local.vm_public_key)}" # Username and SSH public key full path.
206+
ssh-keys = "${local.vm_username}:${file(local.vm_public_key)}" # Username and the SSH public key full path
198207
}
199208
}
200209

210+
# Infrastructure for the Object Storage bucket
211+
201212
resource "yandex_iam_service_account_static_access_key" "bucket-key" {
202-
description = "Object Storage bucket static key"
213+
description = "Static key for the Object Storage bucket"
203214
service_account_id = local.storage_sa_id
204215
}
205216

@@ -210,6 +221,8 @@ resource "yandex_storage_bucket" "storage-bucket" {
210221
secret_key = yandex_iam_service_account_static_access_key.bucket-key.secret_key
211222
}
212223

224+
# Infrastructure for the Data Proc cluster
225+
213226
resource "yandex_dataproc_cluster" "my-dp-cluster" {
214227
description = "Data Proc cluster"
215228
depends_on = [yandex_resourcemanager_folder_iam_binding.dataproc-agent]

0 commit comments

Comments
 (0)