Skip to content

Commit 6ff5059

Browse files
authored
feat: support extra arguments (#28)
## what * Allows extra arguments to be passed to the Tailscale daemon and/or the `tailscale up` command. * Prints additional info in user data * Adds some `trivy` ignore rules. ## why * These extra args were added as a part of my work for ephemeral node support. Eventually, we don't need this for our case, but it would be nice to have in terms of long term maintainability. ## references * N/A
1 parent cabc4f6 commit 6ff5059

File tree

6 files changed

+133
-72
lines changed

6 files changed

+133
-72
lines changed

.trunk/configs/.prettierignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# `release-please` doesn't generate prettier compliant output, see relevant issues:
2+
# https://github.com/googleapis/release-please/issues/1902
3+
# https://github.com/googleapis/release-please/issues/1802
4+
CHANGELOG.md

.trunk/configs/.trivyignore

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Log group is not encrypted
2+
AVD-AWS-0017
3+
4+
# Bucket does not have versioning enabled
5+
AVD-AWS-0090
6+
7+
# Bucket does not encrypt data with a customer managed key
8+
AVD-AWS-0132

README.md

+68-62
Large diffs are not rendered by default.

main.tf

+16-4
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,30 @@ locals {
33
primary_tag = coalesce(var.primary_tag, module.this.id)
44
prefixed_primary_tag = "tag:${local.primary_tag}"
55
prefixed_additional_tags = [for tag in var.additional_tags : "tag:${tag}"]
6-
tailscale_tags = concat([local.prefixed_primary_tag], local.prefixed_additional_tags)
6+
7+
tailscale_tags = concat([local.prefixed_primary_tag], local.prefixed_additional_tags)
8+
9+
tailscaled_extra_flags_enabled = length(var.tailscaled_extra_flags) > 0
10+
tailscale_up_extra_flags_enabled = length(var.tailscale_up_extra_flags) > 0
711

812
userdata = templatefile("${path.module}/userdata.sh.tmpl", {
9-
routes = join(",", var.advertise_routes)
1013
authkey = tailscale_tailnet_key.default.key
14+
exit_node_enabled = var.exit_node_enabled
1115
hostname = module.this.id
12-
tags = join(",", local.tailscale_tags)
16+
routes = join(",", var.advertise_routes)
1317
ssh_enabled = var.ssh_enabled
14-
exit_node_enabled = var.exit_node_enabled
18+
tags = join(",", local.tailscale_tags)
19+
20+
tailscaled_extra_flags_enabled = local.tailscaled_extra_flags_enabled
21+
tailscaled_extra_flags = join(" ", var.tailscaled_extra_flags)
22+
tailscale_up_extra_flags_enabled = local.tailscale_up_extra_flags_enabled
23+
tailscale_up_extra_flags = join(" ", var.tailscale_up_extra_flags)
1524
})
1625
}
1726

27+
# Note: `trunk` ignores that this rule is already listed in `.trivyignore` file.
28+
# Bucket does not have versioning enabled
29+
# trivy:ignore:AVD-AWS-0090
1830
module "tailscale_subnet_router" {
1931
source = "masterpointio/ssm-agent/aws"
2032
version = "1.2.0"

userdata.sh.tmpl

+18-5
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,40 @@
11
#!/bin/bash -ex
22
exec > >(tee /var/log/user-data.log | logger -t user-data -s 2>/dev/console) 2>&1
33

4-
# Enable ip_forward to allow advertising routes
4+
echo "Starting user-data script..."
5+
6+
echo "Enabling IP forwarding..."
57
echo 'net.ipv4.ip_forward = 1' | sudo tee -a /etc/sysctl.conf
68
echo 'net.ipv6.conf.all.forwarding = 1' | sudo tee -a /etc/sysctl.conf
79
sudo sysctl -p /etc/sysctl.conf
810

9-
# Install tailscale
11+
echo "Installing Tailscale..."
1012
sudo yum install -y yum-utils
1113
sudo yum-config-manager --add-repo https://pkgs.tailscale.com/stable/amazon-linux/2/tailscale.repo
1214
sudo yum install -y tailscale
1315

16+
%{ if tailscaled_extra_flags_enabled == true }
17+
echo "Exporting FLAGS to environment variable..."
18+
export FLAGS=${tailscaled_extra_flags}%
19+
%{ endif }
20+
1421
# Setup tailscale
22+
echo "Enabling and starting tailscaled service..."
1523
sudo systemctl enable --now tailscaled
1624

17-
# Wait a few for tailscaled to come up
25+
echo "Waiting for tailscaled to initialize..."
1826
sleep 5
1927

2028
# Start tailscale
2129
# We pass --advertise-tags below even though the authkey being created with those tags should result
2230
# in the same effect. This is to be more explicit because tailscale tags are a complicated topic.
2331
sudo tailscale up \
32+
%{ if ssh_enabled == true }--ssh%{ endif } \
33+
%{ if exit_node_enabled == true }--advertise-exit-node%{ endif } \
34+
%{ if tailscale_up_extra_flags_enabled == true }${tailscale_up_extra_flags}%{ endif } \
2435
--advertise-routes=${routes} \
2536
--advertise-tags=${tags} \
26-
--authkey=${authkey} \
27-
--hostname=${hostname}%{ if ssh_enabled == true } --ssh%{ endif }%{ if exit_node_enabled == true } --advertise-exit-node%{ endif }
37+
--hostname=${hostname} \
38+
--authkey=${authkey}
39+
40+
echo "Tailscale setup completed."

variables.tf

+19-1
Original file line numberDiff line numberDiff line change
@@ -160,5 +160,23 @@ variable "ephemeral" {
160160
variable "reusable" {
161161
default = true
162162
type = bool
163-
description = " Indicates if the key is reusable or single-use."
163+
description = "Indicates if the key is reusable or single-use."
164+
}
165+
166+
variable "tailscaled_extra_flags" {
167+
default = []
168+
type = list(string)
169+
description = <<-EOT
170+
Extra flags to pass to Tailscale daemon for advanced configuration. Example: ["--state=mem:"]
171+
See more in the [docs](https://tailscale.com/kb/1278/tailscaled#flags-to-tailscaled).
172+
EOT
173+
}
174+
175+
variable "tailscale_up_extra_flags" {
176+
default = []
177+
type = list(string)
178+
description = <<-EOT
179+
Extra flags to pass to `tailscale up` for advanced configuration.
180+
See more in the [docs](https://tailscale.com/kb/1241/tailscale-up).
181+
EOT
164182
}

0 commit comments

Comments
 (0)