11locals {
22 name = " example-${ basename (path. cwd )} "
33
4- tags = {
4+ azure_tags = {
55 Name = local.name
66 }
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
734}
835
936resource "azurerm_resource_group" "main" {
1037 location = " centralus"
1138 name = local. name
1239}
1340
14- module "network " {
41+ module "vpc " {
1542 source = " ../internal-modules/azure-network"
1643
1744 name = local. name
18- tags = local. tags
45+ tags = local. azure_tags
1946
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
2249
2350 cidrs = [" 10.0.0.0/22" ]
2451 subnet_cidrs = [
@@ -39,40 +66,49 @@ resource "tailscale_tailnet_key" "main" {
3966 preauthorized = true
4067 reusable = true
4168 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
4870}
4971
5072module "tailscale_azure_linux_virtual_machine" {
5173 source = " ../internal-modules/azure-linux-vm"
5274
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
5577
5678 # 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
5881
5982 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
6386
6487 # 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
7491
7592 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
7794 ]
7895}
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