hashicorp / terraform-provider-aws

The AWS Provider enables Terraform to manage AWS resources.
https://registry.terraform.io/providers/hashicorp/aws
Mozilla Public License 2.0
9.83k stars 9.18k forks source link

Documentation does not specify target_value is an attribute and it is required field #20822

Open ehlaumarc opened 3 years ago

ehlaumarc commented 3 years ago

Community Note

Terraform CLI and Terraform AWS Provider Version

Affected Resource(s)

image

Terraform Configuration Files

Please include all Terraform configurations required to reproduce the bug. Bug reports without a functional reproduction may be closed without investigation.

resource "aws_autoscaling_policy" "asg_policy" {
  for_each = try(var.autoscaling_policy, {})

  name                   = each.value.name                                                  #(Required) The name of the policy.
  autoscaling_group_name = aws_autoscaling_group.asg[each.value.autoscaling_group_key].name #(Required) The name of the autoscaling group.
  adjustment_type        = try(each.value.adjustment_type, null)                            # (Optional) Specifies whether the adjustment is an absolute number or a percentage of the current capacity. Valid values are ChangeInCapacity, ExactCapacity, and PercentChangeInCapacity.
  policy_type            = try(each.value.policy_type, "SimpleScaling")  
dynamic "predictive_scaling_configuration" { #(Optional) The predictive scaling policy configuration to use with Amazon EC2 Auto Scaling.
    for_each = try(each.value.predictive_scaling_config, null) == null ? [] : [1]
    content {
      max_capacity_breach_behavior = try(predictive_scaling_configuration.value.max_capacity_breach_behavior, "HonorMaxCapacity") #(Optional) Defines the behavior that should be applied if the forecast capacity approaches or exceeds the maximum capacity of the Auto Scaling group. Valid values are HonorMaxCapacity or IncreaseMaxCapacity. Default is HonorMaxCapacity.
      max_capacity_buffer          = try(predictive_scaling_configuration.value.max_capacity_buffer, null)                        #(Optional) The size of the capacity buffer to use when the forecast capacity is close to or exceeds the maximum capacity. Valid range is 0 to 100. If set to 0, Amazon EC2 Auto Scaling may scale capacity higher than the maximum capacity to equal but not exceed forecast capacity.

      dynamic "metric_specification" { #(Required) This structure includes the metrics and target utilization to use for predictive scaling.
        for_each = try(predictive_scaling_configuration.value.metric_spec, null) == null ? [] : [1]
        content {

          dynamic "predefined_load_metric_specification" { #(Optional) The load metric specification.
            for_each = try(metric_specification.value.predefined_load_metric_spec, null) == null ? [] : [1]
            content {
              predefined_metric_type = predefined_load_metric_specification.value.metric_type    #(Required) The metric type. Valid values are ASGTotalCPUUtilization, ASGTotalNetworkIn, ASGTotalNetworkOut, or ALBTargetGroupRequestCount.
              resource_label         = predefined_load_metric_specification.value.resource_label #(Required) A label that uniquely identifies a specific Application Load Balancer target group from which to determine the request count served by your Auto Scaling group.
            }
          }

          dynamic "predefined_metric_pair_specification" { #(Optional) The metric pair specification from which Amazon EC2 Auto Scaling determines the appropriate scaling metric and load metric to use.
            for_each = try(metric_specification.value.predefined_metric_pair_spec, null) == null ? [] : [1]
            content {
              predefined_metric_type = predefined_metric_pair_specification.value.metric_type    #(Required) Indicates which metrics to use. There are two different types of metrics for each metric type: one is a load metric and one is a scaling metric. For example, if the metric type is ASGCPUUtilization, the Auto Scaling group's total CPU metric is used as the load metric, and the average CPU metric is used for the scaling metric. Valid values are ASGCPUUtilization, ASGNetworkIn, ASGNetworkOut, or ALBRequestCount.
              resource_label         = predefined_metric_pair_specification.value.resource_label #(Required) A label that uniquely identifies a specific Application Load Balancer target group from which to determine the request count served by your Auto Scaling group.
            }
          }

          dynamic "predefined_scaling_metric_specification" { #(Optional) The scaling metric specification.
            for_each = try(metric_specification.value.predefined_scaling_metric_spec, null) == null ? [] : [1]
            content {
              predefined_metric_type = predefined_scaling_metric_specification.value.metric_type    #(Required) Describes a scaling metric for a predictive scaling policy. Valid values are ASGAverageCPUUtilization, ASGAverageNetworkIn, ASGAverageNetworkOut, or ALBRequestCountPerTarget.
              resource_label         = predefined_scaling_metric_specification.value.resource_label #(Required) A label that uniquely identifies a specific Application Load Balancer target group from which to determine the request count served by your Auto Scaling group.
            }
          }
        }
      }
      mode                   = try(predictive_scaling_configuration.value.mode, "ForecastOnly")              #(Optional) The predictive scaling mode. Valid values are ForecastAndScale and ForecastOnly. Default is ForecastOnly.
      scheduling_buffer_time = try(predictive_scaling_configuration.value.scheduling_buffer_time_seconds, 0) #(Optional) The amount of time, in seconds, by which the instance launch time can be advanced. Minimum is 0.
    }
  }
}

Debug Output

The argument "target_value" is required, but no definition was found.

Panic Output

Expected Behavior

The message "Success! The configuration is valid." should appear

Actual Behavior

Error message: โ”‚ Error: Missing required argument โ”‚ โ”‚ on autoscaling.tf line 145, in resource "aws_autoscaling_policy" "asg_policy": โ”‚ 145: content { โ”‚ โ”‚ The argument "target_value" is required, but no definition was found.

Steps to Reproduce

  1. terraform validate

Important Factoids

References

justinretzolk commented 2 years ago

Hey @ehlaumarc ๐Ÿ‘‹ Thank you for taking the time to raise this! Can you confirm what version of the AWS Provider you experienced this issue with? Looking at the documentation for aws_autoscaling_policy, it looks like target_value is only used in target_tracking_configuration blocks, which doesn't seem to be something you're defining here, so I'm scratching my head a bit on why this error would be thrown.