-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.tf
More file actions
79 lines (64 loc) · 1.78 KB
/
main.tf
File metadata and controls
79 lines (64 loc) · 1.78 KB
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
provider "google" {
credentials = "${file("credentials/gcloud.json")}"
project = "${jsondecode(file("credentials/gcloud.json"))["project_id"]}"
region = "${var.region}"
zone = "${var.zone}"
}
resource "random_id" "announcements" {
byte_length = 8
}
resource "tls_private_key" "connection_key" {
algorithm = "RSA"
rsa_bits = 4096
}
resource "google_compute_network" "announcements_network" {
name = "announcement-network"
}
resource "google_compute_firewall" "announcements_firewall" {
name = "announcements-firewall"
network = "${google_compute_network.announcements_network.name}"
allow {
protocol = "tcp"
ports = [
"22",
"80",
"443"]
}
}
resource "google_compute_address" "announcements_ip" {
name = "annoucement-address"
}
resource "google_compute_instance" "announcement" {
name = "announcement-${random_id.announcements.hex}"
machine_type = "n1-standard-1"
boot_disk {
initialize_params {
image = "gce-uefi-images/ubuntu-1804-lts"
}
}
scratch_disk {
}
provisioner "file" {
source = "token.pickle"
destination = "token.pickle"
connection {
type = "ssh"
user = "root"
host = "${google_compute_instance.announcement.network_interface.0.access_config.0.nat_ip}"
private_key = "${tls_private_key.connection_key.private_key_pem}"
}
}
metadata_startup_script = "${file("./scripts/announcement-setup.sh")}"
network_interface {
network = "${google_compute_network.announcements_network.name}"
access_config {
nat_ip = "${google_compute_address.announcements_ip.address}"
}
}
metadata = {
ssh-keys = "root:${tls_private_key.connection_key.public_key_openssh}"
}
}
output "announcement-ip" {
value = "${google_compute_address.announcements_ip.address}"
}