-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.tf
71 lines (59 loc) · 1.55 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
locals {
name = "example-${basename(path.cwd)}"
metadata = {
Name = local.name
}
tags = []
}
module "vpc" {
source = "../internal-modules/google-vpc"
project_id = var.project_id
region = var.region
name = local.name
subnets = [
{
subnet_name = "subnet-${var.region}-10-0-121"
subnet_ip = "10.0.121.0/24"
subnet_region = var.region
},
{
subnet_name = "subnet-${var.region}-10-0-122"
subnet_ip = "10.0.122.0/24"
subnet_region = var.region
}
]
}
resource "tailscale_tailnet_key" "main" {
ephemeral = true
preauthorized = true
reusable = true
recreate_if_invalid = "always"
tags = [
"tag:example-infra",
"tag:example-exitnode",
"tag:example-subnetrouter",
"tag:example-appconnector",
]
}
module "tailscale_instance" {
source = "../internal-modules/google-compute-instance"
zone = var.zone
machine_name = local.name
machine_type = "e2-medium"
subnet = module.vpc.subnets_ids[0]
instance_metadata = local.metadata
instance_tags = local.tags
# Variables for Tailscale resources
tailscale_hostname = local.name
tailscale_auth_key = tailscale_tailnet_key.main.key
tailscale_set_preferences = [
"--auto-update",
"--ssh",
"--advertise-connector",
"--advertise-exit-node",
"--advertise-routes=${join(",", module.vpc.subnets_ips)}",
]
depends_on = [
module.vpc.nat_ids, # ensure NAT gateway is available before instance provisioning - primarily for private subnets
]
}