-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.tf
76 lines (67 loc) · 1.98 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
76
resource random_id instance_suffix {
byte_length = 2
keepers = {
zone = var.zone
address = var.address
startup_script = local.startup_script
startup_script_parts = sha256(jsonencode(local.instance_metadata))
machine_type = var.machine_type
disk_size = var.disk_size
disk_type = var.disk_type
}
}
resource random_id address_suffix {
byte_length = 2
keepers = {
region = local.region
}
}
resource google_compute_address address {
name = "nat-instance-${local.region}-${random_id.address_suffix.hex}"
address_type = "INTERNAL"
region = random_id.address_suffix.keepers.region
lifecycle {
create_before_destroy = true
}
}
resource google_compute_instance instance {
name = local.instance_name
zone = random_id.instance_suffix.keepers.zone
can_ip_forward = true
machine_type = random_id.instance_suffix.keepers.machine_type
metadata_startup_script = random_id.instance_suffix.keepers.startup_script
metadata = local.instance_metadata
tags = [local.instance_name]
boot_disk {
initialize_params {
size = random_id.instance_suffix.keepers.disk_size
type = random_id.instance_suffix.keepers.disk_type
image = "debian-cloud/debian-10"
}
}
network_interface {
network = "default"
network_ip = google_compute_address.address.address
access_config {
nat_ip = random_id.instance_suffix.keepers.address
}
}
}
resource null_resource delay_between_instance_and_route {
provisioner "local-exec" {
command = "sleep ${var.wait_duration}"
}
triggers = {
after = google_compute_instance.instance.id
}
}
resource google_compute_route route {
name = google_compute_instance.instance.name
network = "default"
dest_range = "0.0.0.0/0"
tags = local.network_tags
priority = var.route_priority
next_hop_instance = google_compute_instance.instance.self_link
next_hop_instance_zone = google_compute_instance.instance.zone
depends_on = [null_resource.delay_between_instance_and_route]
}