-
Notifications
You must be signed in to change notification settings - Fork 0
/
data-proc-nat-gateway.tf
162 lines (137 loc) · 5.05 KB
/
data-proc-nat-gateway.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
# Infrastructure for Yandex Data Processing cluster with NAT gateway
#
# RU: https://cloud.yandex.ru/docs/data-proc/tutorials/configure-network
# EN: https://cloud.yandex.com/en/docs/data-proc/tutorials/configure-network
# Specify the following settings:
locals {
folder_id = "" # Set your cloud folder ID, same as for provider
path_to_ssh_public_key = "" # Set a full path to an SSH public key. Example: "~/.ssh/key.pub"
bucket = "" # Set a unique bucket name
}
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"
}
egress {
description = "Allow outgoing traffic to NTP servers for time synchronization"
protocol = "UDP"
port = 123
v4_cidr_blocks = ["0.0.0.0/0"]
}
}
# Create a service account
resource "yandex_iam_service_account" "dataproc-sa" {
folder_id = local.folder_id
name = "data-proc-sa"
}
# 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.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.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.id}"
}
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.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.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
}
}
}
}