Skip to content

Commit 2d02e20

Browse files
Allow updating DNSConfig in-place (#9446) (#16652)
* Allow updating DNSConfig in-place * leave DNS_SCOPE_UNSPECIFIED as default for cluster_dns_scope * Revert expandDnsConfig() return change * Add DNSConfig update test step [upstream:95bc4cc1c10e7ed012f9f67eb2e876d796cdf30d] Signed-off-by: Modular Magician <[email protected]>
1 parent 473ae4d commit 2d02e20

File tree

4 files changed

+32
-6
lines changed

4 files changed

+32
-6
lines changed

.changelog/9446.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:bug
2+
Allow updating DNSConfig in-place
3+
```

google/services/container/resource_container_cluster.go

+16-1
Original file line numberDiff line numberDiff line change
@@ -1794,7 +1794,6 @@ func ResourceContainerCluster() *schema.Resource {
17941794
Type: schema.TypeList,
17951795
Optional: true,
17961796
MaxItems: 1,
1797-
ForceNew: true,
17981797
DiffSuppressFunc: suppressDiffForAutopilot,
17991798
Description: `Configuration for Cloud DNS for Kubernetes Engine.`,
18001799
Elem: &schema.Resource{
@@ -2702,6 +2701,22 @@ func resourceContainerClusterUpdate(d *schema.ResourceData, meta interface{}) er
27022701
log.Printf("[INFO] GKE cluster %s's cluster-wide autoscaling has been updated", d.Id())
27032702
}
27042703

2704+
if d.HasChange("dns_config") {
2705+
req := &container.UpdateClusterRequest{
2706+
Update: &container.ClusterUpdate{
2707+
DesiredDnsConfig: expandDnsConfig(d.Get("dns_config")),
2708+
},
2709+
}
2710+
2711+
updateF := updateFunc(req, "updating GKE cluster DNSConfig")
2712+
// Call update serially.
2713+
if err := transport_tpg.LockedCall(lockKey, updateF); err != nil {
2714+
return err
2715+
}
2716+
2717+
log.Printf("[INFO] GKE cluster %s's DNSConfig has been updated", d.Id())
2718+
}
2719+
27052720
if d.HasChange("allow_net_admin") {
27062721
allowed := d.Get("allow_net_admin").(bool)
27072722
req := &container.UpdateClusterRequest{

google/services/container/resource_container_cluster_migratev1.go

-1
Original file line numberDiff line numberDiff line change
@@ -1595,7 +1595,6 @@ func resourceContainerClusterResourceV1() *schema.Resource {
15951595
Type: schema.TypeList,
15961596
Optional: true,
15971597
MaxItems: 1,
1598-
ForceNew: true,
15991598
DiffSuppressFunc: suppressDiffForAutopilot,
16001599
Description: `Configuration for Cloud DNS for Kubernetes Engine.`,
16011600
Elem: &schema.Resource{

google/services/container/resource_container_cluster_test.go

+13-4
Original file line numberDiff line numberDiff line change
@@ -3485,11 +3485,20 @@ func TestAccContainerCluster_withDNSConfig(t *testing.T) {
34853485
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
34863486
CheckDestroy: testAccCheckContainerClusterDestroyProducer(t),
34873487
Steps: []resource.TestStep{
3488+
{
3489+
Config: testAccContainerCluster_basic(clusterName, networkName, subnetworkName),
3490+
},
3491+
{
3492+
ResourceName: "google_container_cluster.primary",
3493+
ImportState: true,
3494+
ImportStateVerify: true,
3495+
ImportStateVerifyIgnore: []string{"deletion_protection"},
3496+
},
34883497
{
34893498
Config: testAccContainerCluster_withDNSConfig(clusterName, "CLOUD_DNS", domainName, "VPC_SCOPE", networkName, subnetworkName),
34903499
},
34913500
{
3492-
ResourceName: "google_container_cluster.with_dns_config",
3501+
ResourceName: "google_container_cluster.primary",
34933502
ImportState: true,
34943503
ImportStateVerify: true,
34953504
ImportStateVerifyIgnore: []string{"deletion_protection"},
@@ -7314,9 +7323,9 @@ resource "google_container_cluster" "with_autopilot" {
73147323

73157324
func testAccContainerCluster_withDNSConfig(clusterName, clusterDns, clusterDnsDomain, clusterDnsScope, networkName, subnetworkName string) string {
73167325
return fmt.Sprintf(`
7317-
resource "google_container_cluster" "with_dns_config" {
7318-
name = "%s"
7319-
location = "us-central1-f"
7326+
resource "google_container_cluster" "primary" {
7327+
name = "%s"
7328+
location = "us-central1-a"
73207329
initial_node_count = 1
73217330
dns_config {
73227331
cluster_dns = "%s"

0 commit comments

Comments
 (0)