From 33e324d5b5398919a7caeb9b0044ce28bed4ed6c Mon Sep 17 00:00:00 2001 From: Modular Magician Date: Fri, 13 Mar 2020 20:40:38 +0000 Subject: [PATCH] =?UTF-8?q?[Terraform]=20Add=20support=20for=20dns=5Fcache?= =?UTF-8?q?=5Fconfig=20to=20resource=5Fcontai=E2=80=A6=20(#3126)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add support for dns_cache_config to resource_container_cluster * Changes for tests to run Signed-off-by: Modular Magician --- .changelog/3126.txt | 3 ++ google-beta/resource_container_cluster.go | 33 +++++++++++++++++++ .../resource_container_cluster_test.go | 24 ++++++++++---- .../docs/r/container_cluster.html.markdown | 7 ++++ 4 files changed, 61 insertions(+), 6 deletions(-) create mode 100644 .changelog/3126.txt diff --git a/.changelog/3126.txt b/.changelog/3126.txt new file mode 100644 index 0000000000..c66590a51f --- /dev/null +++ b/.changelog/3126.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +container: added `dns_cache_config` field to `google_container_cluster` resource +``` diff --git a/google-beta/resource_container_cluster.go b/google-beta/resource_container_cluster.go index ed7f24893e..7e4c30b041 100644 --- a/google-beta/resource_container_cluster.go +++ b/google-beta/resource_container_cluster.go @@ -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", } ) @@ -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, + }, + }, + }, + }, }, }, }, @@ -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 } @@ -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} } diff --git a/google-beta/resource_container_cluster_test.go b/google-beta/resource_container_cluster_test.go index facabd8bfa..41297daf1f 100644 --- a/google-beta/resource_container_cluster_test.go +++ b/google-beta/resource_container_cluster_test.go @@ -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"}, }, }, }) @@ -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 @@ -1954,6 +1958,9 @@ resource "google_container_cluster" "primary" { cloudrun_config { disabled = true } + dns_cache_config { + enabled = false + } } } `, clusterName) @@ -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 @@ -1983,6 +1992,9 @@ resource "google_container_cluster" "primary" { cloudrun_config { disabled = false } + dns_cache_config { + enabled = true + } } } `, clusterName) diff --git a/website/docs/r/container_cluster.html.markdown b/website/docs/r/container_cluster.html.markdown index 5f55023a68..c91ce72b3e 100644 --- a/website/docs/r/container_cluster.html.markdown +++ b/website/docs/r/container_cluster.html.markdown @@ -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: