Skip to content

Commit

Permalink
Allow updating DNSConfig in-place (GoogleCloudPlatform#9446)
Browse files Browse the repository at this point in the history
* Allow updating DNSConfig in-place

* leave DNS_SCOPE_UNSPECIFIED as default for cluster_dns_scope

* Revert expandDnsConfig() return change

* Add DNSConfig update test step
  • Loading branch information
wewark authored Dec 1, 2023
1 parent 1e11f80 commit 95bc4cc
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2005,7 +2005,6 @@ func ResourceContainerCluster() *schema.Resource {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
ForceNew: true,
DiffSuppressFunc: suppressDiffForAutopilot,
Description: `Configuration for Cloud DNS for Kubernetes Engine.`,
Elem: &schema.Resource{
Expand Down Expand Up @@ -2956,6 +2955,22 @@ func resourceContainerClusterUpdate(d *schema.ResourceData, meta interface{}) er
log.Printf("[INFO] GKE cluster %s's cluster-wide autoscaling has been updated", d.Id())
}

if d.HasChange("dns_config") {
req := &container.UpdateClusterRequest{
Update: &container.ClusterUpdate{
DesiredDnsConfig: expandDnsConfig(d.Get("dns_config")),
},
}

updateF := updateFunc(req, "updating GKE cluster DNSConfig")
// Call update serially.
if err := transport_tpg.LockedCall(lockKey, updateF); err != nil {
return err
}

log.Printf("[INFO] GKE cluster %s's DNSConfig has been updated", d.Id())
}

if d.HasChange("allow_net_admin") {
allowed := d.Get("allow_net_admin").(bool)
req := &container.UpdateClusterRequest{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1793,7 +1793,6 @@ func resourceContainerClusterResourceV1() *schema.Resource {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
ForceNew: true,
DiffSuppressFunc: suppressDiffForAutopilot,
Description: `Configuration for Cloud DNS for Kubernetes Engine.`,
Elem: &schema.Resource{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4078,13 +4078,22 @@ func TestAccContainerCluster_withDNSConfig(t *testing.T) {
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
CheckDestroy: testAccCheckContainerClusterDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccContainerCluster_basic(clusterName, networkName, subnetworkName),
},
{
ResourceName: "google_container_cluster.primary",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"deletion_protection"},
},
{
Config: testAccContainerCluster_withDNSConfig(clusterName, "CLOUD_DNS", domainName, "VPC_SCOPE", networkName, subnetworkName),
},
{
ResourceName: "google_container_cluster.with_dns_config",
ImportState: true,
ImportStateVerify: true,
ResourceName: "google_container_cluster.primary",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"deletion_protection"},
},
},
Expand Down Expand Up @@ -8398,9 +8407,9 @@ resource "google_container_cluster" "with_autopilot" {

func testAccContainerCluster_withDNSConfig(clusterName, clusterDns, clusterDnsDomain, clusterDnsScope, networkName, subnetworkName string) string {
return fmt.Sprintf(`
resource "google_container_cluster" "with_dns_config" {
name = "%s"
location = "us-central1-f"
resource "google_container_cluster" "primary" {
name = "%s"
location = "us-central1-a"
initial_node_count = 1
dns_config {
cluster_dns = "%s"
Expand Down

0 comments on commit 95bc4cc

Please sign in to comment.