Skip to content

Commit 283d310

Browse files
authored
terraform: azure, google - usability improvements (#24)
closes #22
1 parent 5dc08a0 commit 283d310

File tree

14 files changed

+165
-132
lines changed

14 files changed

+165
-132
lines changed

terraform/aws/aws-ec2-autoscaling-dual-subnet/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ module "tailscale_aws_ec2_autoscaling" {
9090
tailscale_set_preferences = local.tailscale_set_preferences
9191

9292
depends_on = [
93-
module.vpc.natgw_ids, # remove if using your own VPC otherwise ensure provisioned NAT gateway is available
93+
module.vpc.nat_ids, # remove if using your own VPC otherwise ensure provisioned NAT gateway is available
9494
]
9595
}
9696

terraform/aws/aws-ec2-autoscaling-session-recorder/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ module "tailscale_aws_ec2_autoscaling" {
190190
]
191191

192192
depends_on = [
193-
module.vpc.natgw_ids, # remove if using your own VPC otherwise ensure provisioned NAT gateway is available
193+
module.vpc.nat_ids, # remove if using your own VPC otherwise ensure provisioned NAT gateway is available
194194
]
195195
}
196196

terraform/aws/aws-ec2-autoscaling/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ module "tailscale_aws_ec2_autoscaling" {
7878
tailscale_set_preferences = local.tailscale_set_preferences
7979

8080
depends_on = [
81-
module.vpc.natgw_ids, # remove if using your own VPC otherwise ensure provisioned NAT gateway is available
81+
module.vpc.nat_ids, # remove if using your own VPC otherwise ensure provisioned NAT gateway is available
8282
]
8383
}
8484

terraform/aws/aws-ec2-instance-dual-stack-ipv4-ipv6/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ module "tailscale_aws_ec2" {
6868
tailscale_set_preferences = local.tailscale_set_preferences
6969

7070
depends_on = [
71-
module.vpc.natgw_ids, # remove if using your own VPC otherwise ensure provisioned NAT gateway is available
71+
module.vpc.nat_ids, # remove if using your own VPC otherwise ensure provisioned NAT gateway is available
7272
]
7373
}
7474

terraform/aws/aws-ec2-instance/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ module "tailscale_aws_ec2" {
6565
tailscale_set_preferences = local.tailscale_set_preferences
6666

6767
depends_on = [
68-
module.vpc.natgw_ids, # remove if using your own VPC otherwise ensure provisioned NAT gateway is available
68+
module.vpc.nat_ids, # remove if using your own VPC otherwise ensure provisioned NAT gateway is available
6969
]
7070
}
7171

terraform/aws/internal-modules/aws-vpc/outputs.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ output "nat_public_ips" {
2525
value = module.vpc.nat_public_ips
2626
}
2727

28-
output "natgw_ids" {
28+
output "nat_ids" {
2929
description = "Useful for using within `depends_on` for other resources"
30-
value = module.vpc.natgw_ids
30+
value = module.vpc.nat_ids
3131
}
3232

3333
output "public_route_table_ids" {
Lines changed: 63 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,51 @@
11
locals {
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

936
resource "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

5072
module "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+
}

terraform/azure/azure-linux-vm/outputs.tf

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
output "vpc_id" {
2-
value = module.network.vnet_id
2+
value = module.vpc.vnet_id
33
}
44

55
output "nat_public_ips" {
6-
value = module.network.nat_public_ips
6+
value = module.vpc.nat_public_ips
77
}
88

99
output "public_subnet_id" {
10-
value = module.network.public_subnet_id
10+
value = module.vpc.public_subnet_id
1111
}
1212
output "private_subnet_id" {
13-
value = module.network.private_subnet_id
13+
value = module.vpc.private_subnet_id
1414
}
1515

1616
output "private_dns_resolver_inbound_endpoint_ip" {
17-
value = module.network.private_dns_resolver_inbound_endpoint_ip
17+
value = module.vpc.private_dns_resolver_inbound_endpoint_ip
1818
}
1919
output "internal_domain_name_suffix" {
2020
value = module.tailscale_azure_linux_virtual_machine.internal_domain_name_suffix

terraform/azure/internal-modules/azure-linux-vm/main.tf

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -28,26 +28,7 @@ resource "azurerm_network_interface" "primary" {
2828

2929
resource "azurerm_network_interface_security_group_association" "tailscale" {
3030
network_interface_id = azurerm_network_interface.primary.id
31-
network_security_group_id = azurerm_network_security_group.tailscale_ingress.id
32-
}
33-
34-
resource "azurerm_network_security_group" "tailscale_ingress" {
35-
location = var.location
36-
resource_group_name = var.resource_group_name
37-
38-
name = "nsg-tailscale-ingress"
39-
40-
security_rule {
41-
name = "AllowTailscaleInbound"
42-
access = "Allow"
43-
direction = "Inbound"
44-
priority = 100
45-
protocol = "Udp"
46-
source_address_prefix = "Internet"
47-
source_port_range = "*"
48-
destination_address_prefix = "*"
49-
destination_port_range = "41641"
50-
}
31+
network_security_group_id = var.network_security_group_id
5132
}
5233

5334
resource "azurerm_linux_virtual_machine" "tailscale_instance" {

terraform/azure/internal-modules/azure-linux-vm/variables.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ variable "primary_subnet_id" {
2525
description = "The primary subnet (typically PUBLIC) to assign to the virtual machine"
2626
type = string
2727
}
28+
variable "network_security_group_id" {
29+
description = "The network security group to assign to the virtual machine"
30+
type = string
31+
}
2832
variable "machine_size" {
2933
description = "The machine size to assign the virtual machine"
3034
type = string

0 commit comments

Comments
 (0)