Skip to content

Commit fa87d64

Browse files
authored
Merge pull request #13 from masterpointio/feature/support-ssh
feat: adds SSH support + tagging + upgrades ssm-agent 1.0
2 parents e613a1a + f9b7b04 commit fa87d64

File tree

9 files changed

+80
-45
lines changed

9 files changed

+80
-45
lines changed

.trunk/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@
66
plugins
77
user_trunk.yaml
88
user.yaml
9+
tmp

.trunk/trunk.yaml

+15-10
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
# To learn more about the format of this file, see https://docs.trunk.io/reference/trunk-yaml
33
version: 0.1
44
cli:
5-
version: 1.17.2
5+
version: 1.20.0
66
plugins:
77
sources:
88
- id: trunk
9-
ref: v1.2.6
9+
ref: v1.4.3
1010
uri: https://github.com/trunk-io/plugins
1111
runtimes:
1212
enabled:
@@ -15,17 +15,22 @@ runtimes:
1515
1616
lint:
1717
enabled:
18-
18+
19+
1920
- git-diff-check
20-
- markdownlint@0.37.0
21-
- prettier@3.1.0
21+
- markdownlint@0.39.0
22+
- prettier@3.2.5
2223
2324
24-
25-
26-
27-
28-
25+
26+
27+
28+
29+
30+
ignore:
31+
- linters: [shellcheck]
32+
paths:
33+
- userdata.sh.tmpl
2934
actions:
3035
enabled:
3136
- trunk-announce

README.md

+4-4
Large diffs are not rendered by default.

aqua.yaml

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
# aqua - Declarative CLI Version Manager
3+
# https://aquaproj.github.io/
4+
# checksum:
5+
# enabled: true
6+
# require_checksum: true
7+
# supported_envs:
8+
# - all
9+
registries:
10+
- type: standard
11+
ref: v4.137.0 # renovate: depName=aquaproj/aqua-registry
12+
packages:
13+
- name: hashicorp/[email protected]
14+
- name: opentofu/[email protected]

examples/complete/main.tf

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# trunk-ignore-all(trivy/AVD-AWS-0178): We don't need have VPC Flow logs.
12
provider "aws" {
23
region = var.region
34
}

main.tf

+20-13
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,39 @@
11
locals {
2-
tailscale_tags = [for k, v in module.this.tags : "tag:${v}" if k == "Name"]
3-
userdata = templatefile("${path.module}/userdata.sh.tpl", {
4-
routes = join(",", var.advertise_routes)
5-
authkey = tailscale_tailnet_key.default.key
6-
hostname = module.this.id
2+
3+
primary_tag = coalesce(var.primary_tag, module.this.id)
4+
prefixed_primary_tag = "tag:${local.primary_tag}"
5+
prefixed_additional_tags = [for tag in var.additional_tags : "tag:${tag}"]
6+
tailscale_tags = concat([local.prefixed_primary_tag], local.prefixed_additional_tags)
7+
8+
userdata = templatefile("${path.module}/userdata.sh.tmpl", {
9+
routes = join(",", var.advertise_routes)
10+
authkey = tailscale_tailnet_key.default.key
11+
hostname = module.this.id
12+
tags = join(",", local.tailscale_tags)
13+
ssh_enabled = var.ssh_enabled
714
})
815
}
916

1017
module "tailscale_subnet_router" {
1118
source = "masterpointio/ssm-agent/aws"
12-
version = "0.17.0"
19+
version = "1.0.0"
1320

1421
context = module.this.context
1522
tags = module.this.tags
1623

17-
vpc_id = var.vpc_id
18-
subnet_ids = var.subnet_ids
19-
key_pair_name = var.key_pair_name
24+
vpc_id = var.vpc_id
25+
subnet_ids = var.subnet_ids
26+
key_pair_name = var.key_pair_name
27+
create_run_shell_document = var.create_run_shell_document
28+
2029
additional_security_group_ids = var.additional_security_group_ids
21-
create_run_shell_document = var.create_run_shell_document
2230

2331
session_logging_kms_key_alias = var.session_logging_kms_key_alias
2432
session_logging_enabled = var.session_logging_enabled
2533
session_logging_ssm_document_name = var.session_logging_ssm_document_name
2634

27-
ami = var.ami
28-
instance_type = var.instance_type
29-
instance_count = var.instance_count
35+
ami = var.ami
36+
instance_type = var.instance_type
3037

3138
monitoring_enabled = var.monitoring_enabled
3239
associate_public_ip_address = var.associate_public_ip_address

userdata.sh.tpl userdata.sh.tmpl

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

44
# Enable ip_forward to allow advertising routes
55
echo 'net.ipv4.ip_forward = 1' | sudo tee -a /etc/sysctl.conf
@@ -18,7 +18,10 @@ sudo systemctl enable --now tailscaled
1818
sleep 5
1919

2020
# Start tailscale
21+
# We pass --advertise-tags below even though the authkey being created with those tags should result
22+
# in the same effect. This is to be more explicit because tailscale tags are a complicated topic.
2123
sudo tailscale up \
22-
--advertise-routes=${routes} \
23-
--authkey=${authkey} \
24-
--hostname=${hostname}
24+
--advertise-routes=${routes} \
25+
--advertise-tags=${tags} \
26+
--authkey=${authkey} \
27+
--hostname=${hostname}%{ if ssh_enabled == true } --ssh%{ endif }

variables.tf

+18-6
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,6 @@ variable "instance_type" {
8686
description = "The instance type to use for the Tailscale Subnet Router EC2 instance."
8787
}
8888

89-
variable "instance_count" {
90-
default = 1
91-
type = number
92-
description = "The number of Tailscale Subnet Router EC2 instances you would like to deploy."
93-
}
94-
9589
variable "monitoring_enabled" {
9690
description = "Enable detailed monitoring of instances"
9791
type = bool
@@ -108,6 +102,24 @@ variable "associate_public_ip_address" {
108102
## Tailscale ##
109103
##############
110104

105+
variable "primary_tag" {
106+
default = null
107+
type = string
108+
description = "The primary tag to apply to the Tailscale Subnet Router machine. Do not include the `tag:` prefix. This must match the OAuth client's tag. If not provided, the module will use the module's ID as the primary tag, which is configured in context.tf"
109+
}
110+
111+
variable "additional_tags" {
112+
default = []
113+
type = list(string)
114+
description = "Additional Tailscale tags to apply to the Tailscale Subnet Router machine in addition to `primary_tag`. These should not include the `tag:` prefix."
115+
}
116+
117+
variable "ssh_enabled" {
118+
type = bool
119+
default = true
120+
description = "Enable SSH access to the Tailscale Subnet Router EC2 instance. Defaults to true."
121+
}
122+
111123
variable "advertise_routes" {
112124
default = []
113125
type = list(string)

versions.tf

-8
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,6 @@ terraform {
66
source = "hashicorp/aws"
77
version = ">= 4.0"
88
}
9-
local = {
10-
source = "hashicorp/local"
11-
version = ">= 1.2"
12-
}
13-
null = {
14-
source = "hashicorp/null"
15-
version = ">= 2.0"
16-
}
179
tailscale = {
1810
source = "tailscale/tailscale"
1911
version = ">= 0.13.7"

0 commit comments

Comments
 (0)