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

aws_s3_bucket_object : detect empty values at plan time #9591

Merged
merged 1 commit into from
Aug 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
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
14 changes: 8 additions & 6 deletions aws/resource_aws_s3_bucket_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,17 @@ func resourceAwsS3BucketObject() *schema.Resource {

Schema: map[string]*schema.Schema{
"bucket": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validation.NoZeroValues,
},

"key": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validation.NoZeroValues,
},

"acl": {
Expand Down
32 changes: 32 additions & 0 deletions aws/resource_aws_s3_bucket_object_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"log"
"os"
"reflect"
"regexp"
"sort"
"strings"
"testing"
Expand Down Expand Up @@ -155,6 +156,28 @@ func testSweepS3BucketObjects(region string) error {
return nil
}

func TestAccAWSS3BucketObject_noNameNoKey(t *testing.T) {
bucketError := regexp.MustCompile(`bucket must not be empty`)
keyError := regexp.MustCompile(`key must not be empty`)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSS3BucketObjectDestroy,
Steps: []resource.TestStep{
{
PreConfig: func() {},
Config: testAccAWSS3BucketObjectConfigBasic("", "a key"),
ExpectError: bucketError,
},
{
PreConfig: func() {},
Config: testAccAWSS3BucketObjectConfigBasic("a name", ""),
ExpectError: keyError,
},
},
})
}
func TestAccAWSS3BucketObject_empty(t *testing.T) {
var obj s3.GetObjectOutput
resourceName := "aws_s3_bucket_object.object"
Expand Down Expand Up @@ -860,6 +883,15 @@ func testAccAWSS3BucketObjectCreateTempFile(t *testing.T, data string) string {
return filename
}

func testAccAWSS3BucketObjectConfigBasic(bucket, key string) string {
return fmt.Sprintf(`
resource "aws_s3_bucket_object" "object" {
bucket = "%s"
key = "%s"
}
`, bucket, key)
}

func testAccAWSS3BucketObjectConfigEmpty(randInt int) string {
return fmt.Sprintf(`
resource "aws_s3_bucket" "object_bucket" {
Expand Down