From a6378fc3d45f438c5fdba694baa1804687b26667 Mon Sep 17 00:00:00 2001 From: Vincent Roseberry Date: Mon, 13 Nov 2017 15:59:34 -0800 Subject: [PATCH] Add import support for google_compute_backend_bucket (#736) * Add import support for google_compute_backend_bucket * Improve docs for consistency --- google/import_compute_backend_bucket_test.go | 31 +++++++++++++++++++ google/resource_compute_backend_bucket.go | 5 +++ .../r/compute_backend_bucket.html.markdown | 10 +++++- 3 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 google/import_compute_backend_bucket_test.go diff --git a/google/import_compute_backend_bucket_test.go b/google/import_compute_backend_bucket_test.go new file mode 100644 index 00000000000..5301cd83095 --- /dev/null +++ b/google/import_compute_backend_bucket_test.go @@ -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, + }, + }, + }) +} diff --git a/google/resource_compute_backend_bucket.go b/google/resource_compute_backend_bucket.go index cef1c81d979..336df9d52ce 100644 --- a/google/resource_compute_backend_bucket.go +++ b/google/resource_compute_backend_bucket.go @@ -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, @@ -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) diff --git a/website/docs/r/compute_backend_bucket.html.markdown b/website/docs/r/compute_backend_bucket.html.markdown index c8facd3942f..6866bb5e0a8 100644 --- a/website/docs/r/compute_backend_bucket.html.markdown +++ b/website/docs/r/compute_backend_bucket.html.markdown @@ -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}" @@ -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 +```