Skip to content

Commit 666ccf8

Browse files
author
Sébastien GLON
committed
Add network policy
1 parent 3ee79d2 commit 666ccf8

File tree

3 files changed

+73
-0
lines changed

3 files changed

+73
-0
lines changed

google/resource_container_cluster.go

+24
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,22 @@ func resourceContainerCluster() *schema.Resource {
129129
},
130130
},
131131
},
132+
"network_policy": {
133+
Type: schema.TypeList,
134+
Optional: true,
135+
ForceNew: true,
136+
MaxItems: 1,
137+
Elem: &schema.Resource{
138+
Schema: map[string]*schema.Schema{
139+
"disabled": {
140+
Type: schema.TypeBool,
141+
Default: true,
142+
Optional: true,
143+
ForceNew: true,
144+
},
145+
},
146+
},
147+
},
132148
},
133149
},
134150
},
@@ -813,6 +829,14 @@ func expandClusterAddonsConfig(configured interface{}) *container.AddonsConfig {
813829
ForceSendFields: []string{"Disabled"},
814830
}
815831
}
832+
833+
if v, ok := config["network_policy"]; ok && len(v.([]interface{})) > 0 {
834+
addon := v.([]interface{})[0].(map[string]interface{})
835+
ac.NetworkPolicyConfig = &container.NetworkPolicyConfig{
836+
Disabled: addon["disabled"].(bool),
837+
ForceSendFields: []string{"Disabled"},
838+
}
839+
}
816840
return ac
817841
}
818842

google/resource_container_cluster_test.go

+7
Original file line numberDiff line numberDiff line change
@@ -667,9 +667,14 @@ func testAccCheckContainerCluster(n string) resource.TestCheckFunc {
667667
if cluster.AddonsConfig != nil && cluster.AddonsConfig.KubernetesDashboard != nil {
668668
kubernetesDashboardDisabled = cluster.AddonsConfig.KubernetesDashboard.Disabled
669669
}
670+
networkPolicyDisabled := false
671+
if cluster.AddonsConfig != nil && cluster.AddonsConfig.NetworkPolicyConfig != nil {
672+
networkPolicyDisabled = cluster.AddonsConfig.NetworkPolicyConfig.Disabled
673+
}
670674
clusterTests = append(clusterTests, clusterTestField{"addons_config.0.http_load_balancing.0.disabled", httpLoadBalancingDisabled})
671675
clusterTests = append(clusterTests, clusterTestField{"addons_config.0.horizontal_pod_autoscaling.0.disabled", horizontalPodAutoscalingDisabled})
672676
clusterTests = append(clusterTests, clusterTestField{"addons_config.0.kubernetes_dashboard.0.disabled", kubernetesDashboardDisabled})
677+
clusterTests = append(clusterTests, clusterTestField{"addons_config.0.network_policy.0.disabled", networkPolicyDisabled})
673678

674679
for i, np := range cluster.NodePools {
675680
prefix := fmt.Sprintf("node_pool.%d.", i)
@@ -876,6 +881,7 @@ resource "google_container_cluster" "primary" {
876881
addons_config {
877882
http_load_balancing { disabled = true }
878883
kubernetes_dashboard { disabled = true }
884+
network_policy { disabled = true }
879885
}
880886
}`, clusterName)
881887
}
@@ -891,6 +897,7 @@ resource "google_container_cluster" "primary" {
891897
http_load_balancing { disabled = false }
892898
kubernetes_dashboard { disabled = true }
893899
horizontal_pod_autoscaling { disabled = true }
900+
network_policy { disabled = false }
894901
}
895902
}`, clusterName)
896903
}

website/docs/r/container_cluster.html.markdown

+42
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,48 @@ The `node_config` block supports:
201201
* `service_account` - (Optional) The service account to be used by the Node VMs.
202202
If not specified, the "default" service account is used.
203203

204+
* `min_cpu_platform` - (Optional) Minimum CPU platform to be used by this instance.
205+
The instance may be scheduled on the specified or newer CPU platform. Applicable
206+
values are the friendly names of CPU platforms, such as `Intel Haswell`. See the
207+
[official documentation](https://cloud.google.com/compute/docs/instances/specify-min-cpu-platform)
208+
for more information.
209+
210+
**Addons Config** supports the following addons:
211+
212+
* `http_load_balancing` - (Optional) The status of the HTTP Load Balancing
213+
add-on. It is enabled by default; set `disabled = true` to disable.
214+
215+
* `horizontal_pod_autoscaling` - (Optional) The status of the Horizontal Pod
216+
Autoscaling addon. It is enabled by default; set `disabled = true` to
217+
disable.
218+
219+
* `kubernetes_dashboard` - (Optional) The status of the Kubernetes Dashboard
220+
add-on. It is enabled by default; set `disabled = true` to disable.
221+
222+
* `network_policy` - (Optional) The status of the Network Policy
223+
add-on. It is disable by default; set `disabled = false` to enable.
224+
225+
This example `addons_config` disables both addons:
226+
227+
```
228+
addons_config {
229+
http_load_balancing {
230+
disabled = true
231+
}
232+
horizontal_pod_autoscaling {
233+
disabled = true
234+
}
235+
}
236+
```
237+
238+
**Node Pool** supports the following arguments:
239+
240+
* `initial_node_count` - (Required) The initial node count for the pool.
241+
242+
* `name` - (Optional) The name of the node pool. If left blank, Terraform will
243+
auto-generate a unique name.
244+
>>>>>>> Add network policy
245+
204246
* `tags` - (Optional) The list of instance tags applied to all nodes. Tags are used to identify
205247
valid sources or targets for network firewalls.
206248

0 commit comments

Comments
 (0)