-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
70 lines (59 loc) · 2.48 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
68
69
70
variable "project" {
default = ""
}
variable "ssh_user" {
}
variable "ssh_filename" {
}
variable "script_path" {
}
provider "google" {
project = var.project
region = "europe-west4"
zone = "europe-west4-c"
}
resource "google_compute_instance" "vm_instance" {
name = "terraform-instance"
machine_type = "n1-standard-1"
metadata = {
ssh-keys = "${var.ssh_user}:${file("${var.ssh_filename}")}"
startup-script = "${file("${var.script_path}")}"
}
boot_disk {
initialize_params {
image = "ubuntu-os-cloud/ubuntu-1804-bionic-v20190813a"
}
}
network_interface {
# A default network is created for all GCP projects
network = "${google_compute_network.vpc_network.self_link}"
access_config {
}
}
}
resource "google_compute_network" "vpc_network" {
name = "terraform-network"
auto_create_subnetworks = "true"
}
resource "google_compute_firewall" "terraform-network-ssh" {
name = "allow-all-vpc-ssh"
network = "${google_compute_network.vpc_network.name}"
allow {
protocol = "tcp"
ports = ["22"]
}
source_ranges = ["0.0.0.0/0"]
}
resource "google_compute_firewall" "terraform-network-https" {
name = "allow-all-vpc-novnc-https"
network = "${google_compute_network.vpc_network.name}"
allow {
protocol = "tcp"
ports = ["443"]
}
source_ranges = ["0.0.0.0/0"]
}
output "VNC_Server_Url" {
value = "https://${google_compute_instance.vm_instance.network_interface[0].access_config[0].nat_ip}/vnc.html"
description = "VNC web server url"
}