-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.tf
75 lines (64 loc) · 1.86 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
71
72
73
74
75
provider "google" {
# credentials = file("./compute-instance.json")
project = var.project_name
region = var.region
zone = var.zone
}
resource "google_compute_network" "vpc_network" {
name = "${var.name}-network"
auto_create_subnetworks = false
mtu = 1460 # max transmission unit size
}
resource "google_compute_subnetwork" "default" {
name = "${var.name}-subnet"
ip_cidr_range = "10.0.1.0/24"
region = var.region
network = google_compute_network.vpc_network.id
}
resource "google_compute_firewall" "ssh" {
name = "${var.name}-dev-access"
allow {
ports = ["22"]
protocol = "tcp"
}
direction = "INGRESS"
network = google_compute_network.vpc_network.id
priority = 1000
# Allow from everywhere
source_ranges = ["0.0.0.0/0"]
target_tags = ["ssh"]
}
resource "google_compute_firewall" "server" {
name = "${var.name}-server-firewall"
network = google_compute_network.vpc_network.id
allow {
protocol = "tcp"
ports = ["80"]
}
# Allow from everywhere
source_ranges = ["0.0.0.0/0"]
}
# Create a single Compute Engine instance
resource "google_compute_instance" "default" {
name = var.name
machine_type = var.instance_type
zone = var.zone
tags = ["ssh"]
boot_disk {
initialize_params {
image = var.image
}
}
metadata_startup_script = format(file("instance_scripts/deploy_normal.sh"), var.use_quantized)
network_interface {
subnetwork = google_compute_subnetwork.default.id
access_config {
# Include this section to give the VM an external IP address
}
}
}
// A variable for extracting the external IP address of the VM
output "public_ip" {
value = google_compute_instance.default.network_interface.0.access_config.0.nat_ip
description = "The public IP of the server"
}