Skip to content

Commit 70a907d

Browse files
committed
use cloudinit module
1 parent 73ab219 commit 70a907d

File tree

3 files changed

+30
-46
lines changed

3 files changed

+30
-46
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@
2424

2525
## Modules
2626

27-
No modules.
27+
| Name | Source | Version |
28+
|------|--------|---------|
29+
| <a name="module_amz-tailscale-client"></a> [amz-tailscale-client](#module\_amz-tailscale-client) | lbrlabs/tailscale/cloudinit | 0.0.4 |
2830

2931
## Outputs
3032

@@ -35,7 +37,6 @@ No outputs.
3537
| Name | Version |
3638
|------|---------|
3739
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.30 |
38-
| <a name="provider_cloudinit"></a> [cloudinit](#provider\_cloudinit) | >= 2.0 |
3940

4041
## Requirements
4142

@@ -61,5 +62,4 @@ No outputs.
6162
| [aws_ssm_parameter.tailnet_key](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ssm_parameter) | resource |
6263
| [aws_ami.main](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/ami) | data source |
6364
| [aws_iam_policy_document.main](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
64-
| [cloudinit_config.main](https://registry.terraform.io/providers/hashicorp/cloudinit/latest/docs/data-sources/config) | data source |
6565
<!-- END_TF_DOCS -->

ec2.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ resource "aws_launch_template" "main" {
4141
name = aws_iam_instance_profile.main.name
4242
}
4343

44-
user_data = data.cloudinit_config.main.rendered
44+
user_data = module.amz-tailscale-client.rendered
4545

4646

4747

user_data.tf

Lines changed: 26 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,27 @@
1-
data "cloudinit_config" "main" {
2-
gzip = false
3-
base64_encode = true
4-
5-
part {
6-
filename = "kernel.sh"
7-
content_type = "text/x-shellscript"
8-
9-
content = file("${path.module}/files/kernel.sh")
10-
}
11-
12-
part {
13-
filename = "ssm.sh"
14-
content_type = "text/x-shellscript"
15-
16-
content = file("${path.module}/files/ssm.sh")
17-
}
18-
19-
part {
20-
filename = "tailscale.sh"
21-
content_type = "text/x-shellscript"
22-
23-
content = templatefile("${path.module}/templates/tailscale.sh.tmpl", {
24-
AWS_SSM_PARAM_NAME = aws_ssm_parameter.tailnet_key.name
25-
ADVERTISE_ROUTES = join(",", var.advertise_addresses)
26-
ADVERTISE_TAGS = join(",", var.advertise_tags)
27-
HOSTNAME = var.name
28-
TAILSCALE_SSH = var.enable_tailscale_ssh
29-
})
30-
}
31-
32-
part {
33-
filename = "network.sh"
34-
content_type = "text/x-shellscript"
35-
36-
content = templatefile("${path.module}/templates/network.sh.tmpl", {
37-
ENI_ID = aws_network_interface.main.id
38-
HOSTNAME = var.name
39-
})
40-
}
41-
42-
1+
module "amz-tailscale-client" {
2+
source = "lbrlabs/tailscale/cloudinit"
3+
version = "0.0.4"
4+
auth_key = var.tailscale_auth_key
5+
enable_ssh = true
6+
hostname = var.name
7+
advertise_tags = var.advertise_tags
8+
advertise_routes = var.advertise_addresses
9+
accept_routes = true
10+
max_retries = 10
11+
retry_delay = 10
12+
additional_parts = [
13+
{
14+
filename = "ssm.sh"
15+
content_type = "text/x-shellscript"
16+
content = file("${path.module}/files/ssm.sh")
17+
},
18+
{
19+
filename = "network.sh"
20+
content_type = "text/x-shellscript"
21+
content = templatefile("${path.module}/templates/network.sh.tmpl", {
22+
ENI_ID = aws_network_interface.main.id
23+
HOSTNAME = var.name
24+
})
25+
}
26+
]
4327
}

0 commit comments

Comments
 (0)