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

Add timeouts for google_container_cluster #13203

Closed
wants to merge 1 commit into from
Closed
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
17 changes: 14 additions & 3 deletions builtin/providers/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/schema"
"google.golang.org/api/container/v1"
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{
"initial_node_count": &schema.Schema{
Type: schema.TypeInt,
Expand Down Expand Up @@ -317,6 +324,7 @@ func resourceContainerClusterCreate(d *schema.ResourceData, meta interface{}) er
return fmt.Errorf("Cannot specify more than one master_auth.")
}
masterAuth := masterAuths[0].(map[string]interface{})
timeoutInMinutes := int(d.Timeout(schema.TimeoutCreate).Minutes())

cluster := &container.Cluster{
MasterAuth: &container.MasterAuth{
Expand Down Expand Up @@ -450,7 +458,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 @@ -544,6 +552,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 @@ -557,7 +566,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 @@ -578,6 +588,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 @@ -587,7 +598,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
Original file line number Diff line number Diff line change
Expand Up @@ -174,3 +174,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.