-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
88 lines (64 loc) · 1.63 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
data "google_compute_subnetwork" "job" {
name = "${var.subnetwork_name}"
}
data "template_file" "startup_script" {
template = "${file("${path.module}/templates/install.sh")}"
vars {
db_internal_ip = "${var.db_internal_ip}"
}
}
locals {
name = "${var.name}-job"
}
resource "google_compute_instance" "job" {
name = "${local.name}"
machine_type = "n1-standard-1"
zone = "us-west1-a"
allow_stopping_for_update = true
labels = {
name = "job"
}
tags = ["job"]
boot_disk {
initialize_params {
image = "ubuntu-os-cloud/ubuntu-1804-lts"
}
}
// Local SSD disk
scratch_disk {}
network_interface {
subnetwork = "${data.google_compute_subnetwork.job.self_link}"
access_config {
// Ephemeral IP
}
}
metadata {
sshKeys = "ubuntu:${file(var.ssh_public_key_filepath)}"
block-project-ssh-keys = "TRUE"
startup-script = "${data.template_file.startup_script.rendered}"
}
}
resource "google_compute_firewall" "allow_ssh_ingress" {
name = "${local.name}-allow-ssh-ingress"
network = "${data.google_compute_subnetwork.job.network}"
direction = "INGRESS"
priority = 999
allow {
protocol = "tcp"
ports = ["22"]
}
source_ranges = "${var.engineer_cidrs}"
target_tags = ["job"]
}
resource "google_compute_firewall" "allow_data_ingress_to_db" {
name = "${local.name}-allow-data-ingress-to-db"
network = "${data.google_compute_subnetwork.job.network}"
direction = "INGRESS"
priority = 998
allow {
protocol = "tcp"
ports = ["28015"]
}
source_tags = ["job"]
target_tags = ["db"]
}