Skip to content
This repository was archived by the owner on Jul 20, 2024. It is now read-only.

Commit 7caf229

Browse files
authored
Add extra_user_data option (#6)
1 parent 45141ba commit 7caf229

File tree

5 files changed

+18
-1
lines changed

5 files changed

+18
-1
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ This is an open source software. Feel free to open issues and pull requests.
102102

103103
| Name | Description | Type | Default | Required |
104104
|------|-------------|:----:|:-----:|:-----:|
105+
| extra\_user\_data | Extra script to run in the NAT instance | string | `""` | no |
105106
| image\_id | AMI of the NAT instance. Default to the latest Amazon Linux 2 | string | `""` | no |
106107
| instance\_types | Candidates of spot instance type for the NAT instance. This is used in the mixed instances policy | list | `[ "t3.nano", "t3a.nano" ]` | no |
107108
| key\_name | Name of the key pair for the NAT instance. You can set this to assign the key pair to the NAT instance | string | `""` | no |
@@ -118,6 +119,7 @@ This is an open source software. Feel free to open issues and pull requests.
118119
| eip\_id | ID of the Elastic IP |
119120
| eip\_public\_ip | Public IP of the Elastic IP for the NAT instance |
120121
| eni\_id | ID of the ENI for the NAT instance |
122+
| eni\_private\_ip | Private IP of the ENI for the NAT instance |
121123
| iam\_role\_name | Name of the IAM role for the NAT instance |
122124
| sg\_id | ID of the security group of the NAT instance |
123125

data/init.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,6 @@ iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE
1818

1919
# Switch the default route to eth1
2020
ip route del default dev eth0
21+
22+
# Run the extra script if set
23+
${extra_user_data}

main.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ resource "aws_launch_template" "this" {
9292

9393
user_data = base64encode(
9494
templatefile("${path.module}/data/init.sh", {
95-
eni_id = aws_network_interface.this.id
95+
eni_id = aws_network_interface.this.id
96+
extra_user_data = var.extra_user_data
9697
})
9798
)
9899

outputs.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ output "eni_id" {
1313
value = "${aws_network_interface.this.id}"
1414
}
1515

16+
output "eni_private_ip" {
17+
description = "Private IP of the ENI for the NAT instance"
18+
# workaround of https://github.com/terraform-providers/terraform-provider-aws/issues/7522
19+
value = "${tolist(aws_network_interface.this.private_ips)[0]}"
20+
}
21+
1622
output "sg_id" {
1723
description = "ID of the security group of the NAT instance"
1824
value = "${aws_security_group.this.id}"

variables.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ variable "private_route_table_ids" {
1919
default = []
2020
}
2121

22+
variable "extra_user_data" {
23+
description = "Extra script to run in the NAT instance"
24+
default = ""
25+
}
26+
2227
variable "image_id" {
2328
description = "AMI of the NAT instance. Default to the latest Amazon Linux 2"
2429
default = ""

0 commit comments

Comments
 (0)