forked from ehzhang/HELPq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
88 lines (71 loc) · 1.93 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
provider "google" {
credentials = "${file("deploy/credentials/gcloud.json")}"
project = "${jsondecode(file("deploy/credentials/gcloud.json"))["project_id"]}"
region = "europe-west2"
zone = "europe-west2-a"
}
resource "random_id" "helpq" {
byte_length = 8
}
resource "tls_private_key" "connection_key" {
algorithm = "RSA"
rsa_bits = 4096
}
resource "google_compute_address" "helpq" {
name = "helpq-address"
}
resource "google_compute_network" "helpq_network" {
name = "helpq-network"
}
resource "google_compute_firewall" "helpq_firewall" {
name = "helpq-firewall"
network = "${google_compute_network.helpq_network.name}"
allow {
protocol = "tcp"
ports = ["22", "80", "443"]
}
}
resource "google_compute_instance" "helpq" {
name = "helpq-${random_id.helpq.hex}"
machine_type = "n1-standard-2"
boot_disk {
initialize_params {
image = "gce-uefi-images/ubuntu-1804-lts"
}
}
scratch_disk {
}
provisioner "file" {
source = "private/config.json"
destination = "/root/config.json"
connection {
type = "ssh"
user = "root"
host = "${google_compute_address.helpq.address}"
private_key = "${tls_private_key.connection_key.private_key_pem}"
}
}
provisioner "file" {
source = "deploy/helpq.nginx"
destination = "/root/helpq.nginx"
connection {
type = "ssh"
user = "root"
host = "${google_compute_address.helpq.address}"
private_key = "${tls_private_key.connection_key.private_key_pem}"
}
}
metadata_startup_script = "${file("./deploy/setup.sh")}"
network_interface {
network = "${google_compute_network.helpq_network.name}"
access_config {
nat_ip = "${google_compute_address.helpq.address}"
}
}
metadata = {
ssh-keys = "root:${tls_private_key.connection_key.public_key_openssh}"
}
}
output "helpq-ip" {
value = "${google_compute_address.helpq.address}"
}