Skip to content

Commit f0e705f

Browse files
author
Sébastien GLON
committed
Add network policy
1 parent d1ccbb8 commit f0e705f

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

google/resource_container_cluster.go

+24
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,22 @@ func resourceContainerCluster() *schema.Resource {
128128
},
129129
},
130130
},
131+
"network_policy": {
132+
Type: schema.TypeList,
133+
Optional: true,
134+
ForceNew: true,
135+
MaxItems: 1,
136+
Elem: &schema.Resource{
137+
Schema: map[string]*schema.Schema{
138+
"disabled": {
139+
Type: schema.TypeBool,
140+
Default: true,
141+
Optional: true,
142+
ForceNew: true,
143+
},
144+
},
145+
},
146+
},
131147
},
132148
},
133149
},
@@ -863,6 +879,14 @@ func expandClusterAddonsConfig(configured interface{}) *container.AddonsConfig {
863879
ForceSendFields: []string{"Disabled"},
864880
}
865881
}
882+
883+
if v, ok := config["network_policy"]; ok && len(v.([]interface{})) > 0 {
884+
addon := v.([]interface{})[0].(map[string]interface{})
885+
ac.NetworkPolicyConfig = &container.NetworkPolicyConfig{
886+
Disabled: addon["disabled"].(bool),
887+
ForceSendFields: []string{"Disabled"},
888+
}
889+
}
866890
return ac
867891
}
868892

google/resource_container_cluster_test.go

+7
Original file line numberDiff line numberDiff line change
@@ -706,9 +706,14 @@ func testAccCheckContainerCluster(n string) resource.TestCheckFunc {
706706
if cluster.AddonsConfig != nil && cluster.AddonsConfig.KubernetesDashboard != nil {
707707
kubernetesDashboardDisabled = cluster.AddonsConfig.KubernetesDashboard.Disabled
708708
}
709+
networkPolicyDisabled := false
710+
if cluster.AddonsConfig != nil && cluster.AddonsConfig.NetworkPolicyConfig != nil {
711+
networkPolicyDisabled = cluster.AddonsConfig.NetworkPolicyConfig.Disabled
712+
}
709713
clusterTests = append(clusterTests, clusterTestField{"addons_config.0.http_load_balancing.0.disabled", httpLoadBalancingDisabled})
710714
clusterTests = append(clusterTests, clusterTestField{"addons_config.0.horizontal_pod_autoscaling.0.disabled", horizontalPodAutoscalingDisabled})
711715
clusterTests = append(clusterTests, clusterTestField{"addons_config.0.kubernetes_dashboard.0.disabled", kubernetesDashboardDisabled})
716+
clusterTests = append(clusterTests, clusterTestField{"addons_config.0.network_policy.0.disabled", networkPolicyDisabled})
712717

713718
for i, np := range cluster.NodePools {
714719
prefix := fmt.Sprintf("node_pool.%d.", i)
@@ -915,6 +920,7 @@ resource "google_container_cluster" "primary" {
915920
addons_config {
916921
http_load_balancing { disabled = true }
917922
kubernetes_dashboard { disabled = true }
923+
network_policy { disabled = true }
918924
}
919925
}`, clusterName)
920926
}
@@ -930,6 +936,7 @@ resource "google_container_cluster" "primary" {
930936
http_load_balancing { disabled = false }
931937
kubernetes_dashboard { disabled = true }
932938
horizontal_pod_autoscaling { disabled = true }
939+
network_policy { disabled = false }
933940
}
934941
}`, clusterName)
935942
}

website/docs/r/container_cluster.html.markdown

+3
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,9 @@ The `addons_config` block supports:
154154
add-on, which controls whether the Kubernetes Dashboard is enabled for this cluster.
155155
It is enabled by default; set `disabled = true` to disable.
156156

157+
* `network_policy` - (Optional) The status of the Network Policy
158+
add-on. It is disable by default; set `disabled = false` to enable.
159+
157160
This example `addons_config` disables two addons:
158161

159162
```

0 commit comments

Comments
 (0)