diff --git a/google-beta/resource_container_cluster.go b/google-beta/resource_container_cluster.go index 39e4e50257..50cfe6ee76 100644 --- a/google-beta/resource_container_cluster.go +++ b/google-beta/resource_container_cluster.go @@ -511,10 +511,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, @@ -522,6 +530,7 @@ func resourceContainerCluster() *schema.Resource { ForceNew: true, ConflictsWith: ipAllocationRangeFields, }, + "subnetwork_name": { Type: schema.TypeString, Optional: true, @@ -1614,7 +1623,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), @@ -1625,6 +1634,7 @@ func expandIPAllocationPolicy(configured interface{}) *containerBeta.IPAllocatio ClusterSecondaryRangeName: config["cluster_secondary_range_name"].(string), ServicesSecondaryRangeName: config["services_secondary_range_name"].(string), + ForceSendFields: []string{"UseIpAliases"}, } } @@ -1921,6 +1931,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-beta/resource_container_cluster_test.go b/google-beta/resource_container_cluster_test.go index 36eefab751..ff3fca936b 100644 --- a/google-beta/resource_container_cluster_test.go +++ b/google-beta/resource_container_cluster_test.go @@ -1722,6 +1722,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" @@ -2733,7 +2737,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) @@ -2761,9 +2766,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) } @@ -2790,11 +2796,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) } @@ -2807,6 +2814,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 6d891285aa..038e6f4d9e 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