Add project to container cluster import name. (#1282)

* allow import of container cluster by project as well

* update docs for importing container cluster with project

* combine tests
This commit is contained in:
emily 2018-04-03 13:39:28 -07:00 committed by GitHub
parent b80aad4bc6
commit 360260d8d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 7 deletions

View File

@ -1492,14 +1492,20 @@ func flattenPodSecurityPolicyConfig(c *containerBeta.PodSecurityPolicyConfig) []
func resourceContainerClusterStateImporter(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
parts := strings.Split(d.Id(), "/")
if len(parts) != 2 {
return nil, fmt.Errorf("Invalid container cluster specifier. Expecting {zone}/{name}")
switch len(parts) {
case 2:
d.Set("zone", parts[0])
d.Set("name", parts[1])
case 3:
d.Set("project", parts[0])
d.Set("zone", parts[1])
d.Set("name", parts[2])
default:
return nil, fmt.Errorf("Invalid container cluster specifier. Expecting {zone}/{name} or {project}/{zone}/{name}")
}
d.Set("zone", parts[0])
d.Set("name", parts[1])
d.SetId(parts[1])
d.SetId(parts[len(parts)-1])
return []*schema.ResourceData{d}, nil
}

View File

@ -32,6 +32,12 @@ func TestAccContainerCluster_basic(t *testing.T) {
ImportState: true,
ImportStateVerify: true,
},
{
ResourceName: "google_container_cluster.primary",
ImportStateIdPrefix: fmt.Sprintf("%s/us-central1-a/", getTestProjectFromEnv()),
ImportState: true,
ImportStateVerify: true,
},
},
})
}

View File

@ -377,8 +377,11 @@ exported:
## Import
GKE clusters can be imported using the `zone`, and `name`, e.g.
GKE clusters can be imported using the `project` , `zone`, and `name`. If
the project is omitted, the default provider value will be used. Examples:
```
$ terraform import google_container_cluster.mycluster my-gcp-project/us-east1-a/my-cluster
$ terraform import google_container_cluster.mycluster us-east1-a/my-cluster
```