From 749e6b02814260d8fa89274c4443473006a3873f Mon Sep 17 00:00:00 2001 From: The Magician Date: Mon, 4 Mar 2019 14:08:40 -0800 Subject: [PATCH] Make VPC Native configurable in GKE (#3174) /cc @rileykarson --- google/resource_container_cluster.go | 14 ++++++++++++- google/resource_container_cluster_test.go | 20 +++++++++++++------ .../docs/r/container_cluster.html.markdown | 5 +++++ 3 files changed, 32 insertions(+), 7 deletions(-) diff --git a/google/resource_container_cluster.go b/google/resource_container_cluster.go index f373f57bce0..05daf489d3e 100644 --- a/google/resource_container_cluster.go +++ b/google/resource_container_cluster.go @@ -478,10 +478,18 @@ func resourceContainerCluster() *schema.Resource { "ip_allocation_policy": { Type: schema.TypeList, Optional: true, + Computed: true, ForceNew: true, MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ + "use_ip_aliases": { + Type: schema.TypeBool, + Optional: true, + Default: true, + ForceNew: true, + }, + // GKE creates subnetwork automatically "create_subnetwork": { Type: schema.TypeBool, @@ -489,6 +497,7 @@ func resourceContainerCluster() *schema.Resource { ForceNew: true, ConflictsWith: ipAllocationRangeFields, }, + "subnetwork_name": { Type: schema.TypeString, Optional: true, @@ -1485,7 +1494,7 @@ func expandIPAllocationPolicy(configured interface{}) *containerBeta.IPAllocatio config := l[0].(map[string]interface{}) return &containerBeta.IPAllocationPolicy{ - UseIpAliases: true, + UseIpAliases: config["use_ip_aliases"].(bool), CreateSubnetwork: config["create_subnetwork"].(bool), SubnetworkName: config["subnetwork_name"].(string), @@ -1496,6 +1505,7 @@ func expandIPAllocationPolicy(configured interface{}) *containerBeta.IPAllocatio ClusterSecondaryRangeName: config["cluster_secondary_range_name"].(string), ServicesSecondaryRangeName: config["services_secondary_range_name"].(string), + ForceSendFields: []string{"UseIpAliases"}, } } @@ -1702,6 +1712,8 @@ func flattenIPAllocationPolicy(c *containerBeta.IPAllocationPolicy, d *schema.Re } return []map[string]interface{}{ { + "use_ip_aliases": c.UseIpAliases, + "create_subnetwork": c.CreateSubnetwork, "subnetwork_name": c.SubnetworkName, diff --git a/google/resource_container_cluster_test.go b/google/resource_container_cluster_test.go index de8c3822dda..ec1c545eb9c 100644 --- a/google/resource_container_cluster_test.go +++ b/google/resource_container_cluster_test.go @@ -1388,6 +1388,10 @@ resource "google_container_cluster" "primary" { zone = "us-central1-a" initial_node_count = 3 + ip_allocation_policy { + use_ip_aliases = false + } + timeouts { create = "30m" delete = "30m" @@ -2199,7 +2203,8 @@ resource "google_container_cluster" "with_ip_allocation_policy" { initial_node_count = 1 ip_allocation_policy { - cluster_secondary_range_name = "pods" + use_ip_aliases = true + cluster_secondary_range_name = "pods" services_secondary_range_name = "services" } }`, cluster, cluster) @@ -2227,9 +2232,10 @@ resource "google_container_cluster" "with_ip_allocation_policy" { initial_node_count = 1 ip_allocation_policy { + use_ip_aliases = true cluster_ipv4_cidr_block = "10.0.0.0/16" services_ipv4_cidr_block = "10.1.0.0/16" - node_ipv4_cidr_block = "10.2.0.0/16" + node_ipv4_cidr_block = "10.2.0.0/16" } }`, cluster, cluster) } @@ -2256,11 +2262,12 @@ resource "google_container_cluster" "with_ip_allocation_policy" { initial_node_count = 1 ip_allocation_policy { - create_subnetwork = true - subnetwork_name = "tf-test-%s" - cluster_ipv4_cidr_block = "/16" + use_ip_aliases = true + create_subnetwork = true + subnetwork_name = "tf-test-%s" + cluster_ipv4_cidr_block = "/16" services_ipv4_cidr_block = "/22" - node_ipv4_cidr_block = "/22" + node_ipv4_cidr_block = "/22" } }`, cluster, cluster, cluster) } @@ -2273,6 +2280,7 @@ resource "google_container_cluster" "with_ip_allocation_policy" { initial_node_count = 1 ip_allocation_policy { + use_ip_aliases = true create_subnetwork = true } }`, cluster) diff --git a/website/docs/r/container_cluster.html.markdown b/website/docs/r/container_cluster.html.markdown index 6d891285aa7..038e6f4d9eb 100644 --- a/website/docs/r/container_cluster.html.markdown +++ b/website/docs/r/container_cluster.html.markdown @@ -350,6 +350,11 @@ maintenance_policy { The `ip_allocation_policy` block supports: +* `use_ip_aliases` - (Optional) Whether alias IPs will be used for pod IPs in +the cluster. Defaults to `true` if the `ip_allocation_policy` block is defined, +and to the API default otherwise. Prior to March 31, 2019, the default on the +API is `false`; afterwards, it's `true`. + * `cluster_secondary_range_name` - (Optional) The name of the secondary range to be used as for the cluster CIDR block. The secondary range will be used for pod IP addresses. This must be an existing secondary range associated with the cluster