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

[Bug]: Modifying only `final_snapshot` in `aws_ebs_volume` causes error applying changes #31044

Open dbnicholson opened 1 year ago

dbnicholson commented 1 year ago

Terraform Core Version

0.12.31

AWS Provider Version

4.64.0

Affected Resource(s)

Expected Behavior

Adding only final_snapshot should not cause an error.

Actual Behavior

Adding only final_snapshot causes a ModifyVolume request to be sent to AWS without any parameters to modify and AWS returns a 400 with <Message>Invalid input: Must specify at least one of size, type, iops, throughput or multi-attach.</Message>.

Relevant Error/Panic Output Snippet

Error: modifying EBS Volume (vol-XXXXXXXXXXXXXXXXX): InvalidParameterValue: Invalid input: Must specify at least one of size, type, iops, throughput or multi-attach.
        status code: 400, request id: 584915f6-98b3-83a5-dc03-e4a2134b9cc7

Terraform Configuration Files

resource "aws_ebs_volume" "volume" {
  availability_zone = var.az
  size              = var.volume_size
  type              = "gp2"

  final_snapshot = true
  snapshot_id    = var.volume_snapshot

  tags = {
    Name = "${local.module}-${local.env}"
  }
}

Steps to Reproduce

Add final_snapshot = true to an existing aws_ebs_volume and apply changes.

Debug Output

2023-04-28T05:55:42.821-0600 [DEBUG] plugin.terraform-provider-aws_v4.64.0_x5: HTTP Request Sent: http.url=https://ec2.us-west-1.amazonaws.com/ tf_mux_provider=*schema.GRPCProviderServer tf_req_id=584915f6-98b3-83a5-dc03-e4a2134b9cc7 tf_rpc=ApplyResourceChange @module=aws aws.service=EC2 http.method=POST http.user_agent="APN/1.0 HashiCorp/1.0 Terraform/0.12.31 (+https://www.terraform.io) terraform-provider-aws/4.64.0 (+https://registry.terraform.io/providers/hashicorp/aws) aws-sdk-go/1.44.246 (go1.19.8; linux; amd64)" net.peer.name=ec2.us-west-1.amazonaws.com @caller=github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2@v2.0.0-beta.26/logger.go:90 http.request.header.authorization="AWS4-HMAC-SHA256 Credential=AKIA************QUES/20230428/us-west-1/ec2/aws4_request, SignedHeaders=content-length;content-type;host;x-amz-date, Signature=*****" http.request.header.x_amz_date=20230428T115542Z http.request_content_length=69 http.flavor=1.1 tf_resource_type=aws_ebs_volume aws.operation=ModifyVolume aws.region=us-west-1 aws.sdk=aws-sdk-go http.request.body=Action=ModifyVolume&Version=2016-11-15&VolumeId=vol-XXXXXXXXXXXXXXXXX http.request.header.content_type="application/x-www-form-urlencoded; charset=utf-8" tf_provider_addr=registry.terraform.io/hashicorp/aws timestamp=2023-04-28T05:55:42.821-0600
...
2023-04-28T05:55:43.158-0600 [DEBUG] plugin.terraform-provider-aws_v4.64.0_x5: HTTP Response Received: aws.region=us-west-1 aws.service=EC2 http.duration=336 http.response.body="<?xml version="1.0" encoding="UTF-8"?>
<Response><Errors><Error><Code>InvalidParameterValue</Code><Message>Invalid input: Must specify at least one of size, type, iops, throughput or multi-attach.</Message></Error></Errors><RequestID>98bae446-babb-46af-b5aa-f679b31a2646</RequestID></Response>" http.response.header.server=AmazonEC2 aws.operation=ModifyVolume http.response.header.strict_transport_security="max-age=31536000; includeSubDomains" tf_resource_type=aws_ebs_volume @caller=github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2@v2.0.0-beta.26/logger.go:138 @module=aws http.status_code=400 tf_mux_provider=*schema.GRPCProviderServer tf_req_id=584915f6-98b3-83a5-dc03-e4a2134b9cc7 http.response.header.cache_control="no-cache, no-store" http.response.header.content_type=text/xml;charset=UTF-8 http.response.header.x_amzn_requestid=98bae446-babb-46af-b5aa-f679b31a2646 http.response.header.vary=accept-encoding tf_provider_addr=registry.terraform.io/hashicorp/aws tf_rpc=ApplyResourceChange aws.sdk=aws-sdk-go http.response.header.date="Fri, 28 Apr 2023 11:55:42 GMT" timestamp=2023-04-28T05:55:43.158-0600
2023-04-28T05:55:43.159-0600 [ERROR] plugin.terraform-provider-aws_v4.64.0_x5: Response contains error diagnostic: tf_req_id=584915f6-98b3-83a5-dc03-e4a2134b9cc7 tf_rpc=ApplyResourceChange @caller=github.com/hashicorp/terraform-plugin-go@v0.14.3/tfprotov5/internal/diag/diagnostics.go:55 diagnostic_detail= diagnostic_severity=ERROR tf_resource_type=aws_ebs_volume @module=sdk.proto diagnostic_summary="modifying EBS Volume (vol-0fd8e6fabfbbf5465): InvalidParameterValue: Invalid input: Must specify at least one of size, type, iops, throughput or multi-attach.
        status code: 400, request id: 98bae446-babb-46af-b5aa-f679b31a2646" tf_proto_version=5.3 tf_provider_addr=registry.terraform.io/hashicorp/aws timestamp=2023-04-28T05:55:43.159-0600
2023/04/28 05:55:43 [DEBUG] aws_ebs_volume.volume: apply errored, but we're indicating that via the Error pointer rather than returning it: modifying EBS Volume (vol-0fd8e6fabfbbf5465): InvalidParameterValue: Invalid input: Must specify at least one of size, type, iops, throughput or multi-attach.
        status code: 400, request id: 98bae446-babb-46af-b5aa-f679b31a2646

Panic Output

No response

Important Factoids

I think something that may be relevant here is that the volume was created with a pre-v4 version of the AWS provider. So, there was no final_snapshot in the state until I tried to add this change.

References

Seems very similar to #26280 where this a state only change that should be ignored for the purposes of actually sending the AWS API request.

Would you like to implement a fix?

None

github-actions[bot] commented 1 year ago

Community Note

Voting for Prioritization

Volunteering to Work on This Issue

fdarif commented 11 months ago

I encountered the same problem, but it started working when I included an additional parameter that wasn't initially necessary.

TF version : 014.12 Provider version : 5.31.0


resource "aws_ebs_volume" "test" {
  size                   = 20
  type                 = "gp2"
  availability_zone    = "${var.az}"
  final_snapshot           = true
  multi_attach_enabled = false # I added this
  tags = {
    Name     = "Test",
    Snapshot = "true"
  }
}
cueedee commented 3 months ago

@fdarif , additionally setting multi_attach_enabled = false did not make any difference wrt. to the error:

Error: modifying EBS Volume (vol-01234567890abcdef): InvalidParameterValue: Invalid input: Must specify at least one of size, type, iops, throughput or multi-attach.

This is for version 5.33.0 of aws_ebs_volume