From 8d8d3a728afaf7ab2b290d119ed231e5f30cd4ba Mon Sep 17 00:00:00 2001 From: Justin DiPierro Date: Sat, 1 Apr 2017 13:01:53 -0400 Subject: [PATCH 1/3] Google Compute Address Importability --- .../google/import_compute_address_test.go | 28 +++++++++++++++++++ .../google/resource_compute_address.go | 7 ++++- 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 builtin/providers/google/import_compute_address_test.go diff --git a/builtin/providers/google/import_compute_address_test.go b/builtin/providers/google/import_compute_address_test.go new file mode 100644 index 0000000000..db579f4c0c --- /dev/null +++ b/builtin/providers/google/import_compute_address_test.go @@ -0,0 +1,28 @@ +package google + +import ( + "testing" + + "github.com/hashicorp/terraform/helper/resource" +) + +func TestAccComputeAddress_importBasic(t *testing.T) { + resourceName := "google_compute_address.foobar" + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckComputeAddressDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccComputeAddress_basic, + }, + + resource.TestStep{ + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} diff --git a/builtin/providers/google/resource_compute_address.go b/builtin/providers/google/resource_compute_address.go index d4c9622308..54a60cc0ae 100644 --- a/builtin/providers/google/resource_compute_address.go +++ b/builtin/providers/google/resource_compute_address.go @@ -14,7 +14,12 @@ func resourceComputeAddress() *schema.Resource { Create: resourceComputeAddressCreate, Read: resourceComputeAddressRead, Delete: resourceComputeAddressDelete, - + Importer: &schema.ResourceImporter{ + State: func(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { + d.Set("name", d.Id()) + return []*schema.ResourceData{d}, nil + }, + }, Schema: map[string]*schema.Schema{ "name": &schema.Schema{ Type: schema.TypeString, From 8092d90f25961ace8b315cb9861acd7511960cbd Mon Sep 17 00:00:00 2001 From: Justin DiPierro Date: Sat, 1 Apr 2017 13:25:34 -0400 Subject: [PATCH 2/3] Importability for Google Compute Global Address --- .../import_compute_global_address_test.go | 28 +++++++++++++++++++ .../google/resource_compute_global_address.go | 7 ++++- 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 builtin/providers/google/import_compute_global_address_test.go diff --git a/builtin/providers/google/import_compute_global_address_test.go b/builtin/providers/google/import_compute_global_address_test.go new file mode 100644 index 0000000000..73e495644a --- /dev/null +++ b/builtin/providers/google/import_compute_global_address_test.go @@ -0,0 +1,28 @@ +package google + +import ( + "testing" + + "github.com/hashicorp/terraform/helper/resource" +) + +func TestAccComputeGlobalAddress_importBasic(t *testing.T) { + resourceName := "google_compute_global_address.foobar" + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckComputeGlobalAddressDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccComputeGlobalAddress_basic, + }, + + resource.TestStep{ + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} diff --git a/builtin/providers/google/resource_compute_global_address.go b/builtin/providers/google/resource_compute_global_address.go index e335e527a2..7f4df04a4a 100644 --- a/builtin/providers/google/resource_compute_global_address.go +++ b/builtin/providers/google/resource_compute_global_address.go @@ -14,7 +14,12 @@ func resourceComputeGlobalAddress() *schema.Resource { Create: resourceComputeGlobalAddressCreate, Read: resourceComputeGlobalAddressRead, Delete: resourceComputeGlobalAddressDelete, - + Importer: &schema.ResourceImporter{ + State: func(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { + d.Set("name", d.Id()) + return []*schema.ResourceData{d}, nil + }, + }, Schema: map[string]*schema.Schema{ "name": &schema.Schema{ Type: schema.TypeString, From 59d1d82d706dd59aff9453e124fb098e9bd7666c Mon Sep 17 00:00:00 2001 From: Justin DiPierro Date: Sat, 1 Apr 2017 13:45:41 -0400 Subject: [PATCH 3/3] Update docs for newly importable resources --- website/source/docs/import/importability.html.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/website/source/docs/import/importability.html.md b/website/source/docs/import/importability.html.md index 933c47a1dc..8fbdb48786 100644 --- a/website/source/docs/import/importability.html.md +++ b/website/source/docs/import/importability.html.md @@ -141,9 +141,11 @@ To make a resource importable, please see the ### Google +* google_compute_address * google_compute_autoscaler * google_compute_firewall * google_compute_forwarding_rule +* google_compute_global_address * google_compute_http_health_check * google_compute_instance_group_manager * google_compute_instance_template