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.66k stars 9.03k forks source link

[Bug]: aws_autosacling_group - validation desiredCapacityType incorrect #37523

Open hans-d opened 2 months ago

hans-d commented 2 months ago

Terraform Core Version

1.5.7

AWS Provider Version

5.45.0, 5.46.0, 5.47.0, 5.48.0, 5.49.0

Affected Resource(s)

aws_autoscaling_group

Expected Behavior

examples as on https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/autoscaling_group work

Actual Behavior

Validation error

Relevant Error/Panic Output Snippet

Error: updating Auto Scaling Group: operation error Auto Scaling: UpdateAutoScalingGroup, https response error StatusCode: 400, RequestID: 26d074bd-e530-4453-a76f-a03e1f94fcc8, api error ValidationError: 1 validation error detected: Value '' at 'desiredCapacityType' failed to satisfy constraint: Member must have length greater than or equal to 1

Terraform Configuration Files

see https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/autoscaling_group

Steps to Reproduce

apply

Debug Output

No response

Panic Output

No response

Important Factoids

The mention variable is optional, but the validation used makes it mandatory

References

https://github.com/hashicorp/terraform-provider-aws/blame/feecd0b738afe3275a54ce2f4c8d3dcb8414014d/internal/service/autoscaling/group.go#L106

Would you like to implement a fix?

None

github-actions[bot] commented 2 months ago

Community Note

Voting for Prioritization

Volunteering to Work on This Issue

rctunisi commented 2 months ago

Ive got the same issue. It seems that the default values are being set to null, but the default api values for desired_capacity_types for both CreateAutoscalingGroup and UpdateAutoscalingGroup is units

Update: any console changes to asg are setting desired_capacity_types value, so terraform detects this as a drift and tries to revert that to null, causing the error above

Ref on default values: https://docs.aws.amazon.com/autoscaling/ec2/APIReference/API_CreateAutoScalingGroup.html https://docs.aws.amazon.com/autoscaling/ec2/APIReference/API_UpdateAutoScalingGroup.html

justinretzolk commented 2 months ago

Hey @hans-d šŸ‘‹ Thank you for taking the time to raise this! Can you supply a sample configuration that can be used to reproduce this and/or debug logging? That information will be useful for whoever picks this up.

herrbpl commented 2 months ago

This bug seems to have been here since instance requirement support was added. I have had problems with this for ages..

jjunior-onfleet commented 2 months ago

Also happens with AWS provider v5.51.1

xgt001 commented 1 month ago

can second @rctunisi here, ran into this when I modified the ASG in the console and tried to sync it in Terraform code. AWS Provider version 5.47.0.

The only "fix" that can be done for non-critical-absolutely-testonly-workloads I can suggest is to terminate the entire ASG and recreate it and maintain it only in TF, while avoiding editing the capacity units or the number of nodes in the web console.

sergsoares commented 1 month ago

I received that error and got some debug logs to help in that case, seems that because desired_capacity is in ignore_changes for resource aws_autoscalinggroup the value sent to AWS Autoscaling Group API is empty (&DesiredCapacityType=&MaxSize=3)_, stopping at API validation.

Scenario:

Terraform Error:

ā•·
ā”‚ Error: updating Auto Scaling Group (*******************************): operation error Auto Scaling: UpdateAutoScalingGroup, https response error StatusCode: 400, RequestID: *******************************, api error ValidationError: 1 validation error detected: Value '' at 'desiredCapacityType' failed to satisfy constraint: Member must have length greater than or equal to 1
ā”‚ 
ā”‚   with module.self_managed_node_group.aws_autoscaling_group.this[0],
ā”‚   on .terraform/modules/self_managed_node_group/modules/self-managed-node-group/main.tf line 491, in resource "aws_autoscaling_group" "this":
ā”‚  491: resource "aws_autoscaling_group" "this" {
ā”‚ 

Debug Logs:

2024-06-12T00:15:34.634-0300 [DEBUG] module.self_managed_node_group.aws_autoscaling_group.this[0]: applying the planned Update change

2024-06-12T00:15:34.650-0300 [DEBUG] provider.terraform-provider-aws_v5.53.0_x5: HTTP Request Sent: http.request.header.amz_sdk_request="attempt=1; max=25" http.request.header.x_amz_date=20240612T031534Z net.peer.name=autoscaling.eu-west-2.amazonaws.com rpc.system=aws-api http.request.body="Action=UpdateAutoScalingGroup&AutoScalingGroupName=eks-*******************************&DesiredCapacityType=&MaxSize=3&NewInstancesProtectedFromScaleIn=false&Version=2011-01-01" http.request.header.content_type=application/x-www-form-urlencoded aws.region=eu-west-2 http.request_content_length=184 http.url=https://autoscaling.eu-west-2.amazonaws.com/ tf_aws.sdk=aws-sdk-go-v2 tf_rpc=ApplyResourceChange http.request.header.x_amz_security_token=***** http.request.header.amz_sdk_invocation_id=******************************* tf_aws.signing_region= tf_provider_addr=registry.terraform.io/hashicorp/aws http.user_agent="APN/1.0 HashiCorp/1.0 Terraform/1.5.6 (+https://www.terraform.io) terraform-provider-aws/5.53.0 (+https://registry.terraform.io/providers/hashicorp/aws) aws-sdk-go-v2/1.27.1 os/macos lang/go#1.22.2 md/GOOS#darwin md/GOARCH#arm64 api/autoscaling#1.40.10" tf_resource_type=aws_autoscaling_group http.method=POST rpc.service="Auto Scaling" tf_mux_provider=*schema.GRPCProviderServer tf_req_id=******************************* rpc.method=UpdateAutoScalingGroup @module=aws http.request.header.authorization="AWS4-HMAC-SHA256 Credential=********************/20240612/eu-west-2/autoscaling/aws4_request, SignedHeaders=amz-sdk-invocation-id;amz-sdk-request;content-length;content-type;host;x-amz-date;x-amz-security-token, Signature=*****" @caller=github.com/hashicorp/aws-sdk-go-base/v2@v2.0.0-beta.53/logging/tf_logger.go:45 timestamp=2024-06-12T00:15:34.650-0300

`2024-06-12T00:15:35.756-0300 [DEBUG] provider.terraform-provider-aws_v5.53.0_x5: HTTP Response Received: rpc.service="Auto Scaling" tf_provider_addr=registry.terraform.io/hashicorp/aws http.response.header.content_type=text/xml http.response_content_length=397 tf_aws.signing_region= tf_req_id=*** @module=aws aws.region=eu-west-2 http.duration=1105 http.response.body="

Sender ValidationError 1 validation error detected: Value '' at 'desiredCapacityType' failed to satisfy constraint: Member must have length greater than or equal to 1 *******************************

" http.response.header.date="Wed, 12 Jun 2024 03:15:35 GMT" rpc.method=UpdateAutoScalingGroup @caller=github.com/hashicorp/aws-sdk-go-base/v2@v2.0.0-beta.53/logging/tf_logger.go:45 tf_rpc=ApplyResourceChange tf_aws.sdk=aws-sdk-go-v2 tf_resource_type=aws_autoscaling_group rpc.system=aws-api tf_mux_provider=*schema.GRPCProviderServer http.response.header.x_amzn_requestid=*** http.status_code=400 timestamp=2024-06-12T00:15:35.756-0300 `

jmereckimaxar commented 1 month ago

Hello! My team experienced this, and we resolved it by adding the "desired_capacity" and "desired_capacity_type" properties to the Terraform "aws_autoscaling_group" resource, then modifying the resource for the lifecycle tags: ignore_changes = [desired_capacity, desired_capacity_type]. Basically adding the properties, which would be used upon resource creation, then ignoring the properties upon updates.