Skip to content

Add network policy config. #1200

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions google/resource_container_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,20 @@ func resourceContainerCluster() *schema.Resource {
},
},
},
"network_policy_config": {
Type: schema.TypeList,
Optional: true,
Computed: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"disabled": {
Type: schema.TypeBool,
Optional: true,
},
},
},
},
},
},
},
Expand Down Expand Up @@ -1182,6 +1196,15 @@ func expandClusterAddonsConfig(configured interface{}) *containerBeta.AddonsConf
ForceSendFields: []string{"Disabled"},
}
}

if v, ok := config["network_policy_config"]; ok && len(v.([]interface{})) > 0 {
addon := v.([]interface{})[0].(map[string]interface{})
ac.NetworkPolicyConfig = &containerBeta.NetworkPolicyConfig{
Disabled: addon["disabled"].(bool),
ForceSendFields: []string{"Disabled"},
}
}

return ac
}

Expand Down Expand Up @@ -1299,6 +1322,14 @@ func flattenClusterAddonsConfig(c *containerBeta.AddonsConfig) []map[string]inte
},
}
}
if c.NetworkPolicyConfig != nil {
result["network_policy_config"] = []map[string]interface{}{
{
"disabled": c.NetworkPolicyConfig.Disabled,
},
}
}

return []map[string]interface{}{result}
}

Expand Down
32 changes: 31 additions & 1 deletion google/resource_container_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,16 @@ func TestAccContainerCluster_withNetworkPolicyEnabled(t *testing.T) {
),
},
{
Config: testAccContainerCluster_withNetworkPolicyDisabled(clusterName),
Config: testAccContainerCluster_withNetworkPolicyConfigDisabled(clusterName),
Check: resource.ComposeTestCheckFunc(
testAccCheckContainerCluster(
"google_container_cluster.with_network_policy_enabled"),
resource.TestCheckResourceAttr("google_container_cluster.with_network_policy_enabled",
"addons_config.0.network_policy_config.0.disabled", "true"),
),
},
{
Config: testAccContainerCluster_withNetworkPolicyConfigDisabled(clusterName),
PlanOnly: true,
ExpectNonEmptyPlan: false,
},
Expand Down Expand Up @@ -1121,6 +1130,11 @@ resource "google_container_cluster" "with_network_policy_enabled" {
enabled = true
provider = "CALICO"
}
addons_config {
network_policy_config {
disabled = false
}
}
}`, clusterName)
}

Expand All @@ -1144,6 +1158,22 @@ resource "google_container_cluster" "with_network_policy_enabled" {
}`, clusterName)
}

func testAccContainerCluster_withNetworkPolicyConfigDisabled(clusterName string) string {
return fmt.Sprintf(`
resource "google_container_cluster" "with_network_policy_enabled" {
name = "%s"
zone = "us-central1-a"
initial_node_count = 1

network_policy = {}
addons_config {
network_policy_config {
disabled = true
}
}
}`, clusterName)
}

func testAccContainerCluster_withMasterAuthorizedNetworksConfig(clusterName string, cidrs []string) string {

cidrBlocks := ""
Expand Down
5 changes: 4 additions & 1 deletion website/docs/r/container_cluster.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,13 @@ The `addons_config` block supports:
* `http_load_balancing` - (Optional) The status of the HTTP (L7) load balancing
controller addon, which makes it easy to set up HTTP load balancers for services in a
cluster. It is enabled by default; set `disabled = true` to disable.

* `kubernetes_dashboard` - (Optional) The status of the Kubernetes Dashboard
add-on, which controls whether the Kubernetes Dashboard is enabled for this cluster.
It is enabled by default; set `disabled = true` to disable.
* `network_policy_config` - (Optional) Whether we should enable the network policy addon
for the master. This must be enabled in order to enable network policy for the nodes.
It can only be disabled if the nodes already do not have network policies enabled.
Set `disabled = true` to disable.

This example `addons_config` disables two addons:

Expand Down