From 75d8672cf4ba70e22a4da098878e931c841687f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20GLON?= Date: Wed, 25 Oct 2017 12:03:14 +0200 Subject: [PATCH] Add network policy --- google/resource_container_cluster.go | 24 +++++++++++++++++++ google/resource_container_cluster_test.go | 7 ++++++ .../docs/r/container_cluster.html.markdown | 5 ++++ 3 files changed, 36 insertions(+) diff --git a/google/resource_container_cluster.go b/google/resource_container_cluster.go index 7082d2d8c71..7fb98dfabaf 100644 --- a/google/resource_container_cluster.go +++ b/google/resource_container_cluster.go @@ -236,6 +236,22 @@ func resourceContainerCluster() *schema.Resource { }, }, }, + "network_policy": { + Type: schema.TypeList, + Optional: true, + ForceNew: true, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "disabled": { + Type: schema.TypeBool, + Default: true, + Optional: true, + ForceNew: true, + }, + }, + }, + }, }, }, }, @@ -795,6 +811,14 @@ func expandClusterAddonsConfig(configured interface{}) *container.AddonsConfig { ForceSendFields: []string{"Disabled"}, } } + + if v, ok := config["network_policy"]; ok && len(v.([]interface{})) > 0 { + addon := v.([]interface{})[0].(map[string]interface{}) + ac.NetworkPolicyConfig = &container.NetworkPolicyConfig{ + Disabled: addon["disabled"].(bool), + ForceSendFields: []string{"Disabled"}, + } + } return ac } diff --git a/google/resource_container_cluster_test.go b/google/resource_container_cluster_test.go index d60e5ee346f..36231e82d36 100644 --- a/google/resource_container_cluster_test.go +++ b/google/resource_container_cluster_test.go @@ -644,9 +644,14 @@ func testAccCheckContainerCluster(n string) resource.TestCheckFunc { if cluster.AddonsConfig != nil && cluster.AddonsConfig.KubernetesDashboard != nil { kubernetesDashboardDisabled = cluster.AddonsConfig.KubernetesDashboard.Disabled } + networkPolicyDisabled := false + if cluster.AddonsConfig != nil && cluster.AddonsConfig.NetworkPolicyConfig != nil { + networkPolicyDisabled = cluster.AddonsConfig.NetworkPolicyConfig.Disabled + } clusterTests = append(clusterTests, clusterTestField{"addons_config.0.http_load_balancing.0.disabled", httpLoadBalancingDisabled}) clusterTests = append(clusterTests, clusterTestField{"addons_config.0.horizontal_pod_autoscaling.0.disabled", horizontalPodAutoscalingDisabled}) clusterTests = append(clusterTests, clusterTestField{"addons_config.0.kubernetes_dashboard.0.disabled", kubernetesDashboardDisabled}) + clusterTests = append(clusterTests, clusterTestField{"addons_config.0.network_policy.0.disabled", networkPolicyDisabled}) for i, np := range cluster.NodePools { prefix := fmt.Sprintf("node_pool.%d.", i) @@ -853,6 +858,7 @@ resource "google_container_cluster" "primary" { addons_config { http_load_balancing { disabled = true } kubernetes_dashboard { disabled = true } + network_policy { disabled = true } } }`, clusterName) } @@ -868,6 +874,7 @@ resource "google_container_cluster" "primary" { http_load_balancing { disabled = false } kubernetes_dashboard { disabled = true } horizontal_pod_autoscaling { disabled = true } + network_policy { disabled = false } } }`, clusterName) } diff --git a/website/docs/r/container_cluster.html.markdown b/website/docs/r/container_cluster.html.markdown index 489489efb3f..899884e12a2 100644 --- a/website/docs/r/container_cluster.html.markdown +++ b/website/docs/r/container_cluster.html.markdown @@ -169,12 +169,17 @@ which the cluster's instances are launched * `http_load_balancing` - (Optional) The status of the HTTP Load Balancing add-on. It is enabled by default; set `disabled = true` to disable. + * `horizontal_pod_autoscaling` - (Optional) The status of the Horizontal Pod Autoscaling addon. It is enabled by default; set `disabled = true` to disable. + * `kubernetes_dashboard` - (Optional) The status of the Kubernetes Dashboard add-on. It is enabled by default; set `disabled = true` to disable. +* `network_policy` - (Optional) The status of the Network Policy + add-on. It is disable by default; set `disabled = false` to enable. + This example `addons_config` disables both addons: ```