Skip to content

Commit 9ffa8ca

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

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

google/services/container/resource_container_cluster.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,20 @@ var (
121121
})
122122

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

google/services/container/resource_container_cluster_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5079,6 +5079,15 @@ func TestAccContainerCluster_withFleetConfig(t *testing.T) {
50795079
ImportStateVerify: true,
50805080
ImportStateVerifyIgnore: []string{"deletion_protection"},
50815081
},
5082+
{
5083+
Config: testAccContainerCluster_WithEmptyFleetProject(clusterName, networkName, subnetworkName),
5084+
},
5085+
{
5086+
ResourceName: "google_container_cluster.primary",
5087+
ImportState: true,
5088+
ImportStateVerify: true,
5089+
ImportStateVerifyIgnore: []string{"deletion_protection"},
5090+
},
50825091
},
50835092
})
50845093
}
@@ -5117,6 +5126,24 @@ resource "google_container_cluster" "primary" {
51175126
`, resource_name, networkName, subnetworkName)
51185127
}
51195128

5129+
func testAccContainerCluster_WithEmptyFleetProject(resource_name, networkName, subnetworkName string) string {
5130+
return fmt.Sprintf(`
5131+
resource "google_container_cluster" "primary" {
5132+
name = "%s"
5133+
location = "us-central1-a"
5134+
initial_node_count = 1
5135+
5136+
fleet {
5137+
project = ""
5138+
}
5139+
network = "%s"
5140+
subnetwork = "%s"
5141+
5142+
deletion_protection = false
5143+
}
5144+
`, resource_name, networkName, subnetworkName)
5145+
}
5146+
51205147
func testAccContainerCluster_withIncompatibleMasterVersionNodeVersion(name string) string {
51215148
return fmt.Sprintf(`
51225149
resource "google_container_cluster" "gke_cluster" {

0 commit comments

Comments
 (0)