-
Notifications
You must be signed in to change notification settings - Fork 41
/
main.vm.tf
97 lines (83 loc) · 2.56 KB
/
main.vm.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
88
89
90
91
92
93
94
95
96
97
terraform {
required_providers {
google = {
source = "hashicorp/google"
}
googlesiteverification = {
source = "hectorj/googlesiteverification"
version = "0.4.5"
}
}
}
provider "google" {
credentials = file(var.google_service_credentials_json_file)
project = local.google_project_id
region = var.google_region
zone = var.google_zone
}
resource "google_compute_network" "vpc_network" {
name = "${local.environment_name}-network"
}
resource "google_compute_instance" "vm_instance" {
depends_on = [
google_compute_disk.boot,
google_storage_bucket.cloud_storage
]
name = "${local.environment_name}-vm"
machine_type = var.google_machine_type
tags = ["mithril", local.environment_name, var.environment_prefix, var.cardano_network]
allow_stopping_for_update = true
metadata = {
sshKeys = file("./assets/ssh_keys")
}
metadata_startup_script = file("./assets/startup-vm.sh")
boot_disk {
source = google_compute_disk.boot.name
auto_delete = false
}
lifecycle {
ignore_changes = [attached_disk]
}
network_interface {
network = google_compute_network.vpc_network.name
access_config {
nat_ip = google_compute_address.mithril-external-address.address
}
}
}
resource "google_compute_disk" "boot" {
name = "${local.environment_name}-boot"
type = var.google_compute_instance_boot_disk_type
zone = var.google_zone
size = var.google_compute_instance_boot_disk_size
image = var.google_compute_instance_boot_disk_image
snapshot = var.google_compute_instance_boot_disk_snapshot
labels = {
environment = local.environment_name
type = "boot"
}
}
resource "google_compute_resource_policy" "policy-boot" {
name = "${local.environment_name}-policy-boot"
region = var.google_region
snapshot_schedule_policy {
schedule {
daily_schedule {
days_in_cycle = var.google_compute_instance_boot_disk_snapshot_pace_days
start_time = var.google_compute_instance_boot_disk_snapshot_start_time
}
}
retention_policy {
max_retention_days = var.google_compute_instance_boot_disk_snapshot_max_retention_days
on_source_disk_delete = "KEEP_AUTO_SNAPSHOTS"
}
}
}
resource "google_compute_disk_resource_policy_attachment" "policy-attachment-boot" {
name = google_compute_resource_policy.policy-boot.name
disk = google_compute_disk.boot.name
zone = var.google_zone
}
resource "google_compute_address" "mithril-external-address" {
name = "${local.environment_name}-ip"
}