Skip to content
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

[Terraform] Add support for dns_cache_config to resource_container_cluster #1853

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
3 changes: 3 additions & 0 deletions .changelog/3126.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
container: added `dns_cache_config` field to `google_container_cluster` resource
```
33 changes: 33 additions & 0 deletions google-beta/resource_container_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ var (
"addons_config.0.network_policy_config",
"addons_config.0.istio_config",
"addons_config.0.cloudrun_config",
"addons_config.0.dns_cache_config",
}
)

Expand Down Expand Up @@ -278,6 +279,22 @@ func resourceContainerCluster() *schema.Resource {
},
},
},
"dns_cache_config": {
Type: schema.TypeList,
Optional: true,
Computed: true,
AtLeastOneOf: addonsConfigKeys,
ForceNew: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"enabled": {
Type: schema.TypeBool,
Required: true,
},
},
},
},
},
},
},
Expand Down Expand Up @@ -2166,6 +2183,14 @@ func expandClusterAddonsConfig(configured interface{}) *containerBeta.AddonsConf
}
}

if v, ok := config["dns_cache_config"]; ok && len(v.([]interface{})) > 0 {
addon := v.([]interface{})[0].(map[string]interface{})
ac.DnsCacheConfig = &containerBeta.DnsCacheConfig{
Enabled: addon["enabled"].(bool),
ForceSendFields: []string{"Enabled"},
}
}

return ac
}

Expand Down Expand Up @@ -2560,6 +2585,14 @@ func flattenClusterAddonsConfig(c *containerBeta.AddonsConfig) []map[string]inte
},
}
}

if c.DnsCacheConfig != nil {
result["dns_cache_config"] = []map[string]interface{}{
{
"enabled": c.DnsCacheConfig.Enabled,
},
}
}
return []map[string]interface{}{result}
}

Expand Down
24 changes: 18 additions & 6 deletions google-beta/resource_container_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,17 +144,19 @@ func TestAccContainerCluster_withAddons(t *testing.T) {
Config: testAccContainerCluster_withAddons(clusterName),
},
{
ResourceName: "google_container_cluster.primary",
ImportState: true,
ImportStateVerify: true,
ResourceName: "google_container_cluster.primary",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"min_master_version"},
},
{
Config: testAccContainerCluster_updateAddons(clusterName),
},
{
ResourceName: "google_container_cluster.primary",
ImportState: true,
ImportStateVerify: true,
ResourceName: "google_container_cluster.primary",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"min_master_version"},
},
},
})
Expand Down Expand Up @@ -1937,6 +1939,8 @@ resource "google_container_cluster" "primary" {
location = "us-central1-a"
initial_node_count = 1

min_master_version = "latest"

addons_config {
http_load_balancing {
disabled = true
Expand All @@ -1954,6 +1958,9 @@ resource "google_container_cluster" "primary" {
cloudrun_config {
disabled = true
}
dns_cache_config {
enabled = false
}
}
}
`, clusterName)
Expand All @@ -1966,6 +1973,8 @@ resource "google_container_cluster" "primary" {
location = "us-central1-a"
initial_node_count = 1

min_master_version = "latest"

addons_config {
http_load_balancing {
disabled = false
Expand All @@ -1983,6 +1992,9 @@ resource "google_container_cluster" "primary" {
cloudrun_config {
disabled = false
}
dns_cache_config {
enabled = true
}
}
}
`, clusterName)
Expand Down
7 changes: 7 additions & 0 deletions website/docs/r/container_cluster.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,13 @@ The `addons_config` block supports:
* `cloudrun_config` - (Optional, [Beta](https://terraform.io/docs/providers/google/guides/provider_versions.html)).
The status of the CloudRun addon. It requires `istio_config` enabled. It is disabled by default.
Set `disabled = false` to enable. This addon can only be enabled at cluster creation time.

* `dns_cache_config` - (Optional, [Beta](https://terraform.io/docs/providers/google/guides/provider_versions.html)).
The status of the NodeLocal DNSCache addon. It is disabled by default.
Set `enabled = true` to enable.

**Enabling/Disabling NodeLocal DNSCache in an existing cluster is a disruptive operation.
All cluster nodes running GKE 1.15 and higher are recreated.**

This example `addons_config` disables two addons:

Expand Down