Skip to content

Commit f285e30

Browse files
authored
Merge pull request #5 from masterpointio/fix/remove_obsolete_data_source
fix: replace data source of archived provider with 'templatefile' function
2 parents 90cb315 + 312dd25 commit f285e30

File tree

3 files changed

+43
-27
lines changed

3 files changed

+43
-27
lines changed

README.md

+7-12
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22

33
# terraform-aws-tailscale [![Latest Release](https://img.shields.io/github/release/masterpointio/terraform-aws-tailscale.svg)](https://github.com/masterpointio/terraform-aws-tailscale/releases/latest)
44

5-
[![README Header][readme_header_img]][readme_header_link]
6-
7-
85
This is a Terraform Module to create a simple, autoscaled [Tailscale Subnet Router](https://tailscale.com/kb/1019/subnets/) on EC2 instance along with generated auth key, and its corresponding IAM resources. The instance should cycle itself on a schedule.
96

107
It's 100% Open Source and licensed under the [APACHE2](LICENSE).
@@ -46,7 +43,6 @@ Here is an example of using this module:
4643
| Name | Version |
4744
|------|---------|
4845
| <a name="provider_tailscale"></a> [tailscale](#provider\_tailscale) | >= 0.13.7 |
49-
| <a name="provider_template"></a> [template](#provider\_template) | n/a |
5046

5147
## Modules
5248

@@ -60,15 +56,14 @@ Here is an example of using this module:
6056
| Name | Type |
6157
|------|------|
6258
| [tailscale_tailnet_key.default](https://registry.terraform.io/providers/tailscale/tailscale/latest/docs/resources/tailnet_key) | resource |
63-
| [template_file.userdata](https://registry.terraform.io/providers/hashicorp/template/latest/docs/data-sources/file) | data source |
6459

6560
## Inputs
6661

6762
| Name | Description | Type | Default | Required |
6863
|------|-------------|------|---------|:--------:|
6964
| <a name="input_additional_tag_map"></a> [additional\_tag\_map](#input\_additional\_tag\_map) | Additional key-value pairs to add to each map in `tags_as_list_of_maps`. Not added to `tags` or `id`.<br>This is for some rare cases where resources want additional configuration of tags<br>and therefore take a list of maps with tag key, value, and additional configuration. | `map(string)` | `{}` | no |
70-
| <a name="input_advertise_routes"></a> [advertise\_routes](#input\_advertise\_routes) | The routes (expressed as CIDRs) to advertise as part of the Tailscale Subnet Router. e.g. [ '10.0.2.0/24', '10.0.1.0/24 ] | `list(string)` | `[]` | no |
71-
| <a name="input_ami"></a> [ami](#input\_ami) | The AMI to use for the Tailscale Subnet Router EC2 instance. If not provided, the latest Amazon Linux 2 AMI will be used. Note: This will update periodically as AWS releases updates to their AL2 AMI. Pin to a specific AMI if you would like to avoid these updates. | `string` | `""` | no |
65+
| <a name="input_advertise_routes"></a> [advertise\_routes](#input\_advertise\_routes) | The routes (expressed as CIDRs) to advertise as part of the Tailscale Subnet Router.<br> Example: ["10.0.2.0/24", "0.0.1.0/24"] | `list(string)` | `[]` | no |
66+
| <a name="input_ami"></a> [ami](#input\_ami) | The AMI to use for the Tailscale Subnet Router EC2 instance.<br> If not provided, the latest Amazon Linux 2 AMI will be used.<br> Note: This will update periodically as AWS releases updates to their AL2 AMI.<br> Pin to a specific AMI if you would like to avoid these updates. | `string` | `""` | no |
7267
| <a name="input_attributes"></a> [attributes](#input\_attributes) | ID element. Additional attributes (e.g. `workers` or `cluster`) to add to `id`,<br>in the order they appear in the list. New attributes are appended to the<br>end of the list. The elements of the list are joined by the `delimiter`<br>and treated as a single ID element. | `list(string)` | `[]` | no |
7368
| <a name="input_context"></a> [context](#input\_context) | Single object for setting entire context at once.<br>See description of individual variables for details.<br>Leave string and numeric variables as `null` to use default value.<br>Individual variable settings (non-null) override settings in context object,<br>except for attributes, tags, and additional\_tag\_map, which are merged. | `any` | <pre>{<br> "additional_tag_map": {},<br> "attributes": [],<br> "delimiter": null,<br> "descriptor_formats": {},<br> "enabled": true,<br> "environment": null,<br> "id_length_limit": null,<br> "label_key_case": null,<br> "label_order": [],<br> "label_value_case": null,<br> "labels_as_tags": [<br> "unset"<br> ],<br> "name": null,<br> "namespace": null,<br> "regex_replace_chars": null,<br> "stage": null,<br> "tags": {},<br> "tenant": null<br>}</pre> | no |
7469
| <a name="input_create_run_shell_document"></a> [create\_run\_shell\_document](#input\_create\_run\_shell\_document) | Whether or not to create the SSM-SessionManagerRunShell SSM Document. | `bool` | `true` | no |
@@ -79,7 +74,7 @@ Here is an example of using this module:
7974
| <a name="input_ephemeral"></a> [ephemeral](#input\_ephemeral) | Indicates if the key is ephemeral. | `bool` | `false` | no |
8075
| <a name="input_expiry"></a> [expiry](#input\_expiry) | The expiry of the auth key in seconds. | `number` | `7776000` | no |
8176
| <a name="input_id_length_limit"></a> [id\_length\_limit](#input\_id\_length\_limit) | Limit `id` to this many characters (minimum 6).<br>Set to `0` for unlimited length.<br>Set to `null` for keep the existing setting, which defaults to `0`.<br>Does not affect `id_full`. | `number` | `null` | no |
82-
| <a name="input_instance_count"></a> [instance\_count](#input\_instance\_count) | The number of Tailscale Subnet Router EC2 instances you would like to deploy. | `number` | `1` | no |
77+
| <a name="input_instance_count"></a> [instance\_count](#input\_instance\_count) | The number of Tailscale Subnet Router EC2 instances you would like to deploy. | `number` | `1` | no |
8378
| <a name="input_instance_type"></a> [instance\_type](#input\_instance\_type) | The instance type to use for the Tailscale Subnet Router EC2 instance. | `string` | `"t3.nano"` | no |
8479
| <a name="input_key_pair_name"></a> [key\_pair\_name](#input\_key\_pair\_name) | The name of the key-pair to associate with the Tailscale Subnet Router EC2 instance. | `string` | `null` | no |
8580
| <a name="input_label_key_case"></a> [label\_key\_case](#input\_label\_key\_case) | Controls the letter case of the `tags` keys (label names) for tags generated by this module.<br>Does not affect keys of tags passed in via the `tags` input.<br>Possible values: `lower`, `title`, `upper`.<br>Default value: `title`. | `string` | `null` | no |
@@ -91,14 +86,14 @@ Here is an example of using this module:
9186
| <a name="input_preauthorized"></a> [preauthorized](#input\_preauthorized) | Determines whether or not the machines authenticated by the key will be authorized for the tailnet by default. | `bool` | `true` | no |
9287
| <a name="input_regex_replace_chars"></a> [regex\_replace\_chars](#input\_regex\_replace\_chars) | Terraform regular expression (regex) string.<br>Characters matching the regex will be removed from the ID elements.<br>If not set, `"/[^a-zA-Z0-9-]/"` is used to remove all characters other than hyphens, letters and digits. | `string` | `null` | no |
9388
| <a name="input_reusable"></a> [reusable](#input\_reusable) | Indicates if the key is reusable or single-use. | `bool` | `true` | no |
94-
| <a name="input_session_logging_enabled"></a> [session\_logging\_enabled](#input\_session\_logging\_enabled) | To enable CloudWatch and S3 session logging or not. Note this does not apply to SSH sessions as AWS cannot log those sessions. | `bool` | `true` | no |
95-
| <a name="input_session_logging_kms_key_alias"></a> [session\_logging\_kms\_key\_alias](#input\_session\_logging\_kms\_key\_alias) | Alias name for `session_logging` KMS Key. This is only applied if 2 conditions are met: (1) `session_logging_kms_key_arn` is unset, (2) `session_logging_encryption_enabled` = true. | `string` | `"alias/session_logging"` | no |
96-
| <a name="input_session_logging_ssm_document_name"></a> [session\_logging\_ssm\_document\_name](#input\_session\_logging\_ssm\_document\_name) | Name for `session_logging` SSM document. This is only applied if 2 conditions are met: (1) `session_logging_enabled` = true, (2) `create_run_shell_document` = true. | `string` | `"SSM-SessionManagerRunShell-Tailscale"` | no |
89+
| <a name="input_session_logging_enabled"></a> [session\_logging\_enabled](#input\_session\_logging\_enabled) | To enable CloudWatch and S3 session logging or not.<br> Note this does not apply to SSH sessions as AWS cannot log those sessions. | `bool` | `true` | no |
90+
| <a name="input_session_logging_kms_key_alias"></a> [session\_logging\_kms\_key\_alias](#input\_session\_logging\_kms\_key\_alias) | Alias name for `session_logging` KMS Key.<br> This is only applied if 2 conditions are met: (1) `session_logging_kms_key_arn` is unset,<br> (2) `session_logging_encryption_enabled` = true. | `string` | `"alias/session_logging"` | no |
91+
| <a name="input_session_logging_ssm_document_name"></a> [session\_logging\_ssm\_document\_name](#input\_session\_logging\_ssm\_document\_name) | Name for `session_logging` SSM document.<br> This is only applied if 2 conditions are met: (1) `session_logging_enabled` = true,<br> (2) `create_run_shell_document` = true. | `string` | `"SSM-SessionManagerRunShell-Tailscale"` | no |
9792
| <a name="input_stage"></a> [stage](#input\_stage) | ID element. Usually used to indicate role, e.g. 'prod', 'staging', 'source', 'build', 'test', 'deploy', 'release' | `string` | `null` | no |
9893
| <a name="input_subnet_ids"></a> [subnet\_ids](#input\_subnet\_ids) | The Subnet IDs which the Tailscale Subnet Router EC2 instance will run in. These *should* be private subnets. | `list(string)` | n/a | yes |
9994
| <a name="input_tags"></a> [tags](#input\_tags) | Additional tags (e.g. `{'BusinessUnit': 'XYZ'}`).<br>Neither the tag keys nor the tag values will be modified by this module. | `map(string)` | `{}` | no |
10095
| <a name="input_tenant"></a> [tenant](#input\_tenant) | ID element \_(Rarely used, not included by default)\_. A customer identifier, indicating who this instance of a resource is for | `string` | `null` | no |
101-
| <a name="input_user_data"></a> [user\_data](#input\_user\_data) | The user\_data to use for the Tailscale Subnet Router EC2 instance. You can use this to automate installation of all the required command line tools. | `string` | `""` | no |
96+
| <a name="input_user_data"></a> [user\_data](#input\_user\_data) | The user\_data to use for the Tailscale Subnet Router EC2 instance.<br> You can use this to automate installation of all the required command line tools. | `string` | `""` | no |
10297
| <a name="input_vpc_id"></a> [vpc\_id](#input\_vpc\_id) | The ID of the VPC which the Tailscale Subnet Router EC2 instance will run in. | `string` | n/a | yes |
10398

10499
## Outputs

main.tf

+3-7
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
locals {
22
tailscale_tags = [for k, v in module.this.tags : "tag:${v}" if k == "Name"]
3-
}
4-
5-
data "template_file" "userdata" {
6-
template = file("${path.module}/userdata.sh.tpl")
7-
vars = {
3+
userdata = templatefile("${path.module}/userdata.sh.tpl", {
84
routes = join(",", var.advertise_routes)
95
authkey = tailscale_tailnet_key.default.key
106
hostname = module.this.id
11-
}
7+
})
128
}
139

1410
module "tailscale_subnet_router" {
@@ -31,7 +27,7 @@ module "tailscale_subnet_router" {
3127
instance_type = var.instance_type
3228
instance_count = var.instance_count
3329

34-
user_data = base64encode(length(var.user_data) > 0 ? var.user_data : data.template_file.userdata.rendered)
30+
user_data = base64encode(length(var.user_data) > 0 ? var.user_data : local.userdata)
3531
}
3632

3733
resource "tailscale_tailnet_key" "default" {

variables.tf

+33-8
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,31 @@ variable "create_run_shell_document" {
2121
variable "session_logging_enabled" {
2222
default = true
2323
type = bool
24-
description = "To enable CloudWatch and S3 session logging or not. Note this does not apply to SSH sessions as AWS cannot log those sessions."
24+
description = <<EOF
25+
To enable CloudWatch and S3 session logging or not.
26+
Note this does not apply to SSH sessions as AWS cannot log those sessions.
27+
EOF
2528
}
2629

2730
variable "session_logging_kms_key_alias" {
2831
default = "alias/session_logging"
2932
type = string
30-
description = "Alias name for `session_logging` KMS Key. This is only applied if 2 conditions are met: (1) `session_logging_kms_key_arn` is unset, (2) `session_logging_encryption_enabled` = true."
33+
description = <<EOF
34+
Alias name for `session_logging` KMS Key.
35+
This is only applied if 2 conditions are met: (1) `session_logging_kms_key_arn` is unset,
36+
(2) `session_logging_encryption_enabled` = true.
37+
EOF
3138
}
3239

3340

3441
variable "session_logging_ssm_document_name" {
3542
default = "SSM-SessionManagerRunShell-Tailscale"
3643
type = string
37-
description = "Name for `session_logging` SSM document. This is only applied if 2 conditions are met: (1) `session_logging_enabled` = true, (2) `create_run_shell_document` = true."
44+
description = <<EOF
45+
Name for `session_logging` SSM document.
46+
This is only applied if 2 conditions are met: (1) `session_logging_enabled` = true,
47+
(2) `create_run_shell_document` = true.
48+
EOF
3849
}
3950

4051
variable "key_pair_name" {
@@ -46,13 +57,21 @@ variable "key_pair_name" {
4657
variable "user_data" {
4758
default = ""
4859
type = string
49-
description = "The user_data to use for the Tailscale Subnet Router EC2 instance. You can use this to automate installation of all the required command line tools."
60+
description = <<EOF
61+
The user_data to use for the Tailscale Subnet Router EC2 instance.
62+
You can use this to automate installation of all the required command line tools.
63+
EOF
5064
}
5165

5266
variable "ami" {
5367
default = ""
5468
type = string
55-
description = "The AMI to use for the Tailscale Subnet Router EC2 instance. If not provided, the latest Amazon Linux 2 AMI will be used. Note: This will update periodically as AWS releases updates to their AL2 AMI. Pin to a specific AMI if you would like to avoid these updates."
69+
description = <<EOF
70+
The AMI to use for the Tailscale Subnet Router EC2 instance.
71+
If not provided, the latest Amazon Linux 2 AMI will be used.
72+
Note: This will update periodically as AWS releases updates to their AL2 AMI.
73+
Pin to a specific AMI if you would like to avoid these updates.
74+
EOF
5675
}
5776

5877
variable "instance_type" {
@@ -64,7 +83,7 @@ variable "instance_type" {
6483
variable "instance_count" {
6584
default = 1
6685
type = number
67-
description = "The number of Tailscale Subnet Router EC2 instances you would like to deploy."
86+
description = "The number of Tailscale Subnet Router EC2 instances you would like to deploy."
6887
}
6988

7089
################
@@ -74,7 +93,14 @@ variable "instance_count" {
7493
variable "advertise_routes" {
7594
default = []
7695
type = list(string)
77-
description = "The routes (expressed as CIDRs) to advertise as part of the Tailscale Subnet Router. e.g. [ '10.0.2.0/24', '10.0.1.0/24 ]"
96+
description = <<EOF
97+
The routes (expressed as CIDRs) to advertise as part of the Tailscale Subnet Router.
98+
Example: ["10.0.2.0/24", "0.0.1.0/24"]
99+
EOF
100+
validation {
101+
condition = can([for route in var.advertise_routes : cidrsubnet(route, 0, 0)])
102+
error_message = "All elements in the list must be valid CIDR blocks."
103+
}
78104
}
79105

80106
variable "expiry" {
@@ -83,7 +109,6 @@ variable "expiry" {
83109
description = "The expiry of the auth key in seconds."
84110
}
85111

86-
87112
variable "preauthorized" {
88113
default = true
89114
type = bool

0 commit comments

Comments
 (0)