File tree 3 files changed +66
-2
lines changed
3 files changed +66
-2
lines changed Original file line number Diff line number Diff line change @@ -160,6 +160,20 @@ func resourceContainerCluster() *schema.Resource {
160
160
},
161
161
},
162
162
},
163
+ "network_policy_config" : {
164
+ Type : schema .TypeList ,
165
+ Optional : true ,
166
+ Computed : true ,
167
+ MaxItems : 1 ,
168
+ Elem : & schema.Resource {
169
+ Schema : map [string ]* schema.Schema {
170
+ "disabled" : {
171
+ Type : schema .TypeBool ,
172
+ Optional : true ,
173
+ },
174
+ },
175
+ },
176
+ },
163
177
},
164
178
},
165
179
},
@@ -1187,6 +1201,15 @@ func expandClusterAddonsConfig(configured interface{}) *containerBeta.AddonsConf
1187
1201
ForceSendFields : []string {"Disabled" },
1188
1202
}
1189
1203
}
1204
+
1205
+ if v , ok := config ["network_policy_config" ]; ok && len (v .([]interface {})) > 0 {
1206
+ addon := v .([]interface {})[0 ].(map [string ]interface {})
1207
+ ac .NetworkPolicyConfig = & containerBeta.NetworkPolicyConfig {
1208
+ Disabled : addon ["disabled" ].(bool ),
1209
+ ForceSendFields : []string {"Disabled" },
1210
+ }
1211
+ }
1212
+
1190
1213
return ac
1191
1214
}
1192
1215
@@ -1304,6 +1327,14 @@ func flattenClusterAddonsConfig(c *containerBeta.AddonsConfig) []map[string]inte
1304
1327
},
1305
1328
}
1306
1329
}
1330
+ if c .NetworkPolicyConfig != nil {
1331
+ result ["network_policy_config" ] = []map [string ]interface {}{
1332
+ {
1333
+ "disabled" : c .NetworkPolicyConfig .Disabled ,
1334
+ },
1335
+ }
1336
+ }
1337
+
1307
1338
return []map [string ]interface {}{result }
1308
1339
}
1309
1340
Original file line number Diff line number Diff line change @@ -146,7 +146,16 @@ func TestAccContainerCluster_withNetworkPolicyEnabled(t *testing.T) {
146
146
),
147
147
},
148
148
{
149
- Config : testAccContainerCluster_withNetworkPolicyDisabled (clusterName ),
149
+ Config : testAccContainerCluster_withNetworkPolicyConfigDisabled (clusterName ),
150
+ Check : resource .ComposeTestCheckFunc (
151
+ testAccCheckContainerCluster (
152
+ "google_container_cluster.with_network_policy_enabled" ),
153
+ resource .TestCheckResourceAttr ("google_container_cluster.with_network_policy_enabled" ,
154
+ "addons_config.0.network_policy_config.0.disabled" , "true" ),
155
+ ),
156
+ },
157
+ {
158
+ Config : testAccContainerCluster_withNetworkPolicyConfigDisabled (clusterName ),
150
159
PlanOnly : true ,
151
160
ExpectNonEmptyPlan : false ,
152
161
},
@@ -1142,6 +1151,11 @@ resource "google_container_cluster" "with_network_policy_enabled" {
1142
1151
enabled = true
1143
1152
provider = "CALICO"
1144
1153
}
1154
+ addons_config {
1155
+ network_policy_config {
1156
+ disabled = false
1157
+ }
1158
+ }
1145
1159
}` , clusterName )
1146
1160
}
1147
1161
@@ -1165,6 +1179,22 @@ resource "google_container_cluster" "with_network_policy_enabled" {
1165
1179
}` , clusterName )
1166
1180
}
1167
1181
1182
+ func testAccContainerCluster_withNetworkPolicyConfigDisabled (clusterName string ) string {
1183
+ return fmt .Sprintf (`
1184
+ resource "google_container_cluster" "with_network_policy_enabled" {
1185
+ name = "%s"
1186
+ zone = "us-central1-a"
1187
+ initial_node_count = 1
1188
+
1189
+ network_policy = {}
1190
+ addons_config {
1191
+ network_policy_config {
1192
+ disabled = true
1193
+ }
1194
+ }
1195
+ }` , clusterName )
1196
+ }
1197
+
1168
1198
func testAccContainerCluster_withMasterAuthorizedNetworksConfig (clusterName string , cidrs []string ) string {
1169
1199
1170
1200
cidrBlocks := ""
Original file line number Diff line number Diff line change @@ -169,10 +169,13 @@ The `addons_config` block supports:
169
169
* ` http_load_balancing ` - (Optional) The status of the HTTP (L7) load balancing
170
170
controller addon, which makes it easy to set up HTTP load balancers for services in a
171
171
cluster. It is enabled by default; set ` disabled = true ` to disable.
172
-
173
172
* ` kubernetes_dashboard ` - (Optional) The status of the Kubernetes Dashboard
174
173
add-on, which controls whether the Kubernetes Dashboard is enabled for this cluster.
175
174
It is enabled by default; set ` disabled = true ` to disable.
175
+ * ` network_policy_config ` - (Optional) Whether we should enable the network policy addon
176
+ for the master. This must be enabled in order to enable network policy for the nodes.
177
+ It can only be disabled if the nodes already do not have network policies enabled.
178
+ Set ` disabled = true ` to disable.
176
179
177
180
This example ` addons_config ` disables two addons:
178
181
You can’t perform that action at this time.
0 commit comments