From 7054fdfa13cb3cf68978b0b08a582fcfe742c9f6 Mon Sep 17 00:00:00 2001 From: Paddy Date: Thu, 1 Dec 2016 10:38:27 -0800 Subject: [PATCH] providers/google: make projects importable. This change doesn't make much sense now, as projects are read-only anyways, so there's not a lot that importing really does for you--you can already reference pre-existing projects just by defining them in your config. But as we discussed #10425, this change made more and more sense. In a world where projects can be created, we can no longer reference pre-existing projects just by defining them in config. We get that ability back by making projects importable. --- .../google/import_google_project_test.go | 29 +++++++++++++++++++ .../google/resource_google_project.go | 3 ++ .../source/docs/import/importability.html.md | 1 + 3 files changed, 33 insertions(+) create mode 100644 builtin/providers/google/import_google_project_test.go diff --git a/builtin/providers/google/import_google_project_test.go b/builtin/providers/google/import_google_project_test.go new file mode 100644 index 000000000000..b35c8d6bcc76 --- /dev/null +++ b/builtin/providers/google/import_google_project_test.go @@ -0,0 +1,29 @@ +package google + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform/helper/resource" +) + +func TestAccGoogleProject_importBasic(t *testing.T) { + resourceName := "google_project.acceptance" + conf := fmt.Sprintf(testAccGoogleProject_basic, projectId) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: conf, + }, + + resource.TestStep{ + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} diff --git a/builtin/providers/google/resource_google_project.go b/builtin/providers/google/resource_google_project.go index b46d661458fc..9e845ed339a8 100644 --- a/builtin/providers/google/resource_google_project.go +++ b/builtin/providers/google/resource_google_project.go @@ -29,6 +29,9 @@ func resourceGoogleProject() *schema.Resource { Read: resourceGoogleProjectRead, Update: resourceGoogleProjectUpdate, Delete: resourceGoogleProjectDelete, + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, Schema: map[string]*schema.Schema{ "id": &schema.Schema{ diff --git a/website/source/docs/import/importability.html.md b/website/source/docs/import/importability.html.md index b3c56461d431..a3b305738c03 100644 --- a/website/source/docs/import/importability.html.md +++ b/website/source/docs/import/importability.html.md @@ -135,6 +135,7 @@ To make a resource importable, please see the * google_compute_instance_group_manager * google_compute_instance_template * google_compute_target_pool +* google_project ### OpenStack