Skip to content

Commit

Permalink
Make VPC Native-ness (default) configurable in GKE (#489)
Browse files Browse the repository at this point in the history
Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored and rileykarson committed Mar 4, 2019
1 parent df945d3 commit 95a46fa
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
14 changes: 13 additions & 1 deletion google-beta/resource_container_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -511,17 +511,26 @@ 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,
Optional: true,
ForceNew: true,
ConflictsWith: ipAllocationRangeFields,
},

"subnetwork_name": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -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),
Expand All @@ -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"},
}
}

Expand Down Expand Up @@ -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,

Expand Down
20 changes: 14 additions & 6 deletions google-beta/resource_container_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions website/docs/r/container_cluster.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 95a46fa

Please sign in to comment.