mirror of
https://github.com/letic/terraform-provider-google.git
synced 2024-10-01 16:21:06 +00:00
Remove label from bucket (#1550)
* Remove label from bucket * Remove debugging statement * Fix typos
This commit is contained in:
parent
66afc153ab
commit
8c2f47ba69
@ -378,6 +378,15 @@ func resourceStorageBucketUpdate(d *schema.ResourceData, meta interface{}) error
|
||||
if len(sb.Labels) == 0 {
|
||||
sb.NullFields = append(sb.NullFields, "Labels")
|
||||
}
|
||||
|
||||
// To delete a label using PATCH, we have to explicitly set its value
|
||||
// to null.
|
||||
old, _ := d.GetChange("labels")
|
||||
for k := range old.(map[string]interface{}) {
|
||||
if _, ok := sb.Labels[k]; !ok {
|
||||
sb.NullFields = append(sb.NullFields, fmt.Sprintf("Labels.%s", k))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
res, err := config.clientStorage.Buckets.Patch(d.Get("name").(string), sb).Do()
|
||||
|
@ -558,14 +558,7 @@ func TestAccStorageBucket_labels(t *testing.T) {
|
||||
Providers: testAccProviders,
|
||||
CheckDestroy: testAccStorageBucketDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
resource.TestStep{
|
||||
Config: testAccStorageBucket_labels(bucketName),
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccCheckStorageBucketExists(
|
||||
"google_storage_bucket.bucket", bucketName, &bucket),
|
||||
testAccCheckStorageBucketHasLabel(&bucket, "my-label", "my-label-value"),
|
||||
),
|
||||
},
|
||||
// Going from two labels
|
||||
resource.TestStep{
|
||||
Config: testAccStorageBucket_updateLabels(bucketName),
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
@ -575,6 +568,26 @@ func TestAccStorageBucket_labels(t *testing.T) {
|
||||
testAccCheckStorageBucketHasLabel(&bucket, "a-new-label", "a-new-label-value"),
|
||||
),
|
||||
},
|
||||
resource.TestStep{
|
||||
ResourceName: "google_storage_bucket.bucket",
|
||||
ImportState: true,
|
||||
ImportStateVerify: true,
|
||||
},
|
||||
// Down to only one label (test single label deletion)
|
||||
resource.TestStep{
|
||||
Config: testAccStorageBucket_labels(bucketName),
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccCheckStorageBucketExists(
|
||||
"google_storage_bucket.bucket", bucketName, &bucket),
|
||||
testAccCheckStorageBucketHasLabel(&bucket, "my-label", "my-label-value"),
|
||||
),
|
||||
},
|
||||
resource.TestStep{
|
||||
ResourceName: "google_storage_bucket.bucket",
|
||||
ImportState: true,
|
||||
ImportStateVerify: true,
|
||||
},
|
||||
// And make sure deleting all labels work
|
||||
resource.TestStep{
|
||||
Config: testAccStorageBucket_basic(bucketName),
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
@ -583,6 +596,11 @@ func TestAccStorageBucket_labels(t *testing.T) {
|
||||
testAccCheckStorageBucketHasNoLabels(&bucket),
|
||||
),
|
||||
},
|
||||
resource.TestStep{
|
||||
ResourceName: "google_storage_bucket.bucket",
|
||||
ImportState: true,
|
||||
ImportStateVerify: true,
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user