1
1
locals {
2
2
name = " example-${ basename (path. cwd )} "
3
3
4
- tags = {
4
+ aws_tags = {
5
5
Name = local.name
6
6
}
7
+
8
+ tailscale_acl_tags = [
9
+ " tag:example-infra" ,
10
+ " tag:example-exitnode" ,
11
+ " tag:example-subnetrouter" ,
12
+ " tag:example-appconnector" ,
13
+ ]
14
+ tailscale_set_preferences = [
15
+ " --auto-update" ,
16
+ " --ssh" ,
17
+ " --advertise-connector" ,
18
+ " --advertise-exit-node" ,
19
+ " --advertise-routes=${ join (" ," , [
20
+ local . vpc_cidr_block ,
21
+ ])} " ,
22
+ ]
23
+
24
+ // Modify these to use your own VPC
25
+ vpc_cidr_block = module. vpc . vpc_cidr_block
26
+ vpc_id = module. vpc . vpc_id
27
+ subnet_id = module. vpc . public_subnets [0 ]
28
+ security_group_ids = [aws_security_group . tailscale . id ]
29
+ instance_type = " t4g.micro"
7
30
}
8
31
32
+ // Remove this to use your own VPC.
9
33
module "vpc" {
10
34
source = " ../internal-modules/aws-vpc"
11
35
12
36
name = local. name
13
- tags = local. tags
37
+ tags = local. aws_tags
14
38
15
39
cidr = " 10.0.80.0/22"
16
40
@@ -25,41 +49,59 @@ resource "tailscale_tailnet_key" "main" {
25
49
preauthorized = true
26
50
reusable = true
27
51
recreate_if_invalid = " always"
28
- tags = [
29
- " tag:example-infra" ,
30
- " tag:example-exitnode" ,
31
- " tag:example-subnetrouter" ,
32
- " tag:example-appconnector" ,
33
- ]
52
+ tags = local. tailscale_acl_tags
34
53
}
35
54
36
55
module "tailscale_aws_ec2" {
37
56
source = " ../internal-modules/aws-ec2-instance"
38
57
39
- instance_type = " t4g.micro "
40
- instance_tags = local. tags
58
+ instance_type = local . instance_type
59
+ instance_tags = local. aws_tags
41
60
42
- subnet_id = module. vpc . private_subnets [0 ]
43
- vpc_security_group_ids = [
44
- module . vpc . tailscale_security_group_id ,
45
- ]
46
- ipv6_address_count = 1
61
+ subnet_id = local. subnet_id
62
+ vpc_security_group_ids = local. security_group_ids
63
+ ipv6_address_count = 1
47
64
48
65
# Variables for Tailscale resources
49
- tailscale_hostname = local. name
50
- tailscale_auth_key = tailscale_tailnet_key. main . key
51
- tailscale_set_preferences = [
52
- " --auto-update" ,
53
- " --ssh" ,
54
- " --advertise-connector" ,
55
- " --advertise-exit-node" ,
56
- " --advertise-routes=${ join (" ," , [
57
- module . vpc . vpc_cidr_block ,
58
- module . vpc . vpc_ipv6_cidr_block ,
59
- ])} " ,
60
- ]
66
+ tailscale_hostname = local. name
67
+ tailscale_auth_key = tailscale_tailnet_key. main . key
68
+ tailscale_set_preferences = local. tailscale_set_preferences
61
69
62
70
depends_on = [
63
- module . vpc . natgw_ids , # ensure NAT gateway is available before instance provisioning - primarily for private subnets
71
+ module . vpc . natgw_ids , # remove if using your own VPC otherwise ensure provisioned NAT gateway is available
64
72
]
65
73
}
74
+
75
+ resource "aws_security_group" "tailscale" {
76
+ vpc_id = local. vpc_id
77
+ name = local. name
78
+ }
79
+
80
+ resource "aws_security_group_rule" "tailscale_ingress" {
81
+ security_group_id = aws_security_group. tailscale . id
82
+ type = " ingress"
83
+ from_port = 41641
84
+ to_port = 41641
85
+ protocol = " udp"
86
+ cidr_blocks = [" 0.0.0.0/0" ]
87
+ ipv6_cidr_blocks = [" ::/0" ]
88
+ }
89
+
90
+ resource "aws_security_group_rule" "egress" {
91
+ security_group_id = aws_security_group. tailscale . id
92
+ type = " egress"
93
+ from_port = 0
94
+ to_port = 0
95
+ protocol = " -1"
96
+ cidr_blocks = [" 0.0.0.0/0" ]
97
+ ipv6_cidr_blocks = [" ::/0" ]
98
+ }
99
+
100
+ resource "aws_security_group_rule" "internal_vpc_ingress_ipv4" {
101
+ security_group_id = aws_security_group. tailscale . id
102
+ type = " ingress"
103
+ from_port = 0
104
+ to_port = 0
105
+ protocol = " -1"
106
+ cidr_blocks = [local . vpc_cidr_block ]
107
+ }
0 commit comments