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

F d 2217 #11

Merged
merged 3 commits into from
Dec 12, 2017
Merged
Changes from 1 commit
Commits
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
Prev Previous commit
Next Next commit
hashicorp#2217: added acceptance test for basic case
  • Loading branch information
trung committed Nov 16, 2017
commit d7658da5b0bd7dd0d795451108eb1e2ca8b80699
19 changes: 15 additions & 4 deletions aws/data_source_aws_s3_bucket.go
Original file line number Diff line number Diff line change
@@ -19,19 +19,23 @@ func dataSourceAwsS3Bucket() *schema.Resource {
Required: true,
},
"server_side_encryption_configuration": {
Type: schema.TypeSet,
Type: schema.TypeList,
MaxItems: 1,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"enabled": {
Type: schema.TypeBool,
Computed: true,
},
"rule": {
Type: schema.TypeSet,
Type: schema.TypeList,
MaxItems: 1,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"apply_server_side_encryption_by_default": {
Type: schema.TypeSet,
Type: schema.TypeList,
MaxItems: 1,
Computed: true,
Elem: &schema.Resource{
@@ -119,7 +123,13 @@ func bucketEncryption(data *schema.ResourceData, bucket string, conn *s3.S3) err
output, err := conn.GetBucketEncryption(input)
if err != nil {
if isAWSErr(err, "ServerSideEncryptionConfigurationNotFoundError", "encryption configuration was not found") {

log.Printf("[DEBUG] Default encryption is not enabled for %s", bucket)
data.Set("server_side_encryption_configuration", []map[string]interface{}{
{
"enabled": false,
},
})
return nil
} else {
return err
}
@@ -133,6 +143,7 @@ func bucketEncryption(data *schema.ResourceData, bucket string, conn *s3.S3) err
defaultRule[0]["sse_algorithm"] = aws.StringValue(defaultRuleConfiguration.SSEAlgorithm)

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

21 changes: 21 additions & 0 deletions aws/data_source_aws_s3_bucket_test.go
Original file line number Diff line number Diff line change
@@ -56,6 +56,27 @@ func TestAccDataSourceS3Bucket_website(t *testing.T) {
})
}

func TestAccDataSourceS3Bucket_whenDefaultEncryptionNotEnabled(t *testing.T) {
rInt := acctest.RandInt()

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccAWSDataSourceS3BucketConfig_basic(rInt),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSS3BucketExists("data.aws_s3_bucket.bucket"),
resource.TestCheckResourceAttr(
"data.aws_s3_bucket.bucket", "server_side_encryption_configuration.0.enabled", "false"),
resource.TestCheckResourceAttr(
"data.aws_s3_bucket.bucket", "server_side_encryption_configuration.0.rule.#", "0"),
),
},
},
})
}

func testAccAWSDataSourceS3BucketConfig_basic(randInt int) string {
return fmt.Sprintf(`
resource "aws_s3_bucket" "bucket" {