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

aws_autoscaling_traffic_source_attachment add downtime VS target_group_arns #262

Open
florianmagnin opened this issue Mar 21, 2024 · 7 comments
Labels

Comments

@florianmagnin
Copy link

Description

Hello,

We migrate code from:

target_group_arns = [module.alb.outputs.target_groups["front_backend"].arn]

to

create_traffic_source_attachment = true                                                                                                                                                     
traffic_source_identifier        = module.alb.outputs.target_groups["front_backend"].arn                                                                                                    
traffic_source_type              = "elbv2"

But this change add like 2 minutes of downtime (ASG time creation) when we have an ASG re-creation because Terraform:
1 - delete existing aws_autoscaling_traffic_source_attachment
2 - create ASG
3 - create new existing aws_autoscaling_traffic_source_attachment

LOGS (trigger a new creation of ASG):

module.env.module.front_asg.aws_autoscaling_policy.scale_in[0]: Destruction complete after 0s
module.env.module.front_asg.aws_autoscaling_policy.scale_out[0]: Destruction complete after 0s
module.env.module.front_asg.module.main.aws_autoscaling_traffic_source_attachment.this[0]: Still destroying... [id=front-asg-prd-front-Thu-21-Mar-2024-09-...304105646607100000007/ab45916d8cb
5a8aa, 10s elapsed]
module.env.module.front_asg.module.main.aws_autoscaling_traffic_source_attachment.this[0]: Still destroying... [id=front-asg-prd-front-Thu-21-Mar-2024-09-...304105646607100000007/ab45916d8cb
5a8aa, 20s elapsed]
module.env.module.front_asg.module.main.aws_autoscaling_traffic_source_attachment.this[0]: Still destroying... [id=front-asg-prd-front-Thu-21-Mar-2024-09-...304105646607100000007/ab45916d8cb
5a8aa, 30s elapsed]
module.env.module.front_asg.module.main.aws_autoscaling_traffic_source_attachment.this[0]: Still destroying... [id=front-asg-prd-front-Thu-21-Mar-2024-09-...304105646607100000007/ab45916d8cb5a8aa, 40s elapsed]
module.env.module.front_asg.module.main.aws_autoscaling_traffic_source_attachment.this[0]: Still destroying... [id=front-asg-prd-front-Thu-21-Mar-2024-09-...304105646607100000007/ab45916d8cb5a8aa, 50s elapsed]
module.env.module.front_asg.module.main.aws_autoscaling_traffic_source_attachment.this[0]: Still destroying... [id=front-asg-prd-front-Thu-21-Mar-2024-09-...304105646607100000007/ab45916d8cb5a8aa, 1m0s elapsed]
module.env.module.front_asg.module.main.aws_autoscaling_traffic_source_attachment.this[0]: Still destroying... [id=front-asg-prd-front-Thu-21-Mar-2024-09-...304105646607100000007/ab45916d8cb5a8aa, 1m10s elapsed]
module.env.module.front_asg.module.main.aws_autoscaling_traffic_source_attachment.this[0]: Destruction complete after 1m14s
module.env.module.front_asg.module.main.aws_launch_template.this[0]: Modifying... [id=lt-03d0898f38662d5f0]
module.env.module.front_asg.module.main.aws_launch_template.this[0]: Modifications complete after 1s [id=lt-03d0898f38662d5f0]
module.env.module.front_asg.module.main.aws_autoscaling_group.this[0]: Creating...
module.env.module.front_asg.module.main.aws_autoscaling_group.this[0]: Still creating... [10s elapsed]
module.env.module.front_asg.module.main.aws_autoscaling_group.this[0]: Still creating... [20s elapsed]
module.env.module.front_asg.module.main.aws_autoscaling_group.this[0]: Creation complete after 26s [id=front-asg-prd-front-Thu-21-Mar-2024-09-25-35-UTC]
module.env.module.front_asg.module.main.aws_autoscaling_traffic_source_attachment.this[0]: Creating...
module.env.module.front_asg.aws_autoscaling_policy.scale_in[0]: Creating...
module.env.module.front_asg.aws_autoscaling_policy.scale_out[0]: Creating...
module.env.module.front_asg.aws_cloudwatch_metric_alarm.underusage_alarm[0]: Creating...
module.env.module.front_asg.aws_cloudwatch_metric_alarm.overusage_alarm[0]: Creating...
module.env.module.front_asg.aws_cloudwatch_metric_alarm.overusage_alarm[0]: Creation complete after 0s [id=front-asg-prd-front-Thu-21-Mar-2024-09-25-35-UTC_overusage]
module.env.module.front_asg.aws_cloudwatch_metric_alarm.underusage_alarm[0]: Creation complete after 0s [id=front-asg-prd-front-Thu-21-Mar-2024-09-25-35-UTC_underusage]
module.env.module.front_asg.aws_autoscaling_policy.scale_out[0]: Creation complete after 1s [id=front-asg-prd-front-Thu-21-Mar-2024-09-25-35-UTC_scaleout]
module.env.module.front_asg.aws_cloudwatch_metric_alarm.scaleout_alarm[0]: Creating...
module.env.module.front_asg.aws_autoscaling_policy.scale_in[0]: Creation complete after 1s [id=front-asg-prd-front-Thu-21-Mar-2024-09-25-35-UTC_scalein]
module.env.module.front_asg.aws_cloudwatch_metric_alarm.scalein_alarm[0]: Creating...
module.env.module.front_asg.aws_cloudwatch_metric_alarm.scaleout_alarm[0]: Creation complete after 0s [id=front-asg-prd-front-Thu-21-Mar-2024-09-25-35-UTC_scaleout]
module.env.module.front_asg.aws_cloudwatch_metric_alarm.scalein_alarm[0]: Creation complete after 0s [id=front-asg-prd-front-Thu-21-Mar-2024-09-25-35-UTC_scalein]
module.env.module.front_asg.module.main.aws_autoscaling_traffic_source_attachment.this[0]: Still creating... [10s elapsed]
module.env.module.front_asg.module.main.aws_autoscaling_traffic_source_attachment.this[0]: Creation complete after 14s [id=front-asg-prd-front-Thu-21-Mar-2024-09-25-35-UTC,elbv2,arn:aws:elasticloadbalancing:eu-west-3:654654406548:targetgroup/FRTprd20240304105646607100000007/ab45916d8cb5a8aa]

With "target_group_arns" there is no downtime (checked with $ watch -n 0.2 'curl -ILk -s https://...'). But your comment in the main.tf looks scary

  # TODO - remove at next breaking change. Use `traffic_source_identifier`/`traffic_source_type` instead
  load_balancers = var.load_balancers
  # TODO - remove at next breaking change. Use `traffic_source_identifier`/`traffic_source_type` instead
  target_group_arns         = var.target_group_arns

I tried to fixed it by adding a lifecycle in "aws_autoscaling_traffic_source_attachment":

resource "aws_autoscaling_traffic_source_attachment" "this" {
  count = local.create && var.create_traffic_source_attachment ? 1 : 0

  autoscaling_group_name = var.ignore_desired_capacity_changes ? aws_autoscaling_group.idc[0].id : aws_autoscaling_group.this[0].id

  traffic_source {
    identifier = var.traffic_source_identifier
    type       = var.traffic_source_type
  }
  lifecycle {
    create_before_destroy = true
  }
}

It's better, but traffic is mixed between old and new asg, and during 1minute with some http 200 and http 502. Still shitty.

LOGS with lifecycle:

module.env.module.front_asg.module.main.aws_launch_template.this[0]: Modifying... [id=lt-03d0898f38662d5f0]
module.env.module.front_asg.module.main.aws_launch_template.this[0]: Modifications complete after 1s [id=lt-03d0898f38662d5f0]
module.env.module.front_asg.module.main.aws_autoscaling_group.this[0]: Creating...
module.env.module.front_asg.module.main.aws_autoscaling_group.this[0]: Still creating... [10s elapsed]
module.env.module.front_asg.module.main.aws_autoscaling_group.this[0]: Still creating... [20s elapsed]
module.env.module.front_asg.module.main.aws_autoscaling_group.this[0]: Creation complete after 25s [id=front-asg-prd-front-Thu-21-Mar-2024-09-36-43-UTC]
module.env.module.front_asg.module.main.aws_autoscaling_traffic_source_attachment.this[0]: Creating...
module.env.module.front_asg.aws_autoscaling_policy.scale_in[0]: Creating...
module.env.module.front_asg.aws_autoscaling_policy.scale_out[0]: Creating...
module.env.module.front_asg.aws_cloudwatch_metric_alarm.underusage_alarm[0]: Creating...
module.env.module.front_asg.aws_cloudwatch_metric_alarm.overusage_alarm[0]: Creating...
module.env.module.front_asg.aws_cloudwatch_metric_alarm.overusage_alarm[0]: Creation complete after 0s [id=front-asg-prd-front-Thu-21-Mar-2024-09-36-43-UTC_overusage]
module.env.module.front_asg.aws_cloudwatch_metric_alarm.underusage_alarm[0]: Creation complete after 0s [id=front-asg-prd-front-Thu-21-Mar-2024-09-36-43-UTC_underusage]
module.env.module.front_asg.aws_autoscaling_policy.scale_out[0]: Creation complete after 0s [id=front-asg-prd-front-Thu-21-Mar-2024-09-36-43-UTC_scaleout]
module.env.module.front_asg.aws_cloudwatch_metric_alarm.scaleout_alarm[0]: Creating...
module.env.module.front_asg.aws_autoscaling_policy.scale_in[0]: Creation complete after 0s [id=front-asg-prd-front-Thu-21-Mar-2024-09-36-43-UTC_scalein]
module.env.module.front_asg.aws_cloudwatch_metric_alarm.scalein_alarm[0]: Creating...
module.env.module.front_asg.aws_cloudwatch_metric_alarm.scaleout_alarm[0]: Creation complete after 1s [id=front-asg-prd-front-Thu-21-Mar-2024-09-36-43-UTC_scaleout]
module.env.module.front_asg.aws_cloudwatch_metric_alarm.scalein_alarm[0]: Creation complete after 1s [id=front-asg-prd-front-Thu-21-Mar-2024-09-36-43-UTC_scalein]
module.env.module.front_asg.module.main.aws_autoscaling_traffic_source_attachment.this[0]: Creation complete after 2s [id=front-asg-prd-front-Thu-21-Mar-2024-09-36-43-UTC,elbv2,arn:aws:elast
icloadbalancing:eu-west-3:654654406548:targetgroup/FRTprd20240304105646607100000007/ab45916d8cb5a8aa]
module.env.aws_autoscaling_policy.front_asg_phpfpm_workers_scaleout_policy: Creating...
module.env.aws_autoscaling_policy.front_asg_apache_workers_scaleout_policy: Creating...
module.env.aws_cloudwatch_dashboard.cw_scaling: Modifying... [id=Scaling-on-front-asg-prd]
module.env.aws_cloudwatch_metric_alarm.front_asg_phpfpm_workers_metric_alarm_scalein: Modifying... [id=front-asg-prd-phpfpm-workers-metric-alarm-scalein]
module.env.aws_cloudwatch_metric_alarm.front_asg_apache_workers_metric_alarm_scalein: Modifying... [id=front-asg-prd-apache-workers-metric-alarm-scalein]
module.env.aws_cloudwatch_metric_alarm.front_asg_phpfpm_workers_metric_alarm_scalein: Modifications complete after 0s [id=front-asg-prd-phpfpm-workers-metric-alarm-scalein]
module.env.aws_cloudwatch_metric_alarm.front_asg_apache_workers_metric_alarm_scalein: Modifications complete after 0s [id=front-asg-prd-apache-workers-metric-alarm-scalein]
module.env.aws_autoscaling_policy.front_asg_phpfpm_workers_scaleout_policy: Creation complete after 0s [id=front-asg-prd-phpfpm-workers-scaleout-policy]
module.env.aws_autoscaling_policy.front_asg_apache_workers_scaleout_policy: Creation complete after 0s [id=front-asg-prd-apache-workers-scaleout-policy]
module.env.aws_cloudwatch_metric_alarm.front_asg_phpfpm_workers_metric_alarm_scaleout: Modifying... [id=front-asg-prd-phpfpm-workers-metric-alarm-scaleout]
module.env.aws_cloudwatch_metric_alarm.front_asg_apache_workers_metric_alarm_scaleout: Modifying... [id=front-asg-prd-apache-workers-metric-alarm-scaleout]
module.env.aws_cloudwatch_metric_alarm.front_asg_phpfpm_workers_metric_alarm_scaleout: Modifications complete after 0s [id=front-asg-prd-phpfpm-workers-metric-alarm-scaleout]
module.env.aws_cloudwatch_metric_alarm.front_asg_apache_workers_metric_alarm_scaleout: Modifications complete after 1s [id=front-asg-prd-apache-workers-metric-alarm-scaleout]
module.env.aws_cloudwatch_dashboard.cw_scaling: Modifications complete after 1s [id=Scaling-on-front-asg-prd]
module.env.module.front_asg.module.main.aws_autoscaling_traffic_source_attachment.this[0] (deposed object dec1bb0f): Destroying... [id=front-asg-prd-front-Thu-21-Mar-2024-09-25-35-UTC,elbv2,
arn:aws:elasticloadbalancing:eu-west-3:654654406548:targetgroup/FRTprd20240304105646607100000007/ab45916d8cb5a8aa]
module.env.module.front_asg.module.main.aws_autoscaling_traffic_source_attachment.this[0]: Still destroying... [id=front-asg-prd-front-Thu-21-Mar-2024-09-...304105646607100000007/ab45916d8cb
5a8aa, 10s elapsed]
module.env.module.front_asg.module.main.aws_autoscaling_traffic_source_attachment.this[0]: Still destroying... [id=front-asg-prd-front-Thu-21-Mar-2024-09-...304105646607100000007/ab45916d8cb
5a8aa, 20s elapsed]
module.env.module.front_asg.module.main.aws_autoscaling_traffic_source_attachment.this[0]: Still destroying... [id=front-asg-prd-front-Thu-21-Mar-2024-09-...304105646607100000007/ab45916d8cb
5a8aa, 30s elapsed]
module.env.module.front_asg.module.main.aws_autoscaling_traffic_source_attachment.this[0]: Still destroying... [id=front-asg-prd-front-Thu-21-Mar-2024-09-...304105646607100000007/ab45916d8cb
5a8aa, 40s elapsed]
module.env.module.front_asg.module.main.aws_autoscaling_traffic_source_attachment.this[0]: Still destroying... [id=front-asg-prd-front-Thu-21-Mar-2024-09-...304105646607100000007/ab45916d8cb
5a8aa, 50s elapsed]
module.env.module.front_asg.module.main.aws_autoscaling_traffic_source_attachment.this[0]: Still destroying... [id=front-asg-prd-front-Thu-21-Mar-2024-09-...304105646607100000007/ab45916d8cb
5a8aa, 1m0s elapsed]
module.env.module.front_asg.module.main.aws_autoscaling_traffic_source_attachment.this[0]: Still destroying... [id=front-asg-prd-front-Thu-21-Mar-2024-09-...304105646607100000007/ab45916d8cb
5a8aa, 1m10s elapsed]
module.env.module.front_asg.module.main.aws_autoscaling_traffic_source_attachment.this[0]: Destruction complete after 1m14s
module.env.module.front_asg.module.main.aws_autoscaling_group.this[0] (deposed object 21af4693): Destroying... [id=front-asg-prd-front-Thu-21-Mar-2024-09-25-35-UTC]
module.env.module.front_asg.module.main.aws_autoscaling_group.this[0]: Still destroying... [id=front-asg-prd-front-Thu-21-Mar-2024-09-25-35-UTC, 10s elapsed]
module.env.module.front_asg.module.main.aws_autoscaling_group.this[0]: Still destroying... [id=front-asg-prd-front-Thu-21-Mar-2024-09-25-35-UTC, 20s elapsed]
module.env.module.front_asg.module.main.aws_autoscaling_group.this[0]: Still destroying... [id=front-asg-prd-front-Thu-21-Mar-2024-09-25-35-UTC, 30s elapsed]
module.env.module.front_asg.module.main.aws_autoscaling_group.this[0]: Still destroying... [id=front-asg-prd-front-Thu-21-Mar-2024-09-25-35-UTC, 40s elapsed]

Please DO NOT REMOVE "target_group_arns" with way better than additional attachments.

Thanks,
Regards
Florian

Versions

$ terraform -version
Terraform v1.7.5
on linux_amd64
+ provider registry.terraform.io/hashicorp/aws v5.41.0
Copy link

This issue has been automatically marked as stale because it has been open 30 days
with no activity. Remove stale label or comment or this issue will be closed in 10 days

@florianmagnin
Copy link
Author

Bump

@bryantbiggs
Copy link
Member

Its not clear what you are looking for with this issue

@github-actions github-actions bot removed the stale label Apr 22, 2024
@florianmagnin
Copy link
Author

florianmagnin commented Apr 23, 2024

Hello!

Hmm... It looks like your strategy on some modules is to use extra resources when they are available even if we can configure the parameter in the native resource.

Here the example with "aws_autoscaling_group" and the parameter "target_group_arns" that you quote "to remove" in the module. You prefer to use the extra resource "aws_autoscaling_traffic_source_attachment" for the same result.

But with extra resource to configure the same thing than the main resource you add lifecycle issues and downtime to HTTP traffic. Detailed in the main post.

Regards,
Florian

@vesl
Copy link

vesl commented Apr 23, 2024

Hello same issue here

@bryantbiggs
Copy link
Member

I would suggest opening an issue upstream with the AWS provider. The aws_autoscaling_traffic_source_attachment is the recommended resource since it support attaching to multiple different services such as VPC lattice, gateway load balancer, etc.

Copy link

This issue has been automatically marked as stale because it has been open 30 days
with no activity. Remove stale label or comment or this issue will be closed in 10 days

@github-actions github-actions bot added the stale label May 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants