-
Notifications
You must be signed in to change notification settings - Fork 9.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
resource/aws_s3_bucket_object: Ignore changes due to default bucket e… #15234
resource/aws_s3_bucket_object: Ignore changes due to default bucket e… #15234
Conversation
…ncryption (hashicorp#10200) When an object is uploaded to a bucket that has default encryption configured, the object inherits the kms_key_id from the bucket. We therefore need to ignore changes to that attribute, which the user won't have specified. Setting this attribute to "" has the effect of re-encrypting the object with the default `aws/s3` key, which is not what the user intended or expected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @mattburgess 👋 Thank you for contributing this and adding the covering test. 👍 Please reach out if you have any questions or do not have time to implement the change.
DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool { | ||
// ignore diffs where the user hasn't specified a kms_key_id but the bucket has a default KMS key configured | ||
if new == "" && d.Get("server_side_encryption") == s3.ServerSideEncryptionAwsKms { | ||
return true | ||
} | ||
return false | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To properly signal to Terraform that this schema attribute may be without a configuration value, but then have a value set in the state by the provider, we need to use Computed: true
here. Future versions of Terraform core will be much more sensitive about returning an error when Computed
is not used properly. 👍
Computed: true,
We should also add some documentation in website/docs/r/s3_bucket_object.html.markdown
around this updated behavior:
* `kms_key_id` - (Optional) Amazon Resource Name (ARN) of the KMS Key to use for object encryption. If the S3 Bucket has server-side encryption enabled, that value will automatically be used. If referencing the `aws_kms_key` resource, use the `arn` attribute. If referencing the `aws_kms_alias` data source or resource, use the `target_key_arn` attribute. Terraform will only perform drift detection if a configuration value is provided.
Thanks for the review @bflad. I've pushed your suggested changes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks so much, @mattburgess 🚀
Output from acceptance testing:
--- PASS: TestAccAWSS3BucketObject_noNameNoKey (25.78s)
--- PASS: TestAccAWSS3BucketObject_withContentCharacteristics (75.89s)
--- PASS: TestAccAWSS3BucketObject_etagEncryption (74.91s)
--- PASS: TestAccAWSS3BucketObject_content (76.02s)
--- PASS: TestAccAWSS3BucketObject_kms (75.76s)
--- PASS: TestAccAWSS3BucketObject_sse (78.57s)
--- PASS: TestAccAWSS3BucketObject_contentBase64 (77.32s)
--- PASS: TestAccAWSS3BucketObject_source (77.75s)
--- PASS: TestAccAWSS3BucketObject_empty (80.10s)
--- PASS: TestAccAWSS3BucketObject_NonVersioned (78.98s)
--- PASS: TestAccAWSS3BucketObject_updatesWithVersioningViaAccessPoint (119.25s)
--- PASS: TestAccAWSS3BucketObject_updates (118.41s)
--- PASS: TestAccAWSS3BucketObject_updatesWithVersioning (117.78s)
--- PASS: TestAccAWSS3BucketObject_ObjectLockLegalHoldStartWithOn (95.08s)
--- PASS: TestAccAWSS3BucketObject_updateSameFile (121.01s)
--- PASS: TestAccAWSS3BucketObject_defaultBucketSSE (46.34s)
--- PASS: TestAccAWSS3BucketObject_acl (141.31s)
--- PASS: TestAccAWSS3BucketObject_metadata (140.61s)
--- PASS: TestAccAWSS3BucketObject_ObjectLockLegalHoldStartWithNone (142.97s)
--- PASS: TestAccAWSS3BucketObject_tags (155.87s)
--- PASS: TestAccAWSS3BucketObject_tagsLeadingSlash (155.11s)
--- PASS: TestAccAWSS3BucketObject_ObjectLockRetentionStartWithNone (83.04s)
--- PASS: TestAccAWSS3BucketObject_storageClass (164.84s)
--- PASS: TestAccAWSS3BucketObject_ObjectLockRetentionStartWithSet (96.31s)
This has been released in version 3.10.0 of the Terraform AWS provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading. For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template for triage. Thanks! |
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks! |
…ncryption (#10200)
When an object is uploaded to a bucket that has default encryption configured, the object inherits the kms_key_id from the bucket. We therefore need to ignore changes to that attribute, which the user won't have specified. Setting this attribute to "" has the effect of re-encrypting the object with the default
aws/s3
key, which is not what the user intended or expected.Community Note
Relates OR Closes #10200
Release note for CHANGELOG:
Output from acceptance testing: