Skip to content

Commit 6cd1838

Browse files
authored
terraform, aws: comment instance_refresh on asg (#12)
Uncomment to allow ASG to replace the instance. It will take several minutes as the ASG will try to launch a replacement instance before ENIs have been released.
1 parent 8ad515a commit 6cd1838

File tree

4 files changed

+17
-6
lines changed

4 files changed

+17
-6
lines changed

terraform/aws/aws-ec2-autoscaling-dual-subnet/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ This module creates the following:
1919

2020
## Considerations
2121

22+
- The Auto Scaling Group does not define an `instance_refresh` policy as the ASG cannot do a rolling restart with externally manaaged network interfaces (ENIs) as required by this configuration. To update instances to the latest launch template, terminate instances in the ASG in the AWS Console or programmatically. This will release the ENI so the replacement instance can use it.
2223
- Any advertised routes and exit nodes must still be approved in the Tailscale Admin Console. The code can be updated to use [Auto Approvers for routes](https://tailscale.com/kb/1018/acls/#auto-approvers-for-routes-and-exit-nodes) if this is configured in your ACLs.
2324

2425
## To use

terraform/aws/aws-ec2-autoscaling/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ This example creates the following:
99

1010
## Considerations
1111

12+
- The Auto Scaling Group does not define an `instance_refresh` policy as the ASG cannot do a rolling restart with externally manaaged network interfaces (ENIs) as required by this configuration. To update instances to the latest launch template, terminate instances in the ASG in the AWS Console or programmatically. This will release the ENI so the replacement instance can use it.
1213
- Any advertised routes and exit nodes must still be approved in the Tailscale Admin Console. The code can be updated to use [Auto Approvers for routes](https://tailscale.com/kb/1018/acls/#auto-approvers-for-routes-and-exit-nodes) if this is configured in your ACLs.
1314

1415
## To use

terraform/aws/internal-modules/aws-ec2-autoscaling/main.tf

+14-5
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,11 @@ resource "aws_launch_template" "tailscale" {
5353
instance_type = var.instance_type
5454
key_name = var.instance_key_name
5555

56-
iam_instance_profile {
57-
name = var.instance_profile_name
56+
dynamic "iam_instance_profile" {
57+
for_each = var.instance_profile_name != "" ? [1] : []
58+
content {
59+
name = var.instance_profile_name
60+
}
5861
}
5962

6063
metadata_options {
@@ -63,6 +66,7 @@ resource "aws_launch_template" "tailscale" {
6366
}
6467

6568
dynamic "network_interfaces" {
69+
# https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/scenarios-enis.html#creating-dual-homed-instances-with-workloads-roles-on-distinct-subnets
6670
for_each = var.network_interfaces
6771
content {
6872
delete_on_termination = false
@@ -96,15 +100,20 @@ resource "aws_autoscaling_group" "tailscale" {
96100
availability_zones = [data.aws_network_interface.selected[0].availability_zone]
97101

98102
desired_capacity = 1
99-
min_size = 1
100-
max_size = 2
103+
min_size = 0
104+
max_size = 1
105+
106+
/**
107+
* Uncomment to allow ASG to replace the instance. It will take several minutes as the ASG
108+
* will try to launch a replacement instance before ENIs have been released.
101109
102110
instance_refresh {
103111
strategy = "Rolling"
104112
preferences {
105-
min_healthy_percentage = 50
113+
min_healthy_percentage = 0
106114
}
107115
}
116+
*/
108117

109118
health_check_grace_period = 300
110119
health_check_type = "EC2"

terraform/aws/internal-modules/aws-ec2-autoscaling/variables.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ variable "instance_key_name" {
2020
}
2121
variable "instance_profile_name" {
2222
type = string
23-
default = null
23+
default = ""
2424
}
2525
variable "instance_metadata_options" {
2626
type = map(string)

0 commit comments

Comments
 (0)