terraform-aws-modules / terraform-aws-autoscaling

Terraform module to create AWS Auto Scaling resources 🇺🇦
https://registry.terraform.io/modules/terraform-aws-modules/autoscaling/aws
Apache License 2.0
289 stars 553 forks source link

Resource label should be specified for predefined metric type ALBRequestCountPerTarget #192

Closed obi-juan1971 closed 2 years ago

obi-juan1971 commented 2 years ago

Description

When you set a scaling_policy of type ALBRequestCountPerTarget you need to specify a Resource Label and this in not consider in code, so this module fail to create the resource aws_autoscaling_policy.this

⚠️ Note

Before you submit an issue, please perform the following first:

  1. Remove the local .terraform directory (! ONLY if state is stored remotely, which hopefully you are following that best practice!): rm -rf .terraform/
  2. Re-initialize the project root to pull down modules: terraform init
  3. Re-attempt your terraform plan or apply and check if the issue still persists

Versions

Reproduction Code [Required]

Steps to reproduce the behavior:

no yes

Expected behavior

I expect to be able to create an aws_autoscaling_policy if type ALBRequestCountPerTarget like this

  # Target scaling policy schedule based on Request Count per target
  scaling_policies = {
    request-count-per-target = {
      policy_type               = "TargetTrackingScaling"
      estimated_instance_warmup = 120
      target_tracking_configuration = {
        predefined_metric_specification = {
          predefined_metric_type = "ALBRequestCountPerTarget"
          resource_label         = "app/my-lb/abababababab/targetgroup/my-lb-tg/45fafafafafafa"
        }
        target_value = 1600
      }
    },
  }

Actual behavior

It can't be created.

Terminal Output Screenshot(s)

aws_autoscaling_policy.this["request-count-per-target"]: Creating...
╷
│ Error: Error putting scaling policy: ValidationError: Resource label should be specified for predefined metric type ALBRequestCountPerTarget
│       status code: 400, request id: 8da7c386-4988-45d3-a6cd-9974ea8c9e32
│ 
│   with aws_autoscaling_policy.this["request-count-per-target"],
│   on main.tf line 570, in resource "aws_autoscaling_policy" "this":
│  570: resource "aws_autoscaling_policy" "this" 

Additional context

bryantbiggs commented 2 years ago

hi @obi-juan1971 - we'll need a reproduction to troubleshoot

obi-juan1971 commented 2 years ago

hi @obi-juan1971 - we'll need a reproduction to troubleshoot

Hi @bryantbiggs I hope this help. Using your complete example, just add a scaling_policy like this and you'll get the error:

request-count-per-target = {
    policy_type               = "TargetTrackingScaling"
    estimated_instance_warmup = 120
    target_tracking_configuration = {
    predefined_metric_specification = {
        predefined_metric_type = "ALBRequestCountPerTarget"
        resource_label         = "${module.alb.lb_arn_suffix}/${module.alb.target_group_arn_suffixes[0]}"
    }
    target_value = 800
    }
},
cyberitguru commented 2 years ago

I have the exact same issue with the following versions:

"terraform_version": "1.1.9",

module "autoscaling" {
  source  = "terraform-aws-modules/autoscaling/aws"
  version = "6.3.0"
module "alb" {
  source = "terraform-aws-modules/alb/aws"
  version = "6.10.0"

Tried to make sure the resource_label is in the format of: app/my-alb/id-xxx/targetgroup/my-alb-target-group/id-yyy

Everything seems ok except when trying to add the ALBRequestCountPerTarget.

│ Error: Error putting scaling policy: ValidationError: Resource label should be specified for predefined metric type ALBRequestCountPerTarget
│   status code: 400, request id: 3479e05e-bc3a-4419-87b1-74743363d8ec
│
│   with module.autoscaling.aws_autoscaling_policy.this["alb-target-requests-greater-than-yy"],
│   on .terraform/modules/autoscaling/main.tf line 570, in resource "aws_autoscaling_policy" "this":
│  570: resource "aws_autoscaling_policy" "this" {
bryantbiggs commented 2 years ago

Thanks @obi-juan1971 for the repro - fix is coming shortly!

antonbabenko commented 2 years ago

This issue has been resolved in version 6.5.0 :tada:

github-actions[bot] commented 1 year ago

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.