Skip to content

Commit

Permalink
Add import support for google_compute_backend_bucket (#736)
Browse files Browse the repository at this point in the history
* Add import support for google_compute_backend_bucket
* Improve docs for consistency
  • Loading branch information
rosbo authored Nov 13, 2017
1 parent c8d2131 commit a6378fc
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
31 changes: 31 additions & 0 deletions google/import_compute_backend_bucket_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package google

import (
"fmt"
"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
"testing"
)

func TestAccComputeBackendBucket_import(t *testing.T) {
t.Parallel()

backendName := fmt.Sprintf("tf-test-%s", acctest.RandString(10))
storageName := fmt.Sprintf("tf-test-%s", acctest.RandString(10))

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckComputeBackendBucketDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccComputeBackendBucket_basic(backendName, storageName),
},
resource.TestStep{
ResourceName: "google_compute_backend_bucket.foobar",
ImportState: true,
ImportStateVerify: true,
},
},
})
}
5 changes: 5 additions & 0 deletions google/resource_compute_backend_bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ func resourceComputeBackendBucket() *schema.Resource {
Update: resourceComputeBackendBucketUpdate,
Delete: resourceComputeBackendBucketDelete,

Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},

Schema: map[string]*schema.Schema{
"name": &schema.Schema{
Type: schema.TypeString,
Expand Down Expand Up @@ -111,6 +115,7 @@ func resourceComputeBackendBucketRead(d *schema.ResourceData, meta interface{})
return handleNotFoundError(err, d, fmt.Sprintf("Backend Bucket %q", d.Get("name").(string)))
}

d.Set("name", bucket.Name)
d.Set("bucket_name", bucket.BucketName)
d.Set("description", bucket.Description)
d.Set("enable_cdn", bucket.EnableCdn)
Expand Down
10 changes: 9 additions & 1 deletion website/docs/r/compute_backend_bucket.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ and
## Example Usage

```hcl
resource "google_compute_backend_bucket" "foobar" {
resource "google_compute_backend_bucket" "image_backend" {
name = "image-backend-bucket"
description = "Contains beautiful images"
bucket_name = "${google_storage_bucket.image_bucket.name}"
Expand Down Expand Up @@ -53,3 +53,11 @@ The following arguments are supported:
In addition to the arguments listed above, the following computed attributes are exported:

* `self_link` - The URI of the created resource.

## Import

Backend buckets can be imported using the `name`, e.g.

```
$ terraform import google_compute_backend_bucket.image_backend image-backend-bucket
```

0 comments on commit a6378fc

Please sign in to comment.