Skip to content

Commit 75d8672

Browse files
author
Sébastien GLON
committed
Add network policy
1 parent 26944d0 commit 75d8672

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
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
@@ -644,9 +644,14 @@ func testAccCheckContainerCluster(n string) resource.TestCheckFunc {
644644
if cluster.AddonsConfig != nil && cluster.AddonsConfig.KubernetesDashboard != nil {
645645
kubernetesDashboardDisabled = cluster.AddonsConfig.KubernetesDashboard.Disabled
646646
}
647+
networkPolicyDisabled := false
648+
if cluster.AddonsConfig != nil && cluster.AddonsConfig.NetworkPolicyConfig != nil {
649+
networkPolicyDisabled = cluster.AddonsConfig.NetworkPolicyConfig.Disabled
650+
}
647651
clusterTests = append(clusterTests, clusterTestField{"addons_config.0.http_load_balancing.0.disabled", httpLoadBalancingDisabled})
648652
clusterTests = append(clusterTests, clusterTestField{"addons_config.0.horizontal_pod_autoscaling.0.disabled", horizontalPodAutoscalingDisabled})
649653
clusterTests = append(clusterTests, clusterTestField{"addons_config.0.kubernetes_dashboard.0.disabled", kubernetesDashboardDisabled})
654+
clusterTests = append(clusterTests, clusterTestField{"addons_config.0.network_policy.0.disabled", networkPolicyDisabled})
650655

651656
for i, np := range cluster.NodePools {
652657
prefix := fmt.Sprintf("node_pool.%d.", i)
@@ -853,6 +858,7 @@ resource "google_container_cluster" "primary" {
853858
addons_config {
854859
http_load_balancing { disabled = true }
855860
kubernetes_dashboard { disabled = true }
861+
network_policy { disabled = true }
856862
}
857863
}`, clusterName)
858864
}
@@ -868,6 +874,7 @@ resource "google_container_cluster" "primary" {
868874
http_load_balancing { disabled = false }
869875
kubernetes_dashboard { disabled = true }
870876
horizontal_pod_autoscaling { disabled = true }
877+
network_policy { disabled = false }
871878
}
872879
}`, clusterName)
873880
}

website/docs/r/container_cluster.html.markdown

+5
Original file line numberDiff line numberDiff line change
@@ -169,12 +169,17 @@ which the cluster's instances are launched
169169

170170
* `http_load_balancing` - (Optional) The status of the HTTP Load Balancing
171171
add-on. It is enabled by default; set `disabled = true` to disable.
172+
172173
* `horizontal_pod_autoscaling` - (Optional) The status of the Horizontal Pod
173174
Autoscaling addon. It is enabled by default; set `disabled = true` to
174175
disable.
176+
175177
* `kubernetes_dashboard` - (Optional) The status of the Kubernetes Dashboard
176178
add-on. It is enabled by default; set `disabled = true` to disable.
177179

180+
* `network_policy` - (Optional) The status of the Network Policy
181+
add-on. It is disable by default; set `disabled = false` to enable.
182+
178183
This example `addons_config` disables both addons:
179184

180185
```

0 commit comments

Comments
 (0)