-
Notifications
You must be signed in to change notification settings - Fork 0
/
data-proc-dns-connect.tf
177 lines (150 loc) · 5.9 KB
/
data-proc-dns-connect.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
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
166
167
168
169
170
171
172
173
174
175
176
177
# Infrastructure for the Yandex Data Processing cluster with DNS for the master host FQDN
#
# RU: https://cloud.yandex.ru/docs/data-proc/tutorials/reconnect-network
# EN: https://cloud.yandex.com/en-ru/docs/data-proc/tutorials/reconnect-network
# Specify the following settings:
locals {
folder_id = "" # Your cloud folder ID, same as for provider
path_to_ssh_public_key = "" # Absolute path to the SSH public key for the Yandex Data Processing cluster
bucket = "" # Name of an Object Storage bucket for input files. Must be unique in the Cloud.
# Specify these settings ONLY AFTER the cluster is created. Then run "terraform apply" command again
# You should set up the Yandex Data Processing master node FQDN using the GUI/CLI/API to obtain the FQDN
dataproc_fqdn = "test" # Substitute "test" with the Yandex Data Processing cluster master node FQDN
}
resource "yandex_vpc_network" "data-proc-network" {
description = "Network for the Yandex Data Processing cluster"
name = "data-proc-network"
}
# NAT gateway and route table configuration
resource "yandex_vpc_gateway" "nat-gateway" {
name = "test-nat-gateway"
shared_egress_gateway {}
}
resource "yandex_vpc_route_table" "route-table-nat" {
name = "route-table-nat"
network_id = yandex_vpc_network.data-proc-network.id
static_route {
destination_prefix = "0.0.0.0/0"
gateway_id = yandex_vpc_gateway.nat-gateway.id
}
}
resource "yandex_vpc_subnet" "data-proc-subnet" {
description = "Subnet for the Yandex Data Processing cluster"
name = "data-proc-subnet"
network_id = yandex_vpc_network.data-proc-network.id
v4_cidr_blocks = ["192.168.1.0/24"]
zone = "ru-central1-a"
route_table_id = yandex_vpc_route_table.route-table-nat.id
}
resource "yandex_vpc_security_group" "data-proc-security-group" {
description = "Security group for DataProc"
name = "data-proc-security-group"
network_id = yandex_vpc_network.data-proc-network.id
egress {
description = "Allow outgoing HTTPS traffic"
protocol = "TCP"
port = 443
v4_cidr_blocks = ["0.0.0.0/0"]
}
ingress {
description = "Allow any traffic within the security group"
protocol = "ANY"
from_port = 0
to_port = 65535
predefined_target = "self_security_group"
}
egress {
description = "Allow any traffic within the security group"
protocol = "ANY"
from_port = 0
to_port = 65535
predefined_target = "self_security_group"
}
}
# Create a service account
resource "yandex_iam_service_account" "dataproc-sa-user" {
folder_id = local.folder_id
name = "data-proc-sa-user"
}
# Grant permissions to the service account
resource "yandex_resourcemanager_folder_iam_member" "sa-editor" {
folder_id = local.folder_id
role = "storage.editor"
member = "serviceAccount:${yandex_iam_service_account.dataproc-sa-user.id}"
}
resource "yandex_resourcemanager_folder_iam_member" "dataproc-sa-role-dataproc-agent" {
folder_id = local.folder_id
role = "dataproc.agent"
member = "serviceAccount:${yandex_iam_service_account.dataproc-sa-user.id}"
}
resource "yandex_resourcemanager_folder_iam_member" "dataproc-sa-role-dataproc-provisioner" {
folder_id = local.folder_id
role = "dataproc.provisioner"
member = "serviceAccount:${yandex_iam_service_account.dataproc-sa-user.id}"
}
# Create an access key for the service account
resource "yandex_iam_service_account_static_access_key" "sa-static-key" {
description = "Static access key for Object Storage"
service_account_id = yandex_iam_service_account.dataproc-sa-user.id
}
# Use keys to create a bucket
resource "yandex_storage_bucket" "obj-storage-bucket" {
access_key = yandex_iam_service_account_static_access_key.sa-static-key.access_key
secret_key = yandex_iam_service_account_static_access_key.sa-static-key.secret_key
bucket = local.bucket
}
resource "yandex_dataproc_cluster" "dataproc-cluster" {
description = "Yandex Data Processing cluster"
name = "dataproc-cluster"
service_account_id = yandex_iam_service_account.dataproc-sa-user.id
zone_id = "ru-central1-a"
bucket = local.bucket
security_group_ids = [
yandex_vpc_security_group.data-proc-security-group.id
]
cluster_config {
hadoop {
services = ["HDFS", "YARN", "SPARK", "TEZ", "MAPREDUCE", "HIVE"]
ssh_public_keys = [
file(local.path_to_ssh_public_key)
]
}
subcluster_spec {
name = "subcluster-master"
role = "MASTERNODE"
subnet_id = yandex_vpc_subnet.data-proc-subnet.id
hosts_count = 1 # For MASTERNODE only one hosts assigned
resources {
resource_preset_id = "s2.micro" # 4 vCPU Intel Cascade, 16 GB RAM
disk_type_id = "network-ssd" # Fast network SSD storage
disk_size = 20 # GB
}
}
subcluster_spec {
name = "subcluster-data"
role = "DATANODE"
subnet_id = yandex_vpc_subnet.data-proc-subnet.id
hosts_count = 1
resources {
resource_preset_id = "s2.micro" # 4 vCPU, 16 GB RAM
disk_type_id = "network-ssd" # Fast network SSD storage
disk_size = 20 # GB
}
}
}
}
resource "yandex_dns_zone" "data-proc-zone" {
name = "dp-private-zone"
description = "Yandex Data Processing DNS zone"
zone = "data-proc-test-user.org."
public = false
private_networks = [yandex_vpc_network.data-proc-network.id]
}
# DNS record for the Yandex Data Processing cluster master node FQDN
resource "yandex_dns_recordset" "data-proc-record" {
zone_id = yandex_dns_zone.data-proc-zone.id
name = "data-proc-test-user.org."
type = "CNAME"
ttl = 600
data = [local.dataproc_fqdn]
}