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

Import google_compute_shared_vpc_host_project/google_compute_shared_vpc_service_project resources #1004

Merged
merged 2 commits into from
Jan 24, 2018
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
7 changes: 6 additions & 1 deletion google/resource_compute_shared_vpc_host_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ func resourceComputeSharedVpcHostProject() *schema.Resource {
Create: resourceComputeSharedVpcHostProjectCreate,
Read: resourceComputeSharedVpcHostProjectRead,
Delete: resourceComputeSharedVpcHostProjectDelete,
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},

Schema: map[string]*schema.Schema{
"project": &schema.Schema{
Expand Down Expand Up @@ -46,7 +49,7 @@ func resourceComputeSharedVpcHostProjectCreate(d *schema.ResourceData, meta inte
func resourceComputeSharedVpcHostProjectRead(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)

hostProject := d.Get("project").(string)
hostProject := d.Id()

project, err := config.clientCompute.Projects.Get(hostProject).Do()
if err != nil {
Expand All @@ -58,6 +61,8 @@ func resourceComputeSharedVpcHostProjectRead(d *schema.ResourceData, meta interf
d.SetId("")
}

d.Set("project", hostProject)

return nil
}

Expand Down
18 changes: 15 additions & 3 deletions google/resource_compute_shared_vpc_service_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,24 @@ package google

import (
"fmt"
"strings"

"google.golang.org/api/compute/v1"

"log"

"github.com/hashicorp/terraform/helper/schema"
"google.golang.org/api/googleapi"
"log"
)

func resourceComputeSharedVpcServiceProject() *schema.Resource {
return &schema.Resource{
Create: resourceComputeSharedVpcServiceProjectCreate,
Read: resourceComputeSharedVpcServiceProjectRead,
Delete: resourceComputeSharedVpcServiceProjectDelete,
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},

Schema: map[string]*schema.Schema{
"host_project": &schema.Schema{
Expand Down Expand Up @@ -59,8 +64,12 @@ func resourceComputeSharedVpcServiceProjectCreate(d *schema.ResourceData, meta i
func resourceComputeSharedVpcServiceProjectRead(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)

hostProject := d.Get("host_project").(string)
serviceProject := d.Get("service_project").(string)
split := strings.Split(d.Id(), "/")
if len(split) != 2 {
return fmt.Errorf("Error parsing resource ID %s", d.Id())
}
hostProject := split[0]
serviceProject := split[1]

associatedHostProject, err := config.clientCompute.Projects.GetXpnHost(serviceProject).Do()
if err != nil {
Expand All @@ -76,6 +85,9 @@ func resourceComputeSharedVpcServiceProjectRead(d *schema.ResourceData, meta int
return nil
}

d.Set("host_project", hostProject)
d.Set("service_project", serviceProject)

return nil
}

Expand Down
14 changes: 14 additions & 0 deletions google/resource_compute_shared_vpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ func TestAccComputeSharedVpc_basic(t *testing.T) {
hostProject := "xpn-host-" + acctest.RandString(10)
serviceProject := "xpn-service-" + acctest.RandString(10)

hostProjectResourceName := "google_compute_shared_vpc_host_project.host"
serviceProjectResourceName := "google_compute_shared_vpc_service_project.service"

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Expand All @@ -27,6 +30,17 @@ func TestAccComputeSharedVpc_basic(t *testing.T) {
testAccCheckComputeSharedVpcServiceProject(hostProject, serviceProject, true),
),
},
// Test import.
resource.TestStep{
ResourceName: hostProjectResourceName,
ImportState: true,
ImportStateVerify: true,
},
resource.TestStep{
ResourceName: serviceProjectResourceName,
ImportState: true,
ImportStateVerify: true,
},
// Use a separate TestStep rather than a CheckDestroy because we need the project to still exist.
resource.TestStep{
Config: testAccComputeSharedVpc_disabled(hostProject, serviceProject, org, billingId),
Expand Down
7 changes: 7 additions & 0 deletions website/docs/r/compute_shared_vpc_host_project.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,10 @@ The following arguments are expected:

* `project` - (Required) The ID of the project that will serve as a Shared VPC host project

## Import

Google Compute Engine Shared VPC host project feature can be imported using the `project`, e.g.

```
$ terraform import google_compute_shared_vpc_host_project.host host-project-id
```
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,11 @@ The following arguments are expected:
* `host_project` - (Required) The ID of a host project to associate.

* `service_project` - (Required) The ID of the project that will serve as a Shared VPC service project.

## Import

Google Compute Engine Shared VPC service project feature can be imported using the `host_project` and `service_project`, e.g.

```
$ terraform import google_compute_shared_vpc_service_project.service1 host-project-id/service-project-id-1
```