Skip to content

Commit 8719920

Browse files
Promote dns_config of google_container_cluster to GA (#5495) (#10892)
Co-authored-by: upodroid <cy@borg.dev> Signed-off-by: Modular Magician <magic-modules@google.com> Co-authored-by: upodroid <cy@borg.dev>
1 parent ce4ccc9 commit 8719920

File tree

4 files changed

+102
-2
lines changed

4 files changed

+102
-2
lines changed

.changelog/5495.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
container: promoted `dns_config` field of `google_container_cluster` to GA
3+
```

google/resource_container_cluster.go

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1056,6 +1056,36 @@ func resourceContainerCluster() *schema.Resource {
10561056
},
10571057
},
10581058
},
1059+
"dns_config": {
1060+
Type: schema.TypeList,
1061+
Optional: true,
1062+
MaxItems: 1,
1063+
ForceNew: true,
1064+
Description: `Configuration for Cloud DNS for Kubernetes Engine.`,
1065+
Elem: &schema.Resource{
1066+
Schema: map[string]*schema.Schema{
1067+
"cluster_dns": {
1068+
Type: schema.TypeString,
1069+
Default: "PROVIDER_UNSPECIFIED",
1070+
ValidateFunc: validation.StringInSlice([]string{"PROVIDER_UNSPECIFIED", "PLATFORM_DEFAULT", "CLOUD_DNS"}, false),
1071+
Description: `Which in-cluster DNS provider should be used.`,
1072+
Optional: true,
1073+
},
1074+
"cluster_dns_scope": {
1075+
Type: schema.TypeString,
1076+
Default: "DNS_SCOPE_UNSPECIFIED",
1077+
ValidateFunc: validation.StringInSlice([]string{"DNS_SCOPE_UNSPECIFIED", "CLUSTER_SCOPE", "VPC_SCOPE"}, false),
1078+
Description: `The scope of access to cluster DNS records.`,
1079+
Optional: true,
1080+
},
1081+
"cluster_dns_domain": {
1082+
Type: schema.TypeString,
1083+
Description: `The suffix used for all cluster service records.`,
1084+
Optional: true,
1085+
},
1086+
},
1087+
},
1088+
},
10591089
},
10601090
}
10611091
}
@@ -1175,6 +1205,7 @@ func resourceContainerClusterCreate(d *schema.ResourceData, meta interface{}) er
11751205
DefaultSnatStatus: expandDefaultSnatStatus(d.Get("default_snat_status")),
11761206
DatapathProvider: d.Get("datapath_provider").(string),
11771207
PrivateIpv6GoogleAccess: d.Get("private_ipv6_google_access").(string),
1208+
DnsConfig: expandDnsConfig(d.Get("dns_config")),
11781209
},
11791210
MasterAuth: expandMasterAuth(d.Get("master_auth")),
11801211
ConfidentialNodes: expandConfidentialNodes(d.Get("confidential_nodes")),
@@ -1597,7 +1628,9 @@ func resourceContainerClusterRead(d *schema.ResourceData, meta interface{}) erro
15971628
if err := d.Set("resource_usage_export_config", flattenResourceUsageExportConfig(cluster.ResourceUsageExportConfig)); err != nil {
15981629
return err
15991630
}
1600-
1631+
if err := d.Set("dns_config", flattenDnsConfig(cluster.NetworkConfig.DnsConfig)); err != nil {
1632+
return err
1633+
}
16011634
if err := d.Set("logging_config", flattenContainerClusterLoggingConfig(cluster.LoggingConfig)); err != nil {
16021635
return err
16031636
}
@@ -2939,6 +2972,20 @@ func expandResourceUsageExportConfig(configured interface{}) *container.Resource
29392972
return result
29402973
}
29412974

2975+
func expandDnsConfig(configured interface{}) *container.DNSConfig {
2976+
l := configured.([]interface{})
2977+
if len(l) == 0 || l[0] == nil {
2978+
return nil
2979+
}
2980+
2981+
config := l[0].(map[string]interface{})
2982+
return &container.DNSConfig{
2983+
ClusterDns: config["cluster_dns"].(string),
2984+
ClusterDnsScope: config["cluster_dns_scope"].(string),
2985+
ClusterDnsDomain: config["cluster_dns_domain"].(string),
2986+
}
2987+
}
2988+
29422989
func expandContainerClusterLoggingConfig(configured interface{}) *container.LoggingConfig {
29432990
l := configured.([]interface{})
29442991
if len(l) == 0 || l[0] == nil {
@@ -3316,6 +3363,19 @@ func flattenDatabaseEncryption(c *container.DatabaseEncryption) []map[string]int
33163363
}
33173364
}
33183365

3366+
func flattenDnsConfig(c *container.DNSConfig) []map[string]interface{} {
3367+
if c == nil {
3368+
return nil
3369+
}
3370+
return []map[string]interface{}{
3371+
{
3372+
"cluster_dns": c.ClusterDns,
3373+
"cluster_dns_scope": c.ClusterDnsScope,
3374+
"cluster_dns_domain": c.ClusterDnsDomain,
3375+
},
3376+
}
3377+
}
3378+
33193379
func flattenContainerClusterLoggingConfig(c *container.LoggingConfig) []map[string]interface{} {
33203380
if c == nil {
33213381
return nil

google/resource_container_cluster_test.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1818,6 +1818,28 @@ func TestAccContainerCluster_withIPv4Error(t *testing.T) {
18181818
})
18191819
}
18201820

1821+
func TestAccContainerCluster_withDNSConfig(t *testing.T) {
1822+
t.Parallel()
1823+
1824+
clusterName := fmt.Sprintf("tf-test-cluster-%s", randString(t, 10))
1825+
domainName := fmt.Sprintf("tf-test-domain-%s", randString(t, 10))
1826+
vcrTest(t, resource.TestCase{
1827+
PreCheck: func() { testAccPreCheck(t) },
1828+
Providers: testAccProviders,
1829+
CheckDestroy: testAccCheckContainerClusterDestroyProducer(t),
1830+
Steps: []resource.TestStep{
1831+
{
1832+
Config: testAccContainerCluster_withDNSConfig(clusterName, "CLOUD_DNS", domainName, "VPC_SCOPE"),
1833+
},
1834+
{
1835+
ResourceName: "google_container_cluster.with_dns_config",
1836+
ImportState: true,
1837+
ImportStateVerify: true,
1838+
},
1839+
},
1840+
})
1841+
}
1842+
18211843
func testAccContainerCluster_masterAuthorizedNetworksDisabled(t *testing.T, resource_name string) resource.TestCheckFunc {
18221844
return func(s *terraform.State) error {
18231845
rs, ok := s.RootModule().Resources[resource_name]
@@ -3770,6 +3792,21 @@ resource "google_container_cluster" "with_autopilot" {
37703792
`, containerNetName, clusterName, location, enabled)
37713793
}
37723794

3795+
func testAccContainerCluster_withDNSConfig(clusterName string, clusterDns string, clusterDnsDomain string, clusterDnsScope string) string {
3796+
return fmt.Sprintf(`
3797+
resource "google_container_cluster" "with_dns_config" {
3798+
name = "%s"
3799+
location = "us-central1-f"
3800+
initial_node_count = 1
3801+
dns_config {
3802+
cluster_dns = "%s"
3803+
cluster_dns_domain = "%s"
3804+
cluster_dns_scope = "%s"
3805+
}
3806+
}
3807+
`, clusterName, clusterDns, clusterDnsDomain, clusterDnsScope)
3808+
}
3809+
37733810
func testAccContainerCluster_withLoggingConfigEnabled(name string) string {
37743811
return fmt.Sprintf(`
37753812
resource "google_container_cluster" "primary" {

website/docs/r/container_cluster.html.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ subnetwork in which the cluster's instances are launched.
337337
* `default_snat_status` - (Optional)
338338
[GKE SNAT](https://cloud.google.com/kubernetes-engine/docs/how-to/ip-masquerade-agent#how_ipmasq_works) DefaultSnatStatus contains the desired state of whether default sNAT should be disabled on the cluster, [API doc](https://cloud.google.com/kubernetes-engine/docs/reference/rest/v1beta1/projects.locations.clusters#networkconfig). Structure is [documented below](#nested_default_snat_status)
339339

340-
* `dns_config` - (Optional, [Beta](https://terraform.io/docs/providers/google/guides/provider_versions.html))
340+
* `dns_config` - (Optional)
341341
Configuration for [Using Cloud DNS for GKE](https://cloud.google.com/kubernetes-engine/docs/how-to/cloud-dns). Structure is [documented below](#nested_dns_config).
342342

343343
<a name="nested_default_snat_status"></a>The `default_snat_status` block supports

0 commit comments

Comments
 (0)