Skip to content

Commit 217239e

Browse files
danawillowmodular-magician
authored andcommitted
use the cluster subnet to look up the node cidr block
Signed-off-by: Modular Magician <[email protected]>
1 parent 0310ea2 commit 217239e

3 files changed

+18
-23
lines changed

google/resource_container_cluster.go

+16-15
Original file line numberDiff line numberDiff line change
@@ -888,7 +888,7 @@ func resourceContainerClusterRead(d *schema.ResourceData, meta interface{}) erro
888888
return err
889889
}
890890

891-
if err := d.Set("ip_allocation_policy", flattenIPAllocationPolicy(cluster.IpAllocationPolicy, d, config)); err != nil {
891+
if err := d.Set("ip_allocation_policy", flattenIPAllocationPolicy(cluster, d, config)); err != nil {
892892
return err
893893
}
894894

@@ -1783,35 +1783,36 @@ func flattenPrivateClusterConfig(c *containerBeta.PrivateClusterConfig) []map[st
17831783
}
17841784
}
17851785

1786-
func flattenIPAllocationPolicy(c *containerBeta.IPAllocationPolicy, d *schema.ResourceData, config *Config) []map[string]interface{} {
1787-
if c == nil {
1786+
func flattenIPAllocationPolicy(c *containerBeta.Cluster, d *schema.ResourceData, config *Config) []map[string]interface{} {
1787+
if c == nil || c.IpAllocationPolicy == nil {
17881788
return nil
17891789
}
1790-
node_cidr_block := ""
1791-
if c.SubnetworkName != "" {
1792-
subnetwork, err := ParseSubnetworkFieldValue(c.SubnetworkName, d, config)
1790+
nodeCidrBlock := ""
1791+
if c.Subnetwork != "" {
1792+
subnetwork, err := ParseSubnetworkFieldValue(c.Subnetwork, d, config)
17931793
if err == nil {
17941794
sn, err := config.clientCompute.Subnetworks.Get(subnetwork.Project, subnetwork.Region, subnetwork.Name).Do()
17951795
if err == nil {
1796-
node_cidr_block = sn.IpCidrRange
1796+
nodeCidrBlock = sn.IpCidrRange
17971797
}
17981798
} else {
17991799
log.Printf("[WARN] Unable to parse subnetwork name, got error while trying to get new subnetwork: %s", err)
18001800
}
18011801
}
1802+
p := c.IpAllocationPolicy
18021803
return []map[string]interface{}{
18031804
{
1804-
"use_ip_aliases": c.UseIpAliases,
1805+
"use_ip_aliases": p.UseIpAliases,
18051806

1806-
"create_subnetwork": c.CreateSubnetwork,
1807-
"subnetwork_name": c.SubnetworkName,
1807+
"create_subnetwork": p.CreateSubnetwork,
1808+
"subnetwork_name": p.SubnetworkName,
18081809

1809-
"cluster_ipv4_cidr_block": c.ClusterIpv4CidrBlock,
1810-
"services_ipv4_cidr_block": c.ServicesIpv4CidrBlock,
1811-
"node_ipv4_cidr_block": node_cidr_block,
1810+
"cluster_ipv4_cidr_block": p.ClusterIpv4CidrBlock,
1811+
"services_ipv4_cidr_block": p.ServicesIpv4CidrBlock,
1812+
"node_ipv4_cidr_block": nodeCidrBlock,
18121813

1813-
"cluster_secondary_range_name": c.ClusterSecondaryRangeName,
1814-
"services_secondary_range_name": c.ServicesSecondaryRangeName,
1814+
"cluster_secondary_range_name": p.ClusterSecondaryRangeName,
1815+
"services_secondary_range_name": p.ServicesSecondaryRangeName,
18151816
},
18161817
}
18171818
}

google/resource_container_cluster_test.go

+1-8
Original file line numberDiff line numberDiff line change
@@ -2260,22 +2260,15 @@ resource "google_compute_network" "container_network" {
22602260
auto_create_subnetworks = false
22612261
}
22622262
2263-
resource "google_compute_subnetwork" "container_subnetwork" {
2264-
name = "${google_compute_network.container_network.name}"
2265-
network = "${google_compute_network.container_network.name}"
2266-
ip_cidr_range = "10.128.0.0/9"
2267-
region = "us-central1"
2268-
}
2269-
22702263
resource "google_container_cluster" "with_ip_allocation_policy" {
22712264
name = "%s"
22722265
zone = "us-central1-a"
22732266
network = "${google_compute_network.container_network.name}"
2274-
subnetwork = "${google_compute_subnetwork.container_subnetwork.name}"
22752267
22762268
initial_node_count = 1
22772269
ip_allocation_policy {
22782270
use_ip_aliases = true
2271+
create_subnetwork = true
22792272
cluster_ipv4_cidr_block = "10.0.0.0/16"
22802273
services_ipv4_cidr_block = "10.1.0.0/16"
22812274
node_ipv4_cidr_block = "10.2.0.0/16"

google/resource_sql_database_instance_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/hashicorp/terraform/helper/acctest"
1010
"github.com/hashicorp/terraform/helper/resource"
1111
"github.com/hashicorp/terraform/terraform"
12+
1213
sqladmin "google.golang.org/api/sqladmin/v1beta4"
1314
)
1415

0 commit comments

Comments
 (0)