Skip to content

Commit

Permalink
provider/google: Add Timeout support to google_container_cluster
Browse files Browse the repository at this point in the history
  • Loading branch information
sovanesyan authored and stack72 committed Jun 28, 2017
1 parent 3c7cdf0 commit b2f789c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
18 changes: 15 additions & 3 deletions google/resource_container_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"log"
"net"
"regexp"
"time"

"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/helper/schema"
Expand All @@ -22,6 +23,12 @@ func resourceContainerCluster() *schema.Resource {
Update: resourceContainerClusterUpdate,
Delete: resourceContainerClusterDelete,

Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(30 * time.Minute),
Update: schema.DefaultTimeout(10 * time.Minute),
Delete: schema.DefaultTimeout(10 * time.Minute),
},

Schema: map[string]*schema.Schema{
"master_auth": &schema.Schema{
Type: schema.TypeList,
Expand Down Expand Up @@ -363,6 +370,8 @@ func resourceContainerClusterCreate(d *schema.ResourceData, meta interface{}) er
InitialNodeCount: int64(d.Get("initial_node_count").(int)),
}

timeoutInMinutes := int(d.Timeout(schema.TimeoutCreate).Minutes())

if v, ok := d.GetOk("master_auth"); ok {
masterAuths := v.([]interface{})
masterAuth := masterAuths[0].(map[string]interface{})
Expand Down Expand Up @@ -539,7 +548,7 @@ func resourceContainerClusterCreate(d *schema.ResourceData, meta interface{}) er
}

// Wait until it's created
waitErr := containerOperationWait(config, op, project, zoneName, "creating GKE cluster", 30, 3)
waitErr := containerOperationWait(config, op, project, zoneName, "creating GKE cluster", timeoutInMinutes, 3)
if waitErr != nil {
// The resource didn't actually create
d.SetId("")
Expand Down Expand Up @@ -626,6 +635,7 @@ func resourceContainerClusterUpdate(d *schema.ResourceData, meta interface{}) er
zoneName := d.Get("zone").(string)
clusterName := d.Get("name").(string)
desiredNodeVersion := d.Get("node_version").(string)
timeoutInMinutes := int(d.Timeout(schema.TimeoutUpdate).Minutes())

req := &container.UpdateClusterRequest{
Update: &container.ClusterUpdate{
Expand All @@ -639,7 +649,8 @@ func resourceContainerClusterUpdate(d *schema.ResourceData, meta interface{}) er
}

// Wait until it's updated
waitErr := containerOperationWait(config, op, project, zoneName, "updating GKE cluster", 10, 2)

waitErr := containerOperationWait(config, op, project, zoneName, "updating GKE cluster", timeoutInMinutes, 2)
if waitErr != nil {
return waitErr
}
Expand All @@ -660,6 +671,7 @@ func resourceContainerClusterDelete(d *schema.ResourceData, meta interface{}) er

zoneName := d.Get("zone").(string)
clusterName := d.Get("name").(string)
timeoutInMinutes := int(d.Timeout(schema.TimeoutDelete).Minutes())

log.Printf("[DEBUG] Deleting GKE cluster %s", d.Get("name").(string))
op, err := config.clientContainer.Projects.Zones.Clusters.Delete(
Expand All @@ -669,7 +681,7 @@ func resourceContainerClusterDelete(d *schema.ResourceData, meta interface{}) er
}

// Wait until it's deleted
waitErr := containerOperationWait(config, op, project, zoneName, "deleting GKE cluster", 10, 3)
waitErr := containerOperationWait(config, op, project, zoneName, "deleting GKE cluster", timeoutInMinutes, 3)
if waitErr != nil {
return waitErr
}
Expand Down
10 changes: 10 additions & 0 deletions website/docs/r/container_cluster.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -197,3 +197,13 @@ exported:

* `master_auth.cluster_ca_certificate` - Base64 encoded public certificate
that is the root of trust for the cluster

<a id="timeouts"></a>
## Timeouts

`google_container_cluster` provides the following
[Timeouts](/docs/configuration/resources.html#timeouts) configuration options:

- `create` - (Default `30 minutes`) Used for clusters
- `update` - (Default `10 minutes`) Used for updates to clusters
- `delete` - (Default `10 minutes`) Used for destroying clusters.

0 comments on commit b2f789c

Please sign in to comment.