[GKE] Allow additional zones to be configured

This commit is contained in:
Reinhard Nägele 2017-01-04 07:14:39 +01:00
parent 183b73d5e1
commit 038d330365
3 changed files with 69 additions and 1 deletions

View File

@ -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{}{

View File

@ -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"

View File

@ -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