Skip to content

[Bug]:aws_s3_object resource always replaced when aws_s3_bucket data is used in bucket argument #42897

Open
@javierbeaumont

Description

@javierbeaumont

Terraform and AWS Provider Version

Terraform v1.12.1
on darwin_arm64
+ provider registry.terraform.io/hashicorp/aws v5.99.1

Affected Resource(s) or Data Source(s)

  • aws_s3_object
  • aws_s3_bucket

Expected Behavior

Upload an object to S3.
In the following executions, if there are no changes to the object, the resource does not change.

Actual Behavior

Upload an object to S3.
In the following executions, the aws_s3_object resource is replaced.

Relevant Error/Panic Output

# aws_s3_object.this must be replaced
-/+ resource "aws_s3_object" "this" {
      + acl                           = (known after apply)
      ~ arn                           = "arn:aws:s3:::bucket-name/file.zip" -> (known after apply)
      ~ bucket                        = "bucket-name" -> (known after apply) # forces replacement
      ~ bucket_key_enabled            = false -> (known after apply)
      + checksum_crc32                = (known after apply)
      + checksum_crc32c               = (known after apply)
      + checksum_crc64nvme            = (known after apply)
      + checksum_sha1                 = (known after apply)
      + checksum_sha256               = (known after apply)
      ~ content_type                  = "application/octet-stream" -> (known after apply)
      ~ etag                          = "e123456789abcdef0123456789abcdef0" -> (known after apply)
      ~ id                            = "file.zip" -> (known after apply)
      + kms_key_id                    = (known after apply)
      - metadata                      = {} -> null
      ~ server_side_encryption        = "AES256" -> (known after apply)
      ~ storage_class                 = "STANDARD" -> (known after apply)
      - tags                          = {} -> null
      ~ tags_all                      = {} -> (known after apply)
      ~ version_id                    = "FzVF5i_zc4CCsPjpg3X1PbXX80ktTLB8" -> (known after apply)
        # (12 unchanged attributes hidden)
    }

Sample Terraform Configuration

Click to expand configuration
data "aws_s3_bucket" "this" {
  bucket = "bucket-name"
}

resource "aws_s3_object" "this" {
  bucket = data.aws_s3_bucket.this.bucket 
  key    = "file.zip"
}

Steps to Reproduce

  1. Create a bucket
  2. Create a S3 object with aws_s3_object resource and reference a bucket with aws_s3_bucket data.
  3. Re-aply Terraform

Debug Logging

Click to expand log output

GenAI / LLM Assisted Development

n/a

Important Facts and References

Similar behavior bug: #32529

Would you like to implement a fix?

No

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugAddresses a defect in current functionality.needs-triageWaiting for first response or review from a maintainer.service/s3Issues and PRs that pertain to the s3 service.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions