Adding some other simple S3 Bucket Object (Optional) Inputs
This commit is contained in:
parent
d0409f1f1e
commit
2b7a13b609
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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())
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue