Skip to content

Commit

Permalink
Merge branch 'handle-default-bucket-encryption' of ssh://github.com/m…
Browse files Browse the repository at this point in the history
…attburgess/terraform-provider-aws into mattburgess-handle-default-bucket-encryption
  • Loading branch information
bflad committed Oct 6, 2020
2 parents 14e1b4e + 51d009b commit 98dadd6
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 4 deletions.
8 changes: 8 additions & 0 deletions aws/resource_aws_s3_bucket_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,15 @@ func resourceAwsS3BucketObject() *schema.Resource {
"kms_key_id": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ValidateFunc: validateArn,
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
},
},

"etag": {
Expand Down
48 changes: 48 additions & 0 deletions aws/resource_aws_s3_bucket_object_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -955,6 +955,27 @@ func TestAccAWSS3BucketObject_ObjectLockRetentionStartWithSet(t *testing.T) {
})
}

func TestAccAWSS3BucketObject_defaultBucketSSE(t *testing.T) {
var obj1 s3.GetObjectOutput
resourceName := "aws_s3_bucket_object.object"
rInt := acctest.RandInt()

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSS3BucketObjectDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSS3BucketObjectConfig_defaultBucketSSE(rInt, "stuff"),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSS3BucketObjectExists(resourceName, &obj1),
testAccCheckAWSS3BucketObjectBody(&obj1, "stuff"),
),
},
},
})
}

func TestAccAWSS3BucketObject_ignoreTags(t *testing.T) {
var obj s3.GetObjectOutput
resourceName := "aws_s3_bucket_object.object"
Expand Down Expand Up @@ -1656,3 +1677,30 @@ resource "aws_s3_bucket_object" "object" {
}
`, randInt, source)
}

func testAccAWSS3BucketObjectConfig_defaultBucketSSE(randInt int, content string) string {
return fmt.Sprintf(`
resource "aws_kms_key" "test" {
description = "Encrypts test bucket objects"
deletion_window_in_days = 7
}
resource "aws_s3_bucket" "object_bucket" {
bucket = "tf-object-test-bucket-%d"
server_side_encryption_configuration {
rule {
apply_server_side_encryption_by_default {
kms_master_key_id = aws_kms_key.test.arn
sse_algorithm = "aws:kms"
}
}
}
}
resource "aws_s3_bucket_object" "object" {
bucket = aws_s3_bucket.object_bucket.bucket
key = "test-key"
content = %q
}
`, randInt, content)
}
7 changes: 3 additions & 4 deletions website/docs/r/s3_bucket_object.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,9 @@ for the object. Can be either "`STANDARD`", "`REDUCED_REDUNDANCY`", "`ONEZONE_IA
* `etag` - (Optional) Used to trigger updates. The only meaningful value is `${filemd5("path/to/file")}` (Terraform 0.11.12 or later) or `${md5(file("path/to/file"))}` (Terraform 0.11.11 or earlier).
This attribute is not compatible with KMS encryption, `kms_key_id` or `server_side_encryption = "aws:kms"`.
* `server_side_encryption` - (Optional) Specifies server-side encryption of the object in S3. Valid values are "`AES256`" and "`aws:kms`".
* `kms_key_id` - (Optional) Specifies the AWS KMS Key ARN to use for object encryption.
This value is a fully qualified **ARN** of the KMS Key. If using `aws_kms_key`,
use the exported `arn` attribute:
`kms_key_id = "${aws_kms_key.foo.arn}"`
* `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.
* `metadata` - (Optional) A map of keys/values to provision metadata (will be automatically prefixed by `x-amz-meta-`, note that only lowercase label are currently supported by the AWS Go API).
* `tags` - (Optional) A map of tags to assign to the object.
* `force_destroy` - (Optional) Allow the object to be deleted by removing any legal hold on any object version.
Expand Down

0 comments on commit 98dadd6

Please sign in to comment.