Skip to content

Error/Bug: aws_s3_bucket_object inconsistent final plan with version_id #14899

@wernerb

Description

@wernerb

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Terraform CLI and Terraform AWS Provider Version

Terraform v0.13.1
+ provider registry.terraform.io/-/aws v3.4.0
+ provider registry.terraform.io/hashicorp/aws v3.4.0

Affected Resource(s)

  • aws_s3_bucket_object

Terraform Configuration Files

provider "aws" {
  version                     = ">= 3.0.0"
}

resource "aws_s3_bucket" "examplebucket" {
  bucket = "sampletestexamplebuckettftest"
  acl    = "private"

  versioning {
    enabled = true
  }
}

variable "content" {
  type = string
}

resource "aws_s3_bucket_object" "firstfile" {
  key        = "someobject"
  bucket     = aws_s3_bucket.examplebucket.id
  content    = var.content
}

resource "aws_s3_bucket_object" "secondfile" {
  key        = "anotherobject"
  bucket     = aws_s3_bucket.examplebucket.id
  content    = "${md5(var.content)} - ${aws_s3_bucket_object.firstfile.version_id}"
}

Debug Output

https://gist.github.com/wernerb/ec3872b69b1093a136fc9dc41880fb28

Panic Output

Expected Behavior

Terraform knows that a new version_id is there and uses that correctly in secondfile

I have submitted a pull request that completely closes this issue.

Actual Behavior

Error thrown during apply:

$ terraform apply -var content=bla2
aws_s3_bucket.examplebucket: Refreshing state... [id=sampletestexamplebuckettftest]
aws_s3_bucket_object.firstfile: Refreshing state... [id=someobject]
aws_s3_bucket_object.secondfile: Refreshing state... [id=anotherobject]

An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
  ~ update in-place

Terraform will perform the following actions:

  # aws_s3_bucket_object.firstfile will be updated in-place
  ~ resource "aws_s3_bucket_object" "firstfile" {
        acl           = "private"
        bucket        = "sampletestexamplebuckettftest"
      ~ content       = "bla" -> "bla2"
        content_type  = "binary/octet-stream"
        etag          = "128ecf542a35ac5270a87dc740918404"
        force_destroy = false
        id            = "someobject"
        key           = "someobject"
        metadata      = {}
        storage_class = "STANDARD"
        tags          = {}
        version_id    = "5_Fxmip9w4DJgZV2or3_SAAn8Rr2QyA5"
    }

  # aws_s3_bucket_object.secondfile will be updated in-place
  ~ resource "aws_s3_bucket_object" "secondfile" {
        acl           = "private"
        bucket        = "sampletestexamplebuckettftest"
      ~ content       = "128ecf542a35ac5270a87dc740918404 - 5_Fxmip9w4DJgZV2or3_SAAn8Rr2QyA5" -> "a1288b1c7e2257a90bad9bdfb7690fbb - 5_Fxmip9w4DJgZV2or3_SAAn8Rr2QyA5"
        content_type  = "binary/octet-stream"
        etag          = "6be52a6a547f72e84fa7cdd36e01c56d"
        force_destroy = false
        id            = "anotherobject"
        key           = "anotherobject"
        metadata      = {}
        storage_class = "STANDARD"
        tags          = {}
        version_id    = "u04WlTsNLJ16GDUVqSxJ5Y0zAwGn7LT8"
    }

Plan: 0 to add, 2 to change, 0 to destroy.

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

aws_s3_bucket_object.firstfile: Modifying... [id=someobject]
aws_s3_bucket_object.firstfile: Modifications complete after 0s [id=someobject]

Error: Provider produced inconsistent final plan

When expanding the plan for aws_s3_bucket_object.secondfile to include new
values learned so far during apply, provider
"registry.terraform.io/hashicorp/aws" produced an invalid new value for
.content: was cty.StringVal("a1288b1c7e2257a90bad9bdfb7690fbb -
5_Fxmip9w4DJgZV2or3_SAAn8Rr2QyA5"), but now
cty.StringVal("a1288b1c7e2257a90bad9bdfb7690fbb -
0mNGmhdBL8YmClTknce4vf3eQv5yFfF6").

This is a bug in the provider, which should be reported in the provider's own
issue tracker.

Steps to Reproduce

1.terraform apply -var content=bla

First apply is ok.

Second setup

2. terraform apply -var content=anotherbla

Terraform applies correctly with the updated version_id.

Important Factoids

Changes to content or similar keys that always produce changes to version should be hinted to terraform that it will be a new value. When using a version_id in a following resource when changing the object we get a inconsistent state error message from Terraform regarding the version_id.

Expected behavior is for terraform to be aware a content change is always a version_id change.

Please see connected merge request that fixes this issue.

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugAddresses a defect in current functionality.service/s3Issues and PRs that pertain to the s3 service.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions