-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.tf
70 lines (58 loc) · 1.67 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
locals {
name = "example-${basename(path.cwd)}"
tags = {
Name = local.name
}
}
module "vpc" {
source = "../internal-modules/aws-vpc"
name = local.name
tags = local.tags
cidr = "10.0.80.0/22"
public_subnets = ["10.0.80.0/24"]
private_subnets = ["10.0.81.0/24"]
}
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",
]
}
resource "aws_network_interface" "primary" {
subnet_id = module.vpc.public_subnets[0]
security_groups = [module.vpc.tailscale_security_group_id]
tags = local.tags
}
resource "aws_eip" "primary" {
tags = local.tags
}
resource "aws_eip_association" "primary" {
network_interface_id = aws_network_interface.primary.id
allocation_id = aws_eip.primary.id
}
module "tailscale_aws_ec2_autoscaling" {
source = "../internal-modules/aws-ec2-autoscaling/"
autoscaling_group_name = local.name
instance_type = "t4g.micro"
instance_tags = local.tags
network_interfaces = [aws_network_interface.primary.id]
# Variables for Tailscale resources
tailscale_auth_key = tailscale_tailnet_key.main.key
tailscale_hostname = local.name
tailscale_set_preferences = [
"--auto-update",
"--ssh",
"--advertise-connector",
"--advertise-exit-node",
"--advertise-routes=${join(",", [module.vpc.vpc_cidr_block])}",
]
depends_on = [
module.vpc.natgw_ids, # ensure NAT gateway is available before instance provisioning - primarily for private subnets
]
}