mirror of
https://github.com/letic/terraform-provider-google.git
synced 2024-10-06 18:51:13 +00:00
Add additional properties for google resource storage bucket object. (#14259)
This commit is contained in:
parent
99ab5cc6c4
commit
06b92096dd
@ -32,6 +32,37 @@ func resourceStorageBucketObject() *schema.Resource {
|
|||||||
ForceNew: true,
|
ForceNew: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
"cache_control": &schema.Schema{
|
||||||
|
Type: schema.TypeString,
|
||||||
|
ForceNew: true,
|
||||||
|
Optional: true,
|
||||||
|
},
|
||||||
|
|
||||||
|
"content_disposition": &schema.Schema{
|
||||||
|
Type: schema.TypeString,
|
||||||
|
ForceNew: true,
|
||||||
|
Optional: true,
|
||||||
|
},
|
||||||
|
|
||||||
|
"content_encoding": &schema.Schema{
|
||||||
|
Type: schema.TypeString,
|
||||||
|
ForceNew: true,
|
||||||
|
Optional: true,
|
||||||
|
},
|
||||||
|
|
||||||
|
"content_language": &schema.Schema{
|
||||||
|
Type: schema.TypeString,
|
||||||
|
ForceNew: true,
|
||||||
|
Optional: true,
|
||||||
|
},
|
||||||
|
|
||||||
|
"content_type": &schema.Schema{
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Optional: true,
|
||||||
|
ForceNew: true,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
|
||||||
"content": &schema.Schema{
|
"content": &schema.Schema{
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
@ -62,6 +93,13 @@ func resourceStorageBucketObject() *schema.Resource {
|
|||||||
ForceNew: true,
|
ForceNew: true,
|
||||||
ConflictsWith: []string{"content"},
|
ConflictsWith: []string{"content"},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
"storage_class": &schema.Schema{
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Optional: true,
|
||||||
|
ForceNew: true,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -92,6 +130,30 @@ func resourceStorageBucketObjectCreate(d *schema.ResourceData, meta interface{})
|
|||||||
objectsService := storage.NewObjectsService(config.clientStorage)
|
objectsService := storage.NewObjectsService(config.clientStorage)
|
||||||
object := &storage.Object{Bucket: bucket}
|
object := &storage.Object{Bucket: bucket}
|
||||||
|
|
||||||
|
if v, ok := d.GetOk("cache_control"); ok {
|
||||||
|
object.CacheControl = v.(string)
|
||||||
|
}
|
||||||
|
|
||||||
|
if v, ok := d.GetOk("content_disposition"); ok {
|
||||||
|
object.ContentDisposition = v.(string)
|
||||||
|
}
|
||||||
|
|
||||||
|
if v, ok := d.GetOk("content_encoding"); ok {
|
||||||
|
object.ContentEncoding = v.(string)
|
||||||
|
}
|
||||||
|
|
||||||
|
if v, ok := d.GetOk("content_language"); ok {
|
||||||
|
object.ContentLanguage = v.(string)
|
||||||
|
}
|
||||||
|
|
||||||
|
if v, ok := d.GetOk("content_type"); ok {
|
||||||
|
object.ContentType = v.(string)
|
||||||
|
}
|
||||||
|
|
||||||
|
if v, ok := d.GetOk("storage_class"); ok {
|
||||||
|
object.StorageClass = v.(string)
|
||||||
|
}
|
||||||
|
|
||||||
insertCall := objectsService.Insert(bucket, object)
|
insertCall := objectsService.Insert(bucket, object)
|
||||||
insertCall.Name(name)
|
insertCall.Name(name)
|
||||||
insertCall.Media(media)
|
insertCall.Media(media)
|
||||||
@ -133,6 +195,12 @@ func resourceStorageBucketObjectRead(d *schema.ResourceData, meta interface{}) e
|
|||||||
|
|
||||||
d.Set("md5hash", res.Md5Hash)
|
d.Set("md5hash", res.Md5Hash)
|
||||||
d.Set("crc32c", res.Crc32c)
|
d.Set("crc32c", res.Crc32c)
|
||||||
|
d.Set("cache_control", res.CacheControl)
|
||||||
|
d.Set("content_disposition", res.ContentDisposition)
|
||||||
|
d.Set("content_encoding", res.ContentEncoding)
|
||||||
|
d.Set("content_language", res.ContentLanguage)
|
||||||
|
d.Set("content_type", res.ContentType)
|
||||||
|
d.Set("storage_class", res.StorageClass)
|
||||||
|
|
||||||
d.SetId(objectGetId(res))
|
d.SetId(objectGetId(res))
|
||||||
|
|
||||||
|
@ -64,7 +64,113 @@ func TestAccGoogleStorageObject_content(t *testing.T) {
|
|||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
resource.TestStep{
|
resource.TestStep{
|
||||||
Config: testGoogleStorageBucketsObjectContent(bucketName),
|
Config: testGoogleStorageBucketsObjectContent(bucketName),
|
||||||
Check: testAccCheckGoogleStorageObject(bucketName, objectName, data_md5),
|
Check: resource.ComposeTestCheckFunc(
|
||||||
|
testAccCheckGoogleStorageObject(bucketName, objectName, data_md5),
|
||||||
|
resource.TestCheckResourceAttr(
|
||||||
|
"google_storage_bucket_object.object", "content_type", "text/plain; charset=utf-8"),
|
||||||
|
resource.TestCheckResourceAttr(
|
||||||
|
"google_storage_bucket_object.object", "storage_class", "STANDARD"),
|
||||||
|
),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestAccGoogleStorageObject_withContentCharacteristics(t *testing.T) {
|
||||||
|
bucketName := testBucketName()
|
||||||
|
data := []byte(content)
|
||||||
|
h := md5.New()
|
||||||
|
h.Write(data)
|
||||||
|
data_md5 := base64.StdEncoding.EncodeToString(h.Sum(nil))
|
||||||
|
ioutil.WriteFile(tf.Name(), data, 0644)
|
||||||
|
|
||||||
|
disposition, encoding, language, content_type := "inline", "compress", "en", "binary/octet-stream"
|
||||||
|
resource.Test(t, resource.TestCase{
|
||||||
|
PreCheck: func() {
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
testAccPreCheck(t)
|
||||||
|
},
|
||||||
|
Providers: testAccProviders,
|
||||||
|
CheckDestroy: testAccGoogleStorageObjectDestroy,
|
||||||
|
Steps: []resource.TestStep{
|
||||||
|
resource.TestStep{
|
||||||
|
Config: testGoogleStorageBucketsObject_optionalContentFields(
|
||||||
|
bucketName, disposition, encoding, language, content_type),
|
||||||
|
Check: resource.ComposeTestCheckFunc(
|
||||||
|
testAccCheckGoogleStorageObject(bucketName, objectName, data_md5),
|
||||||
|
resource.TestCheckResourceAttr(
|
||||||
|
"google_storage_bucket_object.object", "content_disposition", disposition),
|
||||||
|
resource.TestCheckResourceAttr(
|
||||||
|
"google_storage_bucket_object.object", "content_encoding", encoding),
|
||||||
|
resource.TestCheckResourceAttr(
|
||||||
|
"google_storage_bucket_object.object", "content_language", language),
|
||||||
|
resource.TestCheckResourceAttr(
|
||||||
|
"google_storage_bucket_object.object", "content_type", content_type),
|
||||||
|
),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestAccGoogleStorageObject_cacheControl(t *testing.T) {
|
||||||
|
bucketName := testBucketName()
|
||||||
|
data := []byte(content)
|
||||||
|
h := md5.New()
|
||||||
|
h.Write(data)
|
||||||
|
data_md5 := base64.StdEncoding.EncodeToString(h.Sum(nil))
|
||||||
|
ioutil.WriteFile(tf.Name(), data, 0644)
|
||||||
|
|
||||||
|
cacheControl := "private"
|
||||||
|
resource.Test(t, resource.TestCase{
|
||||||
|
PreCheck: func() {
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
testAccPreCheck(t)
|
||||||
|
},
|
||||||
|
Providers: testAccProviders,
|
||||||
|
CheckDestroy: testAccGoogleStorageObjectDestroy,
|
||||||
|
Steps: []resource.TestStep{
|
||||||
|
resource.TestStep{
|
||||||
|
Config: testGoogleStorageBucketsObject_cacheControl(bucketName, cacheControl),
|
||||||
|
Check: resource.ComposeTestCheckFunc(
|
||||||
|
testAccCheckGoogleStorageObject(bucketName, objectName, data_md5),
|
||||||
|
resource.TestCheckResourceAttr(
|
||||||
|
"google_storage_bucket_object.object", "cache_control", cacheControl),
|
||||||
|
),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestAccGoogleStorageObject_storageClass(t *testing.T) {
|
||||||
|
bucketName := testBucketName()
|
||||||
|
data := []byte(content)
|
||||||
|
h := md5.New()
|
||||||
|
h.Write(data)
|
||||||
|
data_md5 := base64.StdEncoding.EncodeToString(h.Sum(nil))
|
||||||
|
ioutil.WriteFile(tf.Name(), data, 0644)
|
||||||
|
|
||||||
|
storageClass := "MULTI_REGIONAL"
|
||||||
|
resource.Test(t, resource.TestCase{
|
||||||
|
PreCheck: func() {
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
testAccPreCheck(t)
|
||||||
|
},
|
||||||
|
Providers: testAccProviders,
|
||||||
|
CheckDestroy: testAccGoogleStorageObjectDestroy,
|
||||||
|
Steps: []resource.TestStep{
|
||||||
|
resource.TestStep{
|
||||||
|
Config: testGoogleStorageBucketsObject_storageClass(bucketName, storageClass),
|
||||||
|
Check: resource.ComposeTestCheckFunc(
|
||||||
|
testAccCheckGoogleStorageObject(bucketName, objectName, data_md5),
|
||||||
|
resource.TestCheckResourceAttr(
|
||||||
|
"google_storage_bucket_object.object", "storage_class", storageClass),
|
||||||
|
),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
@ -129,6 +235,7 @@ resource "google_storage_bucket_object" "object" {
|
|||||||
}
|
}
|
||||||
`, bucketName, objectName, content)
|
`, bucketName, objectName, content)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testGoogleStorageBucketsObjectBasic(bucketName string) string {
|
func testGoogleStorageBucketsObjectBasic(bucketName string) string {
|
||||||
return fmt.Sprintf(`
|
return fmt.Sprintf(`
|
||||||
resource "google_storage_bucket" "bucket" {
|
resource "google_storage_bucket" "bucket" {
|
||||||
@ -143,3 +250,52 @@ resource "google_storage_bucket_object" "object" {
|
|||||||
}
|
}
|
||||||
`, bucketName, objectName, tf.Name())
|
`, bucketName, objectName, tf.Name())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testGoogleStorageBucketsObject_optionalContentFields(
|
||||||
|
bucketName, disposition, encoding, language, content_type string) string {
|
||||||
|
return fmt.Sprintf(`
|
||||||
|
resource "google_storage_bucket" "bucket" {
|
||||||
|
name = "%s"
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "google_storage_bucket_object" "object" {
|
||||||
|
name = "%s"
|
||||||
|
bucket = "${google_storage_bucket.bucket.name}"
|
||||||
|
content = "%s"
|
||||||
|
content_disposition = "%s"
|
||||||
|
content_encoding = "%s"
|
||||||
|
content_language = "%s"
|
||||||
|
content_type = "%s"
|
||||||
|
}
|
||||||
|
`, bucketName, objectName, content, disposition, encoding, language, content_type)
|
||||||
|
}
|
||||||
|
|
||||||
|
func testGoogleStorageBucketsObject_cacheControl(bucketName, cacheControl string) string {
|
||||||
|
return fmt.Sprintf(`
|
||||||
|
resource "google_storage_bucket" "bucket" {
|
||||||
|
name = "%s"
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "google_storage_bucket_object" "object" {
|
||||||
|
name = "%s"
|
||||||
|
bucket = "${google_storage_bucket.bucket.name}"
|
||||||
|
source = "%s"
|
||||||
|
cache_control = "%s"
|
||||||
|
}
|
||||||
|
`, bucketName, objectName, tf.Name(), cacheControl)
|
||||||
|
}
|
||||||
|
|
||||||
|
func testGoogleStorageBucketsObject_storageClass(bucketName string, storageClass string) string {
|
||||||
|
return fmt.Sprintf(`
|
||||||
|
resource "google_storage_bucket" "bucket" {
|
||||||
|
name = "%s"
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "google_storage_bucket_object" "object" {
|
||||||
|
name = "%s"
|
||||||
|
bucket = "${google_storage_bucket.bucket.name}"
|
||||||
|
content = "%s"
|
||||||
|
storage_class = "%s"
|
||||||
|
}
|
||||||
|
`, bucketName, objectName, content, storageClass)
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user