-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
67 lines (58 loc) · 2.19 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
provider "google" {
project = "${var.project-name}"
region = "${var.region}"
}
// Create a new instance
resource "google_compute_instance" "default" {
// strip underscores from provided name b/c GCE doesn't like them
name = "${replace(var.instance-name,"_","")}"
machine_type = "n1-standard-1"
zone = "us-central1-c"
tags = ["allow-8080", "allow-3000", "allow-k8s-nodeports"]
boot_disk {
initialize_params {
image = "ubuntu-1804-lts"
// image = "microk8s-from-instance-01"
}
}
network_interface {
network = "default"
access_config {
// An Ephemeral IP will be assigned
}
}
// startup:
// 1. install microk8s
// 2. program instance for self-deletion
// TODO: bake an image where all this is already done
metadata = {
startup-script = <<-SCRIPT
snap install microk8s --classic
# Patch microk8s configuration so we can connect from the outside
# This is not a good practice, use it only for the purpose of this lab
sed -i.sed-bak "s/127\.0\.0\.1/0.0.0.0/" /var/snap/microk8s/current/args/kube-apiserver
systemctl restart snap.microk8s.daemon-apiserver.service
microk8s.status --wait-ready
microk8s.enable dns
microk8s.status --wait-ready
echo "gcloud compute instances delete $(hostname) --zone $(curl -H Metadata-Flavor:Google http://metadata.google.internal/computeMetadata/v1/instance/zone -s | cut -d/ -f4) -q" | at Now + ${var.self-destruct-timeout-minutes} Minutes
SCRIPT
}
service_account {
scopes = [
// default GCE scopes
"https://www.googleapis.com/auth/devstorage.read_only",
"https://www.googleapis.com/auth/logging.write",
"https://www.googleapis.com/auth/monitoring.write",
"https://www.googleapis.com/auth/pubsub",
"https://www.googleapis.com/auth/service.management.readonly",
"https://www.googleapis.com/auth/servicecontrol",
"https://www.googleapis.com/auth/trace.append",
// grant permission to compute API so this instance can delete itself
"https://www.googleapis.com/auth/compute",
]
}
}
output "ip" {
value = "${google_compute_instance.default.network_interface.0.access_config.0.nat_ip}"
}