Skip to content

Commit

Permalink
Make VPC Native configurable in GKE
Browse files Browse the repository at this point in the history
Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
rileykarson authored and modular-magician committed Mar 4, 2019
1 parent 84902cc commit 7fa68f1
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
14 changes: 13 additions & 1 deletion google/resource_container_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -478,17 +478,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 @@ -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),
Expand All @@ -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"},
}
}

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

Expand Down
20 changes: 14 additions & 6 deletions google/resource_container_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
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 7fa68f1

Please sign in to comment.