add master_version to container cluster (#538)

This commit is contained in:
Dana Hoffman 2017-10-06 15:48:01 -07:00 committed by GitHub
parent efa4c36e37
commit d67bf7b3fc
2 changed files with 49 additions and 14 deletions

View File

@ -242,6 +242,12 @@ func resourceContainerCluster() *schema.Resource {
},
},
"master_version": {
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"node_config": schemaNodeConfig,
"node_version": {
@ -296,10 +302,14 @@ func resourceContainerClusterCreate(d *schema.ResourceData, meta interface{}) er
}
}
if v, ok := d.GetOk("node_version"); ok {
if v, ok := d.GetOk("master_version"); ok {
cluster.InitialClusterVersion = v.(string)
}
if _, ok := d.GetOk("node_version"); ok {
return fmt.Errorf("cannot set node_version on create, use master_version instead")
}
if v, ok := d.GetOk("additional_zones"); ok {
locationsList := v.(*schema.Set).List()
locations := []string{}
@ -458,6 +468,7 @@ func resourceContainerClusterRead(d *schema.ResourceData, meta interface{}) erro
d.Set("master_auth", masterAuth)
d.Set("initial_node_count", cluster.InitialNodeCount)
d.Set("master_version", cluster.CurrentMasterVersion)
d.Set("node_version", cluster.CurrentNodeVersion)
d.Set("cluster_ipv4_cidr", cluster.ClusterIpv4Cidr)
d.Set("description", cluster.Description)
@ -496,13 +507,12 @@ func resourceContainerClusterUpdate(d *schema.ResourceData, meta interface{}) er
d.Partial(true)
if d.HasChange("node_version") {
desiredNodeVersion := d.Get("node_version").(string)
// The master must be updated before the nodes
// The master must be updated before the nodes
if d.HasChange("master_version") {
desiredMasterVersion := d.Get("master_version").(string)
req := &container.UpdateClusterRequest{
Update: &container.ClusterUpdate{
DesiredMasterVersion: desiredNodeVersion,
DesiredMasterVersion: desiredMasterVersion,
},
}
op, err := config.clientContainer.Projects.Zones.Clusters.Update(
@ -518,22 +528,27 @@ func resourceContainerClusterUpdate(d *schema.ResourceData, meta interface{}) er
}
log.Printf("[INFO] GKE cluster %s: master has been updated to %s", d.Id(),
desiredNodeVersion)
desiredMasterVersion)
// Update the nodes
req = &container.UpdateClusterRequest{
d.SetPartial("master_version")
}
if d.HasChange("node_version") {
desiredNodeVersion := d.Get("node_version").(string)
req := &container.UpdateClusterRequest{
Update: &container.ClusterUpdate{
DesiredNodeVersion: desiredNodeVersion,
},
}
op, err = config.clientContainer.Projects.Zones.Clusters.Update(
op, err := config.clientContainer.Projects.Zones.Clusters.Update(
project, zoneName, clusterName, req).Do()
if err != nil {
return err
}
// Wait until it's updated
waitErr = containerOperationWait(config, op, project, zoneName, "updating GKE node version", timeoutInMinutes, 2)
waitErr := containerOperationWait(config, op, project, zoneName, "updating GKE node version", timeoutInMinutes, 2)
if waitErr != nil {
return waitErr
}

View File

@ -172,7 +172,7 @@ func TestAccContainerCluster_updateVersion(t *testing.T) {
),
},
{
Config: testAccContainerCluster_withVersion(clusterName),
Config: testAccContainerCluster_updateVersion(clusterName),
Check: resource.ComposeTestCheckFunc(
testAccCheckContainerCluster(
"google_container_cluster.with_version"),
@ -824,7 +824,7 @@ data "google_container_engine_versions" "central1a" {
resource "google_container_cluster" "with_version" {
name = "cluster-test-%s"
zone = "us-central1-a"
node_version = "${data.google_container_engine_versions.central1a.latest_node_version}"
master_version = "${data.google_container_engine_versions.central1a.latest_master_version}"
initial_node_count = 1
master_auth {
@ -843,7 +843,27 @@ data "google_container_engine_versions" "central1a" {
resource "google_container_cluster" "with_version" {
name = "cluster-test-%s"
zone = "us-central1-a"
node_version = "${data.google_container_engine_versions.central1a.valid_master_versions.1}"
master_version = "${data.google_container_engine_versions.central1a.valid_master_versions.1}"
initial_node_count = 1
master_auth {
username = "mr.yoda"
password = "adoy.rm"
}
}`, clusterName)
}
func testAccContainerCluster_updateVersion(clusterName string) string {
return fmt.Sprintf(`
data "google_container_engine_versions" "central1a" {
zone = "us-central1-a"
}
resource "google_container_cluster" "with_version" {
name = "cluster-test-%s"
zone = "us-central1-a"
master_version = "${data.google_container_engine_versions.central1a.latest_master_version}"
node_version = "${data.google_container_engine_versions.central1a.latest_node_version}"
initial_node_count = 1
master_auth {