Skip to content

Commit 05a110e

Browse files
Adding support for Cloud DNS Additive VPC Scope for GKE, currently in preview (#10590) (#7321)
[upstream:d20b9dd485b908780761f82ad6a89c8fa62d592a] Signed-off-by: Modular Magician <[email protected]>
1 parent 1b8cb4b commit 05a110e

File tree

3 files changed

+55
-6
lines changed

3 files changed

+55
-6
lines changed

google-beta/services/container/resource_container_cluster.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2015,6 +2015,11 @@ func ResourceContainerCluster() *schema.Resource {
20152015
Description: `Configuration for Cloud DNS for Kubernetes Engine.`,
20162016
Elem: &schema.Resource{
20172017
Schema: map[string]*schema.Schema{
2018+
"additive_vpc_scope_dns_domain": {
2019+
Type: schema.TypeString,
2020+
Description: `Enable additive VPC scope DNS in a GKE cluster.`,
2021+
Optional: true,
2022+
},
20182023
"cluster_dns": {
20192024
Type: schema.TypeString,
20202025
Default: "PROVIDER_UNSPECIFIED",
@@ -5240,9 +5245,10 @@ func expandDnsConfig(configured interface{}) *container.DNSConfig {
52405245

52415246
config := l[0].(map[string]interface{})
52425247
return &container.DNSConfig{
5243-
ClusterDns: config["cluster_dns"].(string),
5244-
ClusterDnsScope: config["cluster_dns_scope"].(string),
5245-
ClusterDnsDomain: config["cluster_dns_domain"].(string),
5248+
AdditiveVpcScopeDnsDomain: config["additive_vpc_scope_dns_domain"].(string),
5249+
ClusterDns: config["cluster_dns"].(string),
5250+
ClusterDnsScope: config["cluster_dns_scope"].(string),
5251+
ClusterDnsDomain: config["cluster_dns_domain"].(string),
52465252
}
52475253
}
52485254

@@ -6101,9 +6107,10 @@ func flattenDnsConfig(c *container.DNSConfig) []map[string]interface{} {
61016107
}
61026108
return []map[string]interface{}{
61036109
{
6104-
"cluster_dns": c.ClusterDns,
6105-
"cluster_dns_scope": c.ClusterDnsScope,
6106-
"cluster_dns_domain": c.ClusterDnsDomain,
6110+
"additive_vpc_scope_dns_domain": c.AdditiveVpcScopeDnsDomain,
6111+
"cluster_dns": c.ClusterDns,
6112+
"cluster_dns_scope": c.ClusterDnsScope,
6113+
"cluster_dns_domain": c.ClusterDnsDomain,
61076114
},
61086115
}
61096116
}

google-beta/services/container/resource_container_cluster_test.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,29 @@ func TestAccContainerCluster_withFQDNNetworkPolicy(t *testing.T) {
487487
})
488488
}
489489

490+
func TestAccContainerCluster_withAdditiveVPC(t *testing.T) {
491+
t.Parallel()
492+
493+
clusterName := fmt.Sprintf("tf-test-cluster-%s", acctest.RandString(t, 10))
494+
495+
acctest.VcrTest(t, resource.TestCase{
496+
PreCheck: func() { acctest.AccTestPreCheck(t) },
497+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
498+
CheckDestroy: testAccCheckContainerClusterDestroyProducer(t),
499+
Steps: []resource.TestStep{
500+
{
501+
Config: testAccContainerCluster_withAdditiveVPC(clusterName),
502+
},
503+
{
504+
ResourceName: "google_container_cluster.cluster",
505+
ImportState: true,
506+
ImportStateVerify: true,
507+
ImportStateVerifyIgnore: []string{"min_master_version", "deletion_protection"},
508+
},
509+
},
510+
})
511+
}
512+
490513
func TestAccContainerCluster_withMasterAuthConfig_NoCert(t *testing.T) {
491514
t.Parallel()
492515

@@ -627,6 +650,23 @@ resource "google_container_cluster" "cluster" {
627650
`, clusterName, clusterName)
628651
}
629652

653+
func testAccContainerCluster_withAdditiveVPC(clusterName string) string {
654+
return fmt.Sprintf(`
655+
resource "google_container_cluster" "cluster" {
656+
name = "%s"
657+
location = "us-central1-a"
658+
initial_node_count = 1
659+
660+
dns_config {
661+
cluster_dns = "CLOUD_DNS"
662+
additive_vpc_scope_dns_domain = "test.com"
663+
cluster_dns_scope = "CLUSTER_SCOPE"
664+
}
665+
deletion_protection = false
666+
}
667+
`, clusterName)
668+
}
669+
630670
func testAccContainerCluster_withFQDNNetworkPolicy(clusterName string, enabled bool) string {
631671
return fmt.Sprintf(`
632672
data "google_container_engine_versions" "uscentral1a" {

website/docs/r/container_cluster.html.markdown

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1287,6 +1287,8 @@ linux_node_config {
12871287

12881288
<a name="nested_dns_config"></a>The `dns_config` block supports:
12891289

1290+
* `additive_vpc_scope_dns_domain` - (Optional, [Beta](https://terraform.io/docs/providers/google/guides/provider_versions.html)) This will enable Cloud DNS additive VPC scope. Must provide a domain name that is unique within the VPC. For this to work `cluster_dns = "CLOUD_DNS"` and `cluster_dns_scope = "CLUSTER_SCOPE"` must both be set as well.
1291+
12901292
* `cluster_dns` - (Optional) Which in-cluster DNS provider should be used. `PROVIDER_UNSPECIFIED` (default) or `PLATFORM_DEFAULT` or `CLOUD_DNS`.
12911293

12921294
* `cluster_dns_scope` - (Optional) The scope of access to cluster DNS records. `DNS_SCOPE_UNSPECIFIED` (default) or `CLUSTER_SCOPE` or `VPC_SCOPE`.

0 commit comments

Comments
 (0)