From 038d330365fecb16cf6ce7f15a1064550bd3738b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Reinhard=20N=C3=A4gele?= Date: Wed, 4 Jan 2017 07:14:39 +0100 Subject: [PATCH] [GKE] Allow additional zones to be configured --- .../google/resource_container_cluster.go | 25 ++++++++++++++ .../google/resource_container_cluster_test.go | 34 +++++++++++++++++++ .../google/r/container_cluster.html.markdown | 11 +++++- 3 files changed, 69 insertions(+), 1 deletion(-) diff --git a/builtin/providers/google/resource_container_cluster.go b/builtin/providers/google/resource_container_cluster.go index 9340d78e64..22fd5a40ef 100644 --- a/builtin/providers/google/resource_container_cluster.go +++ b/builtin/providers/google/resource_container_cluster.go @@ -92,6 +92,12 @@ func resourceContainerCluster() *schema.Resource { ForceNew: true, }, + "additional_zones": &schema.Schema{ + Type: schema.TypeList, + Optional: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + "cluster_ipv4_cidr": &schema.Schema{ Type: schema.TypeString, Optional: true, @@ -282,6 +288,24 @@ func resourceContainerClusterCreate(d *schema.ResourceData, meta interface{}) er cluster.InitialClusterVersion = v.(string) } + if v, ok := d.GetOk("additional_zones"); ok { + locationsList := v.([]interface{}) + locations := []string{} + zoneInLocations := false + for _, v := range locationsList { + location := v.(string) + locations = append(locations, location) + if location == zoneName { + zoneInLocations = true + } + } + if !zoneInLocations { + // zone must be in locations if specified separately + locations = append(locations, zoneName) + } + cluster.Locations = locations + } + if v, ok := d.GetOk("cluster_ipv4_cidr"); ok { cluster.ClusterIpv4Cidr = v.(string) } @@ -419,6 +443,7 @@ func resourceContainerClusterRead(d *schema.ResourceData, meta interface{}) erro d.Set("name", cluster.Name) d.Set("zone", cluster.Zone) + d.Set("additional_zones", cluster.Locations) d.Set("endpoint", cluster.Endpoint) masterAuth := []map[string]interface{}{ diff --git a/builtin/providers/google/resource_container_cluster_test.go b/builtin/providers/google/resource_container_cluster_test.go index d0dbb48e9f..3cef09e45f 100644 --- a/builtin/providers/google/resource_container_cluster_test.go +++ b/builtin/providers/google/resource_container_cluster_test.go @@ -26,6 +26,23 @@ func TestAccContainerCluster_basic(t *testing.T) { }) } +func TestAccContainerCluster_withAdditionalZones(t *testing.T) { + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckContainerClusterDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccContainerCluster_withAdditionalZones, + Check: resource.ComposeTestCheckFunc( + testAccCheckContainerClusterExists( + "google_container_cluster.with_additional_zones"), + ), + }, + }, + }) +} + func TestAccContainerCluster_withVersion(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -155,6 +172,23 @@ resource "google_container_cluster" "primary" { } }`, acctest.RandString(10)) +var testAccContainerCluster_withAdditionalZones = fmt.Sprintf(` +resource "google_container_cluster" "with_additional_zones" { + name = "cluster-test-%s" + zone = "us-central1-a" + initial_node_count = 1 + + additional_zones = [ + "us-central1-b", + "us-central1-c" + ] + + master_auth { + username = "mr.yoda" + password = "adoy.rm" + } +}`, acctest.RandString(10)) + var testAccContainerCluster_withVersion = fmt.Sprintf(` resource "google_container_cluster" "with_version" { name = "cluster-test-%s" diff --git a/website/source/docs/providers/google/r/container_cluster.html.markdown b/website/source/docs/providers/google/r/container_cluster.html.markdown index a667323b74..9c2306feeb 100644 --- a/website/source/docs/providers/google/r/container_cluster.html.markdown +++ b/website/source/docs/providers/google/r/container_cluster.html.markdown @@ -20,6 +20,11 @@ resource "google_container_cluster" "primary" { zone = "us-central1-a" initial_node_count = 3 + additional_zones = [ + "us-central1-b", + "us-central1-c" + ] + master_auth { username = "mr.yoda" password = "adoy.rm" @@ -47,9 +52,13 @@ resource "google_container_cluster" "primary" { * `name` - (Required) The name of the cluster, unique within the project and zone. -* `zone` - (Required) The zone that all resources should be created in. +* `zone` - (Required) The zone that the master and the number of nodes specified + in `initial_node_count` should be created in. - - - +* `additional_zones` - (Optional) If additional zones are configured, the number + of nodes specified in `initial_node_count` is created in all specified zones. + * `addons_config` - (Optional) The configuration for addons supported by Google Container Engine