-
Notifications
You must be signed in to change notification settings - Fork 0
/
ubnt-vm-main.tf
88 lines (75 loc) · 2.7 KB
/
ubnt-vm-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
##~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~##
## GCP Linux VM - Main ##
##~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~##
## Change as Required ##
##~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~##
/* App Data Disk --------------------------------------------------------------------- */
resource "google_compute_disk" "app-data" {
name = "app-data"
type = "pd-standard"
zone = "${var.gcp_zone}"
size = 20
labels = {
vm = "gcp-cos-vm-01"
managedby = "terraform"
}
}
/* VM --------------------------------------------------------------------- */
resource "google_compute_instance" "gcp-ubnt-vm" {
name = var.vm_name
machine_type = var.vm_instance_type
zone = var.gcp_zone
can_ip_forward = "true"
allow_stopping_for_update = "true"
tags = ["ssh","http-server","https-server"]
/* Boot Disk --------------------------------------------------------------------- */
boot_disk {
initialize_params {
image = var.ubnt_2204
}
}
/* App Data Disk --------------------------------------------------------------------- */
attached_disk {
source = google_compute_disk.app-data.self_link
device_name = google_compute_disk.app-data.name
}
/* Startup Script --------------------------------------------------------------------- */
metadata = {
ssh-keys = "${var.user}:${file(var.publickeypath)}"
}
metadata_startup_script = "${file("../startup/startup.sh")}"
/* Network --------------------------------------------------------------------- */
network_interface {
network = google_compute_network.vpc.name
subnetwork = google_compute_subnetwork.network_subnet.name
access_config {
}
}
/* Options --------------------------------------------------------------------- */
scheduling {
automatic_restart = true
}
lifecycle {
ignore_changes = [attached_disk]
}
/* File Copy --------------------------------------------------------------------- */
provisioner "file" {
# source file name on the local machine where you execute terraform plan and apply
source = "../compose_files/docker-compose.yaml"
# destination is the file location on the newly created instance
destination = "/home/${var.user}/docker-compose.yaml"
connection {
host = google_compute_instance.gcp-ubnt-vm.network_interface.0.access_config.0.nat_ip
type = "ssh"
# username of the instance would vary for each account refer the OS Login in GCP documentation
user = var.user
timeout = "500s"
private_key = file(var.privatekeypath)
}
# Commands to be executed as the instance gets ready.
# installing nginx
#inline = [
# "sudo /tmp/startupscript.sh"
#]
}
}