Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

terraform, aws: comment instance_refresh on asg #12

Merged
merged 1 commit into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions terraform/aws/aws-ec2-autoscaling-dual-subnet/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ This module creates the following:

## Considerations

- 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.
- 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.

## To use
Expand Down
1 change: 1 addition & 0 deletions terraform/aws/aws-ec2-autoscaling/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ This example creates the following:

## Considerations

- 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.
- 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.

## To use
Expand Down
19 changes: 14 additions & 5 deletions terraform/aws/internal-modules/aws-ec2-autoscaling/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,11 @@ resource "aws_launch_template" "tailscale" {
instance_type = var.instance_type
key_name = var.instance_key_name

iam_instance_profile {
name = var.instance_profile_name
dynamic "iam_instance_profile" {
for_each = var.instance_profile_name != "" ? [1] : []
content {
name = var.instance_profile_name
}
}

metadata_options {
Expand All @@ -63,6 +66,7 @@ resource "aws_launch_template" "tailscale" {
}

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

desired_capacity = 1
min_size = 1
max_size = 2
min_size = 0
max_size = 1

/**
* 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.

instance_refresh {
strategy = "Rolling"
preferences {
min_healthy_percentage = 50
min_healthy_percentage = 0
}
}
*/

health_check_grace_period = 300
health_check_type = "EC2"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ variable "instance_key_name" {
}
variable "instance_profile_name" {
type = string
default = null
default = ""
}
variable "instance_metadata_options" {
type = map(string)
Expand Down
Loading