Skip to content
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

[dirty] [WIP] d/aws_s3_bucket: get default encryption configuration #2298

Closed
wants to merge 18 commits into from
Closed
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
90c1c22
test case to cover gp2 with iops
trung Sep 20, 2017
fdc3867
Merge branch 'master' of github.com:terraform-providers/terraform-pro…
trung Sep 21, 2017
68ed0d7
test case to cover gp2 with iops
trung Sep 20, 2017
285d3d6
merged upstream/master
trung Sep 28, 2017
14e39a1
Merge branch 'master' of github.com:terraform-providers/terraform-pro…
trung Oct 9, 2017
07cc945
Merge branch 'master' of github.com:terraform-providers/terraform-pro…
trung Oct 14, 2017
ea8d786
Merge branch 'master' of github.com:terraform-providers/terraform-pro…
trung Oct 24, 2017
d4223a8
Merge branch 'master' of github.com:terraform-providers/terraform-pro…
trung Nov 1, 2017
8a6cb04
Merge branch 'master' of github.com:terraform-providers/terraform-pro…
trung Nov 8, 2017
c217db2
Merge branch 'master' of github.com:terraform-providers/terraform-pro…
trung Nov 12, 2017
8579685
Merge branch 'master' of github.com:terraform-providers/terraform-pro…
trung Nov 13, 2017
33ba731
Merge branch 'master' of github.com:terraform-providers/terraform-pro…
trung Nov 15, 2017
a87fbe8
test case to cover gp2 with iops
trung Sep 20, 2017
d3ac253
test case to cover gp2 with iops
trung Sep 20, 2017
b4b50c9
Merge branch 'master' of github.com:trung/terraform-provider-aws
trung Nov 15, 2017
ddb02a8
#2217: get default encryption configuration for s3 bucket data source
trung Nov 15, 2017
6824b73
#2217: get default encryption configuration for s3 bucket data source
trung Nov 15, 2017
d4f08f7
#2217: get default encryption configuration for s3 bucket data source
trung Nov 15, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions aws/data_source_aws_s3_bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,41 @@ func dataSourceAwsS3Bucket() *schema.Resource {
Type: schema.TypeString,
Required: true,
},
"server_side_encryption_configuration": {
Type: schema.TypeSet,
MaxItems: 1,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"rule": {
Type: schema.TypeSet,
MaxItems: 1,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"apply_server_side_encryption_by_default": {
Type: schema.TypeSet,
MaxItems: 1,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"kms_master_key_id": {
Type: schema.TypeString,
Computed: true,
},
"sse_algorithm": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
},
},
},
},
},
},
"arn": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -70,6 +105,38 @@ func dataSourceAwsS3BucketRead(d *schema.ResourceData, meta interface{}) error {
return err
}

if err := bucketEncryption(d, bucket, conn); err != nil {
return err
}

return nil
}

func bucketEncryption(data *schema.ResourceData, bucket string, conn *s3.S3) error {
input := &s3.GetBucketEncryptionInput{
Bucket: aws.String(bucket),
}
output, err := conn.GetBucketEncryption(input)
if err != nil {
if isAWSErr(err, "ServerSideEncryptionConfigurationNotFoundError", "encryption configuration was not found") {

} else {
return err
}
}
if ruleCount := len(output.ServerSideEncryptionConfiguration.Rules); ruleCount != 1 {
return fmt.Errorf("expect one rule returned but there are %d rules. Changes required in the data source to support this", ruleCount)
}
defaultRuleConfiguration := output.ServerSideEncryptionConfiguration.Rules[0].ApplyServerSideEncryptionByDefault
defaultRule := make([]map[string]interface{}, 1)
defaultRule[0]["kms_master_key_id"] = aws.StringValue(defaultRuleConfiguration.KMSMasterKeyID)
defaultRule[0]["sse_algorithm"] = aws.StringValue(defaultRuleConfiguration.SSEAlgorithm)

encryptionConfiguration := make([]map[string]interface{}, 1)
encryptionConfiguration[0]["rule"] = make([]map[string]interface{}, 1)
encryptionConfiguration[0]["rule"].(map[string]interface{})["apply_server_side_encryption_by_default"] = defaultRule

data.Set("server_side_encryption_configuration", encryptionConfiguration)
return nil
}

Expand Down