-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
133 lines (103 loc) · 2.6 KB
/
main.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
terraform {
backend "remote" {
organization = "laloloop"
workspaces {
name = "kubernetes_fundamentals"
}
}
}
// Provider
provider "google" {
project = var.project
region = "us-central1"
version = "~> 3.35.0"
}
// Variables
variable "project" {
description = "GCP project to create this resources into."
}
variable "ssh-user" {
description = "SSH user to log into the instances."
default = "student"
}
variable "gce_ssh_pub_key_file" {
description = "The public SSH key to log into the instances."
default = "./id_rsa.pub"
}
// Enable required APIs
resource "google_project_service" "cloud_resource_manager_api" {
service = "cloudresourcemanager.googleapis.com"
disable_dependent_services = false
disable_on_destroy = false
}
resource "google_project_service" "compute_engine_api" {
service = "compute.googleapis.com"
disable_dependent_services = false
disable_on_destroy = false
}
// VPC network
resource "google_compute_network" "vpc_lfclass" {
name = "lfclass"
description = "For my LF class"
auto_create_subnetworks = false
}
resource "google_compute_subnetwork" "subnet_lfsclass" {
name = "lfclass"
ip_cidr_range = "10.2.0.0/16"
network = google_compute_network.vpc_lfclass.id
}
// Firewall rules
resource "google_compute_firewall" "fw_lfclass" {
name = "lfclass"
description = "For my LF class"
network = google_compute_network.vpc_lfclass.name
allow {
protocol = "all"
}
source_ranges = ["0.0.0.0/0"]
}
// Nodes
resource "google_compute_instance" "master" {
name = "master"
zone = "us-central1-f"
machine_type = "n1-standard-2"
boot_disk {
initialize_params {
size = 20
image = "ubuntu-1804-lts"
}
}
metadata = {
"ssh-keys" = "${var.ssh-user}:${file(var.gce_ssh_pub_key_file)}"
}
metadata_startup_script = file("./scripts/master_startup.sh")
network_interface {
network = google_compute_network.vpc_lfclass.name
subnetwork = google_compute_subnetwork.subnet_lfsclass.name
access_config {
// Ephemeral IP
}
}
}
resource "google_compute_instance" "worker" {
name = "worker"
zone = "us-central1-f"
machine_type = "n1-standard-2"
boot_disk {
initialize_params {
size = 20
image = "ubuntu-1804-lts"
}
}
metadata = {
"ssh-keys" = "${var.ssh-user}:${file(var.gce_ssh_pub_key_file)}"
}
metadata_startup_script = file("./scripts/worker_startup.sh")
network_interface {
network = google_compute_network.vpc_lfclass.name
subnetwork = google_compute_subnetwork.subnet_lfsclass.name
access_config {
// Ephemeral IP
}
}
}