mirror of
https://github.com/letic/terraform-provider-google.git
synced 2024-10-01 16:21:06 +00:00
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:
parent
b80aad4bc6
commit
360260d8d0
@ -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
|
||||
}
|
||||
|
||||
|
@ -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,
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
@ -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
|
||||
```
|
||||
|
Loading…
Reference in New Issue
Block a user