1
1
locals {
2
2
name = " example-${ basename (path. cwd )} "
3
3
4
- tags = {
4
+ azure_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 (" ," , coalescelist (
20
+ local. vpc_cidr_block ,
21
+ ))} " ,
22
+ ]
23
+
24
+ // Modify these to use your own VPC
25
+ resource_group_name = azurerm_resource_group. main . name
26
+ location = azurerm_resource_group. main . location
27
+
28
+ vpc_cidr_block = module. vpc . vnet_address_space
29
+ vpc_id = module. vpc . vnet_id
30
+ subnet_id = module. vpc . public_subnet_id
31
+ network_security_group_id = azurerm_network_security_group. tailscale_ingress . id
32
+ instance_type = " Standard_DS1_v2"
33
+ admin_public_key_path = var. admin_public_key_path
7
34
}
8
35
9
36
resource "azurerm_resource_group" "main" {
10
37
location = " centralus"
11
38
name = local. name
12
39
}
13
40
14
- module "network " {
41
+ module "vpc " {
15
42
source = " ../internal-modules/azure-network"
16
43
17
44
name = local. name
18
- tags = local. tags
45
+ tags = local. azure_tags
19
46
20
- location = azurerm_resource_group . main . location
21
- resource_group_name = azurerm_resource_group . main . name
47
+ location = local . location
48
+ resource_group_name = local . resource_group_name
22
49
23
50
cidrs = [" 10.0.0.0/22" ]
24
51
subnet_cidrs = [
@@ -39,40 +66,49 @@ resource "tailscale_tailnet_key" "main" {
39
66
preauthorized = true
40
67
reusable = true
41
68
recreate_if_invalid = " always"
42
- tags = [
43
- " tag:example-infra" ,
44
- " tag:example-exitnode" ,
45
- " tag:example-subnetrouter" ,
46
- " tag:example-appconnector" ,
47
- ]
69
+ tags = local. tailscale_acl_tags
48
70
}
49
71
50
72
module "tailscale_azure_linux_virtual_machine" {
51
73
source = " ../internal-modules/azure-linux-vm"
52
74
53
- location = azurerm_resource_group . main . location
54
- resource_group_name = azurerm_resource_group . main . name
75
+ location = local . location
76
+ resource_group_name = local . resource_group_name
55
77
56
78
# public subnet
57
- primary_subnet_id = module. network . public_subnet_id
79
+ primary_subnet_id = local. subnet_id
80
+ network_security_group_id = local. network_security_group_id
58
81
59
82
machine_name = local. name
60
- machine_size = " Standard_DS1_v2 "
61
- admin_public_key_path = var . admin_public_key_path
62
- resource_tags = local. tags
83
+ machine_size = local . instance_type
84
+ admin_public_key_path = local . admin_public_key_path
85
+ resource_tags = local. azure_tags
63
86
64
87
# Variables for Tailscale resources
65
- tailscale_hostname = local. name
66
- tailscale_auth_key = tailscale_tailnet_key. main . key
67
- tailscale_set_preferences = [
68
- " --auto-update" ,
69
- " --ssh" ,
70
- " --advertise-connector" ,
71
- " --advertise-exit-node" ,
72
- " --advertise-routes=${ join (" ," , module. network . vnet_address_space )} " ,
73
- ]
88
+ tailscale_hostname = local. name
89
+ tailscale_auth_key = tailscale_tailnet_key. main . key
90
+ tailscale_set_preferences = local. tailscale_set_preferences
74
91
75
92
depends_on = [
76
- module . network . natgw_ids , # for private subnets - ensure NAT gateway is available before instance provisioning
93
+ module . vpc . nat_ids , # remove if using your own VPC otherwise ensure provisioned NAT gateway is available
77
94
]
78
95
}
96
+
97
+ resource "azurerm_network_security_group" "tailscale_ingress" {
98
+ location = local. location
99
+ resource_group_name = local. resource_group_name
100
+
101
+ name = " nsg-tailscale-ingress"
102
+
103
+ security_rule {
104
+ name = " AllowTailscaleInbound"
105
+ access = " Allow"
106
+ direction = " Inbound"
107
+ priority = 100
108
+ protocol = " Udp"
109
+ source_address_prefix = " Internet"
110
+ source_port_range = " *"
111
+ destination_address_prefix = " *"
112
+ destination_port_range = " 41641"
113
+ }
114
+ }
0 commit comments