Skip to content
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
14 changes: 8 additions & 6 deletions main.tf
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
locals {
name = "squid"
name = "squid"
lifecycle_hook_name = "${local.name}-hook"
userdata = templatefile("${path.module}/templates/cloud-init.tpl", {
architecture = local.architecture
aws_region = data.aws_region.current.name
eip_allocation_id = var.enable_eip ? aws_eip.squid[0].id : ""
s3_bucket = module.config_bucket.s3_bucket_id
architecture = local.architecture
aws_region = data.aws_region.current.name
eip_allocation_id = var.enable_eip ? aws_eip.squid[0].id : ""
lifecycle_hook_name = local.lifecycle_hook_name
s3_bucket = module.config_bucket.s3_bucket_id
})
}

Expand Down Expand Up @@ -232,7 +234,7 @@ resource "aws_autoscaling_group" "squid" {
vpc_zone_identifier = var.public_subnet_ids

initial_lifecycle_hook {
name = "squid-asg-hook"
name = local.lifecycle_hook_name
lifecycle_transition = "autoscaling:EC2_INSTANCE_LAUNCHING"
heartbeat_timeout = 300
default_result = "ABANDON"
Expand Down
3 changes: 2 additions & 1 deletion templates/cloud-init.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ write_files:
--allocation-id "${eip_allocation_id}" \
--network-interface-id "$eni_id" \
--private-ip-address "$private_ip" \
--allow-reassociation \
--region "$region"
fi

Expand Down Expand Up @@ -144,7 +145,7 @@ write_files:

# Complete the lifecycle action
aws autoscaling complete-lifecycle-action \
--lifecycle-hook-name squid-asg-hook \
--lifecycle-hook-name "${lifecycle_hook_name}" \
--auto-scaling-group-name "$asg_name" \
--lifecycle-action-result CONTINUE \
--instance-id "$instanceid" \
Expand Down
Loading