Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make google_project_services resource importable #601

Merged
merged 2 commits into from
Oct 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions google/import_google_project_services_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package google

import (
"testing"

"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
)

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

resourceName := "google_project_services.acceptance"
projectId := "terraform-" + acctest.RandString(10)
services := []string{"iam.googleapis.com", "cloudresourcemanager.googleapis.com", "servicemanagement.googleapis.com"}

conf := testAccGoogleProjectAssociateServicesBasic(services, projectId, pname, org)

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
resource.TestStep{
Config: conf,
},
resource.TestStep{
ResourceName: resourceName,
ImportState: true,
ImportStateId: projectId,
ImportStateVerify: true,
},
},
})
}
4 changes: 4 additions & 0 deletions google/resource_google_project_services.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ func resourceGoogleProjectServices() *schema.Resource {
Read: resourceGoogleProjectServicesRead,
Update: resourceGoogleProjectServicesUpdate,
Delete: resourceGoogleProjectServicesDelete,
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},

Schema: map[string]*schema.Schema{
"project": &schema.Schema{
Expand Down Expand Up @@ -71,6 +74,7 @@ func resourceGoogleProjectServicesRead(d *schema.ResourceData, meta interface{})
return err
}

d.Set("project", d.Id())
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should project content be checked before overwriting?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eh I don't think it needs to be but may as well throw an error

d.Set("services", services)
return nil
}
Expand Down
8 changes: 8 additions & 0 deletions website/docs/r/google_project_services.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,11 @@ The following arguments are supported:

* `services` - (Required) The list of services that are enabled. Supports
update.

## Import

Project services can be imported using the `project_id`, e.g.

```
$ terraform import google_project_services.my_project your-project-id
```