From 2b7a13b6091bb5b8499f9c441ba92b7f23d2b90d Mon Sep 17 00:00:00 2001 From: stack72 Date: Thu, 17 Sep 2015 20:10:35 +0100 Subject: [PATCH] Adding some other simple S3 Bucket Object (Optional) Inputs --- .../aws/resource_aws_s3_bucket_object.go | 47 +++++++++++++++++-- .../aws/resource_aws_s3_bucket_object_test.go | 41 ++++++++++++++++ .../aws/r/s3_bucket_object.html.markdown | 5 ++ 3 files changed, 90 insertions(+), 3 deletions(-) diff --git a/builtin/providers/aws/resource_aws_s3_bucket_object.go b/builtin/providers/aws/resource_aws_s3_bucket_object.go index 9d46952d07..537ed32974 100644 --- a/builtin/providers/aws/resource_aws_s3_bucket_object.go +++ b/builtin/providers/aws/resource_aws_s3_bucket_object.go @@ -26,6 +26,31 @@ func resourceAwsS3BucketObject() *schema.Resource { ForceNew: true, }, + "cache_control": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + }, + + "content_disposition": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + }, + + "content_encoding": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + }, + + "content_language": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + }, + + "content_type": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + }, + "key": &schema.Schema{ Type: schema.TypeString, Required: true, @@ -52,6 +77,11 @@ func resourceAwsS3BucketObjectPut(d *schema.ResourceData, meta interface{}) erro bucket := d.Get("bucket").(string) key := d.Get("key").(string) source := d.Get("source").(string) + encoding := d.Get("content_encoding").(string) + contentType := d.Get("content_type").(string) + cacheControl := d.Get("cache_control").(string) + contentLanguage := d.Get("content_language").(string) + contentDisposition := d.Get("content_disposition").(string) file, err := os.Open(source) @@ -61,9 +91,14 @@ func resourceAwsS3BucketObjectPut(d *schema.ResourceData, meta interface{}) erro resp, err := s3conn.PutObject( &s3.PutObjectInput{ - Bucket: aws.String(bucket), - Key: aws.String(key), - Body: file, + Bucket: aws.String(bucket), + Key: aws.String(key), + Body: file, + CacheControl: aws.String(cacheControl), + ContentDisposition: aws.String(contentDisposition), + ContentEncoding: aws.String(encoding), + ContentLanguage: aws.String(contentLanguage), + ContentType: aws.String(contentType), }) if err != nil { @@ -99,6 +134,12 @@ func resourceAwsS3BucketObjectRead(d *schema.ResourceData, meta interface{}) err return err } + d.Set("cache_control", resp.CacheControl) + d.Set("content_disposition", resp.ContentDisposition) + d.Set("content_encoding", resp.ContentEncoding) + d.Set("content_language", resp.ContentLanguage) + d.Set("content_type", resp.ContentType) + log.Printf("[DEBUG] Reading S3 Bucket Object meta: %s", resp) return nil } diff --git a/builtin/providers/aws/resource_aws_s3_bucket_object_test.go b/builtin/providers/aws/resource_aws_s3_bucket_object_test.go index 4f947736ae..5e1480be23 100644 --- a/builtin/providers/aws/resource_aws_s3_bucket_object_test.go +++ b/builtin/providers/aws/resource_aws_s3_bucket_object_test.go @@ -36,6 +36,31 @@ func TestAccAWSS3BucketObject_basic(t *testing.T) { }) } +func TestAccAWSS3BucketObject_withContentCharacteristics(t *testing.T) { + // first write some data to the tempfile just so it's not 0 bytes. + ioutil.WriteFile(tf.Name(), []byte("{anything will do }"), 0644) + resource.Test(t, resource.TestCase{ + PreCheck: func() { + if err != nil { + panic(err) + } + testAccPreCheck(t) + }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSS3BucketObjectDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccAWSS3BucketObjectConfig_withContentCharacteristics, + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSS3BucketObjectExists("aws_s3_bucket_object.object"), + resource.TestCheckResourceAttr( + "aws_s3_bucket_object.object", "content_type", "binary/octet-stream"), + ), + }, + }, + }) +} + func testAccCheckAWSS3BucketObjectDestroy(s *terraform.State) error { s3conn := testAccProvider.Meta().(*AWSClient).s3conn @@ -95,5 +120,21 @@ resource "aws_s3_bucket_object" "object" { bucket = "${aws_s3_bucket.object_bucket.bucket}" key = "test-key" source = "%s" + content_type = "binary/octet-stream" +} +`, randomBucket, tf.Name()) + +var testAccAWSS3BucketObjectConfig_withContentCharacteristics = fmt.Sprintf(` +resource "aws_s3_bucket" "object_bucket_2" { + bucket = "tf-object-test-bucket-%d" +} + +resource "aws_s3_bucket_object" "object" { + bucket = "${aws_s3_bucket.object_bucket_2.bucket}" + key = "test-key" + source = "%s" + content_language = "en" + content_type = "binary/octet-stream" + } `, randomBucket, tf.Name()) diff --git a/website/source/docs/providers/aws/r/s3_bucket_object.html.markdown b/website/source/docs/providers/aws/r/s3_bucket_object.html.markdown index 63d201b826..649130f80a 100644 --- a/website/source/docs/providers/aws/r/s3_bucket_object.html.markdown +++ b/website/source/docs/providers/aws/r/s3_bucket_object.html.markdown @@ -29,6 +29,11 @@ The following arguments are supported: * `bucket` - (Required) The name of the bucket to put the file in. * `key` - (Required) The name of the object once it is in the bucket. * `source` - (Required) The path to the source file being uploaded to the bucket. +* `cache_control` - (Optional) Specifies caching behavior along the request/reply chain. +* `content_disposition` - (Optional) Specifies presentational information for the object. +* `content_encoding` - (Optional) Specifies what content encodings have been applied to the object and thus what decoding mechanisms must be applied to obtain the media-type referenced by the Content-Type header field. +* `content_language` - (Optional) The language the content is in. +* `content_type` - (Optional) A standard MIME type describing the format of the object data. ## Attributes Reference