mirror of
https://github.com/letic/terraform-provider-google.git
synced 2024-10-06 18:51:13 +00:00
Make google_container_node_pool resources importable. (#284)
This commit is contained in:
parent
958f27892b
commit
f06970c97a
32
google/import_container_node_pool_test.go
Normal file
32
google/import_container_node_pool_test.go
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
package google
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/hashicorp/terraform/helper/acctest"
|
||||||
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestAccGoogleContainerNodePool_import(t *testing.T) {
|
||||||
|
resourceName := "google_container_node_pool.np"
|
||||||
|
cluster := fmt.Sprintf("tf-nodepool-test-%s", acctest.RandString(10))
|
||||||
|
np := fmt.Sprintf("tf-nodepool-test-%s", acctest.RandString(10))
|
||||||
|
conf := testAccContainerNodePool_basic(cluster, np)
|
||||||
|
resource.Test(t, resource.TestCase{
|
||||||
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
|
Providers: testAccProviders,
|
||||||
|
CheckDestroy: testAccCheckContainerNodePoolDestroy,
|
||||||
|
Steps: []resource.TestStep{
|
||||||
|
resource.TestStep{
|
||||||
|
Config: conf,
|
||||||
|
},
|
||||||
|
|
||||||
|
resource.TestStep{
|
||||||
|
ResourceName: resourceName,
|
||||||
|
ImportState: true,
|
||||||
|
ImportStateVerify: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
@ -3,6 +3,7 @@ package google
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/hashicorp/terraform/helper/resource"
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
"github.com/hashicorp/terraform/helper/schema"
|
"github.com/hashicorp/terraform/helper/schema"
|
||||||
@ -17,6 +18,10 @@ func resourceContainerNodePool() *schema.Resource {
|
|||||||
Delete: resourceContainerNodePoolDelete,
|
Delete: resourceContainerNodePoolDelete,
|
||||||
Exists: resourceContainerNodePoolExists,
|
Exists: resourceContainerNodePoolExists,
|
||||||
|
|
||||||
|
Importer: &schema.ResourceImporter{
|
||||||
|
State: resourceContainerNodePoolStateImporter,
|
||||||
|
},
|
||||||
|
|
||||||
Schema: map[string]*schema.Schema{
|
Schema: map[string]*schema.Schema{
|
||||||
"project": &schema.Schema{
|
"project": &schema.Schema{
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
@ -357,3 +362,16 @@ func resourceContainerNodePoolExists(d *schema.ResourceData, meta interface{}) (
|
|||||||
}
|
}
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func resourceContainerNodePoolStateImporter(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
|
||||||
|
parts := strings.Split(d.Id(), "/")
|
||||||
|
if len(parts) != 3 {
|
||||||
|
return nil, fmt.Errorf("Invalid container cluster specifier. Expecting {zone}/{cluster}/{name}")
|
||||||
|
}
|
||||||
|
|
||||||
|
d.Set("zone", parts[0])
|
||||||
|
d.Set("cluster", parts[1])
|
||||||
|
d.Set("name", parts[2])
|
||||||
|
|
||||||
|
return []*schema.ResourceData{d}, nil
|
||||||
|
}
|
||||||
|
@ -111,3 +111,11 @@ The `autoscaling` block supports:
|
|||||||
<= `maxNodeCount`.
|
<= `maxNodeCount`.
|
||||||
|
|
||||||
* `maxNodeCount` - (Required) Maximum number of nodes in the NodePool. Must be >= minNodeCount.
|
* `maxNodeCount` - (Required) Maximum number of nodes in the NodePool. Must be >= minNodeCount.
|
||||||
|
|
||||||
|
## Import
|
||||||
|
|
||||||
|
Node pools can be imported using the `zone`, `cluster` and `name`, e.g.
|
||||||
|
|
||||||
|
```
|
||||||
|
$ terraform import google_container_node_pool.mainpool us-east1-a/my-cluster/main-pool
|
||||||
|
```
|
Loading…
Reference in New Issue
Block a user