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

Promote dns_config of google_container_cluster to GA #10892

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/5495.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
container: promoted `dns_config` field of `google_container_cluster` to GA
```
62 changes: 61 additions & 1 deletion google/resource_container_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -1056,6 +1056,36 @@ func resourceContainerCluster() *schema.Resource {
},
},
},
"dns_config": {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
ForceNew: true,
Description: `Configuration for Cloud DNS for Kubernetes Engine.`,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"cluster_dns": {
Type: schema.TypeString,
Default: "PROVIDER_UNSPECIFIED",
ValidateFunc: validation.StringInSlice([]string{"PROVIDER_UNSPECIFIED", "PLATFORM_DEFAULT", "CLOUD_DNS"}, false),
Description: `Which in-cluster DNS provider should be used.`,
Optional: true,
},
"cluster_dns_scope": {
Type: schema.TypeString,
Default: "DNS_SCOPE_UNSPECIFIED",
ValidateFunc: validation.StringInSlice([]string{"DNS_SCOPE_UNSPECIFIED", "CLUSTER_SCOPE", "VPC_SCOPE"}, false),
Description: `The scope of access to cluster DNS records.`,
Optional: true,
},
"cluster_dns_domain": {
Type: schema.TypeString,
Description: `The suffix used for all cluster service records.`,
Optional: true,
},
},
},
},
},
}
}
Expand Down Expand Up @@ -1175,6 +1205,7 @@ func resourceContainerClusterCreate(d *schema.ResourceData, meta interface{}) er
DefaultSnatStatus: expandDefaultSnatStatus(d.Get("default_snat_status")),
DatapathProvider: d.Get("datapath_provider").(string),
PrivateIpv6GoogleAccess: d.Get("private_ipv6_google_access").(string),
DnsConfig: expandDnsConfig(d.Get("dns_config")),
},
MasterAuth: expandMasterAuth(d.Get("master_auth")),
ConfidentialNodes: expandConfidentialNodes(d.Get("confidential_nodes")),
Expand Down Expand Up @@ -1597,7 +1628,9 @@ func resourceContainerClusterRead(d *schema.ResourceData, meta interface{}) erro
if err := d.Set("resource_usage_export_config", flattenResourceUsageExportConfig(cluster.ResourceUsageExportConfig)); err != nil {
return err
}

if err := d.Set("dns_config", flattenDnsConfig(cluster.NetworkConfig.DnsConfig)); err != nil {
return err
}
if err := d.Set("logging_config", flattenContainerClusterLoggingConfig(cluster.LoggingConfig)); err != nil {
return err
}
Expand Down Expand Up @@ -2939,6 +2972,20 @@ func expandResourceUsageExportConfig(configured interface{}) *container.Resource
return result
}

func expandDnsConfig(configured interface{}) *container.DNSConfig {
l := configured.([]interface{})
if len(l) == 0 || l[0] == nil {
return nil
}

config := l[0].(map[string]interface{})
return &container.DNSConfig{
ClusterDns: config["cluster_dns"].(string),
ClusterDnsScope: config["cluster_dns_scope"].(string),
ClusterDnsDomain: config["cluster_dns_domain"].(string),
}
}

func expandContainerClusterLoggingConfig(configured interface{}) *container.LoggingConfig {
l := configured.([]interface{})
if len(l) == 0 || l[0] == nil {
Expand Down Expand Up @@ -3316,6 +3363,19 @@ func flattenDatabaseEncryption(c *container.DatabaseEncryption) []map[string]int
}
}

func flattenDnsConfig(c *container.DNSConfig) []map[string]interface{} {
if c == nil {
return nil
}
return []map[string]interface{}{
{
"cluster_dns": c.ClusterDns,
"cluster_dns_scope": c.ClusterDnsScope,
"cluster_dns_domain": c.ClusterDnsDomain,
},
}
}

func flattenContainerClusterLoggingConfig(c *container.LoggingConfig) []map[string]interface{} {
if c == nil {
return nil
Expand Down
37 changes: 37 additions & 0 deletions google/resource_container_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1818,6 +1818,28 @@ func TestAccContainerCluster_withIPv4Error(t *testing.T) {
})
}

func TestAccContainerCluster_withDNSConfig(t *testing.T) {
t.Parallel()

clusterName := fmt.Sprintf("tf-test-cluster-%s", randString(t, 10))
domainName := fmt.Sprintf("tf-test-domain-%s", randString(t, 10))
vcrTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckContainerClusterDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccContainerCluster_withDNSConfig(clusterName, "CLOUD_DNS", domainName, "VPC_SCOPE"),
},
{
ResourceName: "google_container_cluster.with_dns_config",
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func testAccContainerCluster_masterAuthorizedNetworksDisabled(t *testing.T, resource_name string) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[resource_name]
Expand Down Expand Up @@ -3770,6 +3792,21 @@ resource "google_container_cluster" "with_autopilot" {
`, containerNetName, clusterName, location, enabled)
}

func testAccContainerCluster_withDNSConfig(clusterName string, clusterDns string, clusterDnsDomain string, clusterDnsScope string) string {
return fmt.Sprintf(`
resource "google_container_cluster" "with_dns_config" {
name = "%s"
location = "us-central1-f"
initial_node_count = 1
dns_config {
cluster_dns = "%s"
cluster_dns_domain = "%s"
cluster_dns_scope = "%s"
}
}
`, clusterName, clusterDns, clusterDnsDomain, clusterDnsScope)
}

func testAccContainerCluster_withLoggingConfigEnabled(name string) string {
return fmt.Sprintf(`
resource "google_container_cluster" "primary" {
Expand Down
2 changes: 1 addition & 1 deletion website/docs/r/container_cluster.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ subnetwork in which the cluster's instances are launched.
* `default_snat_status` - (Optional)
[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)

* `dns_config` - (Optional, [Beta](https://terraform.io/docs/providers/google/guides/provider_versions.html))
* `dns_config` - (Optional)
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).

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