From 8d1292d608df575e3501d45e8268c157e95e45f8 Mon Sep 17 00:00:00 2001 From: Kazunori Kojima Date: Mon, 7 Mar 2016 09:31:33 +0900 Subject: [PATCH] Return empty string when input empty S3 bucket policy Before: "" -> "Error parsing JSON: unexpected end of JSON input" After: "" -> "" --- .../providers/aws/resource_aws_s3_bucket.go | 2 +- .../aws/resource_aws_s3_bucket_test.go | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/builtin/providers/aws/resource_aws_s3_bucket.go b/builtin/providers/aws/resource_aws_s3_bucket.go index 6bd9c451f..fc3c5deab 100644 --- a/builtin/providers/aws/resource_aws_s3_bucket.go +++ b/builtin/providers/aws/resource_aws_s3_bucket.go @@ -907,7 +907,7 @@ func removeNil(data map[string]interface{}) map[string]interface{} { } func normalizeJson(jsonString interface{}) string { - if jsonString == nil { + if jsonString == nil || jsonString == "" { return "" } var j interface{} diff --git a/builtin/providers/aws/resource_aws_s3_bucket_test.go b/builtin/providers/aws/resource_aws_s3_bucket_test.go index d306f5437..43b7a8ad6 100644 --- a/builtin/providers/aws/resource_aws_s3_bucket_test.go +++ b/builtin/providers/aws/resource_aws_s3_bucket_test.go @@ -69,6 +69,14 @@ func TestAccAWSS3Bucket_Policy(t *testing.T) { "aws_s3_bucket.bucket", ""), ), }, + resource.TestStep{ + Config: testAccAWSS3BucketConfigWithEmptyPolicy(rInt), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSS3BucketExists("aws_s3_bucket.bucket"), + testAccCheckAWSS3BucketPolicy( + "aws_s3_bucket.bucket", ""), + ), + }, }, }) } @@ -724,6 +732,16 @@ resource "aws_s3_bucket" "bucket" { `, randInt) } +func testAccAWSS3BucketConfigWithEmptyPolicy(randInt int) string { + return fmt.Sprintf(` +resource "aws_s3_bucket" "bucket" { + bucket = "tf-test-bucket-%d" + acl = "public-read" + policy = "" +} +`, randInt) +} + func testAccAWSS3BucketConfigWithVersioning(randInt int) string { return fmt.Sprintf(` resource "aws_s3_bucket" "bucket" {