Skip to content

Commit

Permalink
add support for google_container_node_pool management (sans-tests)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidquarles committed Nov 2, 2017
1 parent 905ee21 commit 1946401
Showing 1 changed file with 76 additions and 0 deletions.
76 changes: 76 additions & 0 deletions google/resource_container_node_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,29 @@ var schemaNodePool = map[string]*schema.Schema{
Deprecated: "Use node_count instead",
},

"management": {
Type: schema.TypeList,
Optional: true,
Computed: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{

"auto_repair": {
Type: schema.TypeBool,
Optional: true,
Computed: true,
},

"auto_upgrade": {
Type: schema.TypeBool,
Optional: true,
Computed: true,
},
},
},
},

"name": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -304,6 +327,19 @@ func expandNodePool(d *schema.ResourceData, prefix string) (*container.NodePool,
}
}

if v, ok := d.GetOk(prefix + "management"); ok {
managementConfig := v.([]interface{})[0].(map[string]interface{})
np.Management = &container.NodeManagement{}

if v, ok := managementConfig["auto_repair"]; ok {
np.Management.AutoRepair = v.(bool)
}

if v, ok := managementConfig["auto_upgrade"]; ok {
np.Management.AutoUpgrade = v.(bool)
}
}

return np, nil
}

Expand Down Expand Up @@ -338,6 +374,15 @@ func flattenNodePool(d *schema.ResourceData, config *Config, np *container.NodeP
}
}

if np.Management != nil {
nodePool["management"] = []map[string]interface{}{
{
"auto_repair": np.Management.AutoRepair,
"auto_upgrade": np.Management.AutoUpgrade,
},
}
}

return nodePool, nil
}

Expand Down Expand Up @@ -415,6 +460,37 @@ func nodePoolUpdate(d *schema.ResourceData, meta interface{}, clusterName, prefi
}
}

if d.HasChange(prefix + "management") {

management := &container.NodeManagement{}
if v, ok := d.GetOk(prefix + "management"); ok {
managementConfig := v.([]interface{})[0].(map[string]interface{})
management.AutoRepair = managementConfig["auto_repair"].(bool)
management.AutoUpgrade = managementConfig["auto_upgrade"].(bool)
}
req := &container.SetNodePoolManagementRequest{
Management: management,
}
op, err := config.clientContainer.Projects.Zones.Clusters.NodePools.SetManagement(
project, zone, clusterName, npName, req).Do()

if err != nil {
return err
}

// Wait until it's updated
waitErr := containerOperationWait(config, op, project, zone, "updating GKE node pool management", timeoutInMinutes, 2)
if waitErr != nil {
return waitErr
}

log.Printf("[INFO] Updated management in Node Pool %s", d.Id())

if prefix == "" {
d.SetPartial("management")
}
}

return nil
}

Expand Down

0 comments on commit 1946401

Please sign in to comment.