-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.tf
107 lines (89 loc) · 2.68 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
locals {
name = "example-${basename(path.cwd)}"
aws_tags = {
Name = local.name
}
tailscale_acl_tags = [
"tag:example-infra",
"tag:example-exitnode",
"tag:example-subnetrouter",
"tag:example-appconnector",
]
tailscale_set_preferences = [
"--auto-update",
"--ssh",
"--advertise-connector",
"--advertise-exit-node",
"--advertise-routes=${join(",", [
local.vpc_cidr_block,
])}",
]
// Modify these to use your own VPC
vpc_cidr_block = module.vpc.vpc_cidr_block
vpc_id = module.vpc.vpc_id
subnet_id = module.vpc.public_subnets[0]
security_group_ids = [aws_security_group.tailscale.id]
instance_type = "t4g.micro"
}
// Remove this to use your own VPC.
module "vpc" {
source = "../internal-modules/aws-vpc"
name = local.name
tags = local.aws_tags
cidr = "10.0.80.0/22"
public_subnets = ["10.0.80.0/24"]
private_subnets = ["10.0.81.0/24"]
enable_ipv6 = true
}
resource "tailscale_tailnet_key" "main" {
ephemeral = true
preauthorized = true
reusable = true
recreate_if_invalid = "always"
tags = local.tailscale_acl_tags
}
module "tailscale_aws_ec2" {
source = "../internal-modules/aws-ec2-instance"
instance_type = local.instance_type
instance_tags = local.aws_tags
subnet_id = local.subnet_id
vpc_security_group_ids = local.security_group_ids
ipv6_address_count = 1
# Variables for Tailscale resources
tailscale_hostname = local.name
tailscale_auth_key = tailscale_tailnet_key.main.key
tailscale_set_preferences = local.tailscale_set_preferences
depends_on = [
module.vpc.nat_ids, # remove if using your own VPC otherwise ensure provisioned NAT gateway is available
]
}
resource "aws_security_group" "tailscale" {
vpc_id = local.vpc_id
name = local.name
}
resource "aws_security_group_rule" "tailscale_ingress" {
security_group_id = aws_security_group.tailscale.id
type = "ingress"
from_port = 41641
to_port = 41641
protocol = "udp"
cidr_blocks = ["0.0.0.0/0"]
ipv6_cidr_blocks = ["::/0"]
}
resource "aws_security_group_rule" "egress" {
security_group_id = aws_security_group.tailscale.id
type = "egress"
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
ipv6_cidr_blocks = ["::/0"]
}
resource "aws_security_group_rule" "internal_vpc_ingress_ipv4" {
security_group_id = aws_security_group.tailscale.id
type = "ingress"
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = [local.vpc_cidr_block]
}