Skip to content

Commit 8f07134

Browse files
author
Sébastien GLON
committed
Add network policy
1 parent 32fac9c commit 8f07134

File tree

6 files changed

+1828
-1332
lines changed

6 files changed

+1828
-1332
lines changed

google/resource_container_cluster.go

+24
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,22 @@ func resourceContainerCluster() *schema.Resource {
236236
},
237237
},
238238
},
239+
"network_policy": {
240+
Type: schema.TypeList,
241+
Optional: true,
242+
ForceNew: true,
243+
MaxItems: 1,
244+
Elem: &schema.Resource{
245+
Schema: map[string]*schema.Schema{
246+
"disabled": {
247+
Type: schema.TypeBool,
248+
Default: true,
249+
Optional: true,
250+
ForceNew: true,
251+
},
252+
},
253+
},
254+
},
239255
},
240256
},
241257
},
@@ -795,6 +811,14 @@ func expandClusterAddonsConfig(configured interface{}) *container.AddonsConfig {
795811
ForceSendFields: []string{"Disabled"},
796812
}
797813
}
814+
815+
if v, ok := config["network_policy"]; ok && len(v.([]interface{})) > 0 {
816+
addon := v.([]interface{})[0].(map[string]interface{})
817+
ac.NetworkPolicyConfig = &container.NetworkPolicyConfig{
818+
Disabled: addon["disabled"].(bool),
819+
ForceSendFields: []string{"Disabled"},
820+
}
821+
}
798822
return ac
799823
}
800824

google/resource_container_cluster_test.go

+7
Original file line numberDiff line numberDiff line change
@@ -643,9 +643,14 @@ func testAccCheckContainerCluster(n string) resource.TestCheckFunc {
643643
if cluster.AddonsConfig != nil && cluster.AddonsConfig.KubernetesDashboard != nil {
644644
kubernetesDashboardDisabled = cluster.AddonsConfig.KubernetesDashboard.Disabled
645645
}
646+
networkPolicyDisabled := false
647+
if cluster.AddonsConfig != nil && cluster.AddonsConfig.NetworkPolicyConfig != nil {
648+
networkPolicyDisabled = cluster.AddonsConfig.NetworkPolicyConfig.Disabled
649+
}
646650
clusterTests = append(clusterTests, clusterTestField{"addons_config.0.http_load_balancing.0.disabled", httpLoadBalancingDisabled})
647651
clusterTests = append(clusterTests, clusterTestField{"addons_config.0.horizontal_pod_autoscaling.0.disabled", horizontalPodAutoscalingDisabled})
648652
clusterTests = append(clusterTests, clusterTestField{"addons_config.0.kubernetes_dashboard.0.disabled", kubernetesDashboardDisabled})
653+
clusterTests = append(clusterTests, clusterTestField{"addons_config.0.network_policy.0.disabled", networkPolicyDisabled})
649654

650655
for i, np := range cluster.NodePools {
651656
prefix := fmt.Sprintf("node_pool.%d.", i)
@@ -852,6 +857,7 @@ resource "google_container_cluster" "primary" {
852857
addons_config {
853858
http_load_balancing { disabled = true }
854859
kubernetes_dashboard { disabled = true }
860+
network_policy { disabled = true }
855861
}
856862
}`, clusterName)
857863
}
@@ -867,6 +873,7 @@ resource "google_container_cluster" "primary" {
867873
http_load_balancing { disabled = false }
868874
kubernetes_dashboard { disabled = true }
869875
horizontal_pod_autoscaling { disabled = true }
876+
network_policy { disabled = false }
870877
}
871878
}`, clusterName)
872879
}

0 commit comments

Comments
 (0)