Skip to content

Commit a9917d0

Browse files
Suppress diffs in the Fleet block between null vs {} vs {project = ""} (#13512)
[upstream:a00e8fa9ad0c2b62821e8c512ee341e19cbf15a3] Signed-off-by: Modular Magician <[email protected]>
1 parent 443ca35 commit a9917d0

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

google-beta/services/container/resource_container_cluster.go

+10
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,20 @@ var (
123123
})
124124

125125
suppressDiffForPreRegisteredFleet = schema.SchemaDiffSuppressFunc(func(k, oldValue, newValue string, d *schema.ResourceData) bool {
126+
// Suppress if the cluster has been pre registered to fleet.
126127
if v, _ := d.Get("fleet.0.pre_registered").(bool); v {
127128
log.Printf("[DEBUG] fleet suppress pre_registered: %v\n", v)
128129
return true
129130
}
131+
// Suppress the addition of a fleet block (count changes 0 -> 1) if the "project" field being added is null or empty.
132+
if k == "fleet.#" && oldValue == "0" && newValue == "1" {
133+
// When transitioning from 0->1 blocks, d.Get/d.GetOk effectively reads the 'new' config value.
134+
projectVal, projectIsSet := d.GetOk("fleet.0.project")
135+
if !projectIsSet || projectVal.(string) == "" {
136+
log.Printf("[DEBUG] Suppressing diff for 'fleet.#' (0 -> 1) because fleet.0.project is null or empty in config.\n")
137+
return true
138+
}
139+
}
130140
return false
131141
})
132142
)

google-beta/services/container/resource_container_cluster_test.go

+27
Original file line numberDiff line numberDiff line change
@@ -5480,6 +5480,15 @@ func TestAccContainerCluster_withFleetConfig(t *testing.T) {
54805480
ImportStateVerify: true,
54815481
ImportStateVerifyIgnore: []string{"deletion_protection"},
54825482
},
5483+
{
5484+
Config: testAccContainerCluster_WithEmptyFleetProject(clusterName, networkName, subnetworkName),
5485+
},
5486+
{
5487+
ResourceName: "google_container_cluster.primary",
5488+
ImportState: true,
5489+
ImportStateVerify: true,
5490+
ImportStateVerifyIgnore: []string{"deletion_protection"},
5491+
},
54835492
},
54845493
})
54855494
}
@@ -5584,6 +5593,24 @@ resource "google_container_cluster" "primary" {
55845593
`, resource_name, networkName, subnetworkName)
55855594
}
55865595

5596+
func testAccContainerCluster_WithEmptyFleetProject(resource_name, networkName, subnetworkName string) string {
5597+
return fmt.Sprintf(`
5598+
resource "google_container_cluster" "primary" {
5599+
name = "%s"
5600+
location = "us-central1-a"
5601+
initial_node_count = 1
5602+
5603+
fleet {
5604+
project = ""
5605+
}
5606+
network = "%s"
5607+
subnetwork = "%s"
5608+
5609+
deletion_protection = false
5610+
}
5611+
`, resource_name, networkName, subnetworkName)
5612+
}
5613+
55875614
func testAccContainerCluster_withIncompatibleMasterVersionNodeVersion(name string) string {
55885615
return fmt.Sprintf(`
55895616
resource "google_container_cluster" "gke_cluster" {

0 commit comments

Comments
 (0)