-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathlinux-vm-main.tf
41 lines (35 loc) · 1.13 KB
/
linux-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
#########################
## GCP Linux VM - Main ##
#########################
# Terraform plugin for creating random ids
resource "random_id" "instance_id" {
byte_length = 4
}
# Bootstrapping Script to Install Apache
data "template_file" "linux-metadata" {
template = <<EOF
sudo apt-get update;
sudo apt-get install -yq build-essential apache2;
sudo systemctl start apache2;
sudo systemctl enable apache2;
EOF
}
# Create VM
resource "google_compute_instance" "vm_instance_public" {
name = "${lower(var.company)}-${lower(var.app_name)}-${var.environment}-vm${random_id.instance_id.hex}"
machine_type = var.linux_instance_type
zone = var.gcp_zone
hostname = "${var.app_name}-vm${random_id.instance_id.hex}.${var.app_domain}"
tags = ["ssh","http"]
boot_disk {
initialize_params {
image = var.ubuntu_2004_sku
}
}
metadata_startup_script = data.template_file.linux-metadata.rendered
network_interface {
network = google_compute_network.vpc.name
subnetwork = google_compute_subnetwork.network_subnet.name
access_config { }
}
}