-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
55 lines (47 loc) · 1.38 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
module "network" {
source = "./modules/network"
network_name = "dev-network"
subnetwork_name = "dev-subnetwork"
subnet_cidr = "10.142.0.0/20"
region = var.region
project = var.project_id
firewall_name = "dev-firewall"
router_name = "dev-router"
nat_name = "dev-nat"
host_ip = var.host_ip
}
resource "google_compute_instance" "workspace" {
name = "dev-workspace"
machine_type = "f1-micro"
zone = "${var.region}-b"
project = var.project_id
boot_disk {
initialize_params {
image = data.google_compute_image.os_image.self_link
}
}
network_interface {
subnetwork = module.network.subnet.name
access_config {
// Leave this empty to use an ephemeral IP.
}
}
metadata = {
ssh-keys = "ubuntu:${file(var.public_key_path)}"
}
metadata_startup_script = file("templates/userdata.tpl")
labels = {
environment = "dev"
}
service_account {
scopes = ["userinfo-email", "compute-ro", "storage-ro"]
}
provisioner "local-exec" {
command = templatefile("templates/${var.host_os}-ssh-config.tpl", {
hostname = self.network_interface[0].access_config[0].nat_ip,
user = "ubuntu",
indentityfile = "~/.ssh/gcp_dev_environ"
})
interpreter = var.host_os == "windows" ? ["Powershell", "-Command"] : ["bash", "-c"]
}
}