Skip to content

Instantly share code, notes, and snippets.

@rbreslow
Created August 11, 2021 18:56
Show Gist options
  • Save rbreslow/a5277789e2a96f0232b093aaa4f77c77 to your computer and use it in GitHub Desktop.
Save rbreslow/a5277789e2a96f0232b093aaa4f77c77 to your computer and use it in GitHub Desktop.
Lifecycle-fix for target groups.
resource "aws_lb_target_group" "app" {
# We want a randomly generated resource name so the lifecycle block will
# function. name_prefix can only be 6 characters due to a limitation in the
# AWS API.
# https://github.com/hashicorp/terraform-provider-aws/issues/636#issuecomment-637761075
name_prefix = substr(var.environment, 0, 6)
health_check {
healthy_threshold = "3"
interval = "30"
matcher = "200"
protocol = "HTTP"
timeout = "3"
path = "/healthcheck"
unhealthy_threshold = "2"
}
port = "80"
protocol = "HTTP"
vpc_id = module.vpc.id
target_type = "ip"
tags = {
Name = "tg${var.environment}App"
Project = var.project
Environment = var.environment
}
lifecycle {
create_before_destroy = true
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment