mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
[GKE] Allow additional zones to be configured
This commit is contained in:
parent
183b73d5e1
commit
038d330365
@ -92,6 +92,12 @@ func resourceContainerCluster() *schema.Resource {
|
|||||||
ForceNew: true,
|
ForceNew: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
"additional_zones": &schema.Schema{
|
||||||
|
Type: schema.TypeList,
|
||||||
|
Optional: true,
|
||||||
|
Elem: &schema.Schema{Type: schema.TypeString},
|
||||||
|
},
|
||||||
|
|
||||||
"cluster_ipv4_cidr": &schema.Schema{
|
"cluster_ipv4_cidr": &schema.Schema{
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
@ -282,6 +288,24 @@ func resourceContainerClusterCreate(d *schema.ResourceData, meta interface{}) er
|
|||||||
cluster.InitialClusterVersion = v.(string)
|
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 {
|
if v, ok := d.GetOk("cluster_ipv4_cidr"); ok {
|
||||||
cluster.ClusterIpv4Cidr = v.(string)
|
cluster.ClusterIpv4Cidr = v.(string)
|
||||||
}
|
}
|
||||||
@ -419,6 +443,7 @@ func resourceContainerClusterRead(d *schema.ResourceData, meta interface{}) erro
|
|||||||
|
|
||||||
d.Set("name", cluster.Name)
|
d.Set("name", cluster.Name)
|
||||||
d.Set("zone", cluster.Zone)
|
d.Set("zone", cluster.Zone)
|
||||||
|
d.Set("additional_zones", cluster.Locations)
|
||||||
d.Set("endpoint", cluster.Endpoint)
|
d.Set("endpoint", cluster.Endpoint)
|
||||||
|
|
||||||
masterAuth := []map[string]interface{}{
|
masterAuth := []map[string]interface{}{
|
||||||
|
@ -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) {
|
func TestAccContainerCluster_withVersion(t *testing.T) {
|
||||||
resource.Test(t, resource.TestCase{
|
resource.Test(t, resource.TestCase{
|
||||||
PreCheck: func() { testAccPreCheck(t) },
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
@ -155,6 +172,23 @@ resource "google_container_cluster" "primary" {
|
|||||||
}
|
}
|
||||||
}`, acctest.RandString(10))
|
}`, 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(`
|
var testAccContainerCluster_withVersion = fmt.Sprintf(`
|
||||||
resource "google_container_cluster" "with_version" {
|
resource "google_container_cluster" "with_version" {
|
||||||
name = "cluster-test-%s"
|
name = "cluster-test-%s"
|
||||||
|
@ -20,6 +20,11 @@ resource "google_container_cluster" "primary" {
|
|||||||
zone = "us-central1-a"
|
zone = "us-central1-a"
|
||||||
initial_node_count = 3
|
initial_node_count = 3
|
||||||
|
|
||||||
|
additional_zones = [
|
||||||
|
"us-central1-b",
|
||||||
|
"us-central1-c"
|
||||||
|
]
|
||||||
|
|
||||||
master_auth {
|
master_auth {
|
||||||
username = "mr.yoda"
|
username = "mr.yoda"
|
||||||
password = "adoy.rm"
|
password = "adoy.rm"
|
||||||
@ -47,9 +52,13 @@ resource "google_container_cluster" "primary" {
|
|||||||
* `name` - (Required) The name of the cluster, unique within the project and
|
* `name` - (Required) The name of the cluster, unique within the project and
|
||||||
zone.
|
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
|
* `addons_config` - (Optional) The configuration for addons supported by Google
|
||||||
Container Engine
|
Container Engine
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user