Skip to content

Commit

Permalink
fix failing remove (#5156) (#10025)
Browse files Browse the repository at this point in the history
Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
modular-magician committed Sep 7, 2021
1 parent f04afc3 commit 43e0024
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .changelog/5156.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
Container: fixed a bug in failing to remove `maintenance_exclusion` on `google_container_cluster`
```
2 changes: 1 addition & 1 deletion google/resource_container_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -2622,7 +2622,7 @@ func expandMaintenancePolicy(d *schema.ResourceData, meta interface{}) *containe
}
maintenancePolicy := l[0].(map[string]interface{})

if maintenanceExclusions, ok := maintenancePolicy["maintenance_exclusion"]; ok && len(maintenanceExclusions.(*schema.Set).List()) > 0 {
if maintenanceExclusions, ok := maintenancePolicy["maintenance_exclusion"]; ok {
for k := range exclusions {
delete(exclusions, k)
}
Expand Down
60 changes: 60 additions & 0 deletions google/resource_container_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1129,6 +1129,47 @@ func TestAccContainerCluster_withMaintenanceExclusionWindow(t *testing.T) {
})
}

func TestAccContainerCluster_deleteExclusionWindow(t *testing.T) {
t.Parallel()
cluster := fmt.Sprintf("tf-test-cluster-%s", randString(t, 10))
resourceName := "google_container_cluster.with_maintenance_exclusion_window"

vcrTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckContainerClusterDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccContainerCluster_withExclusion_DailyMaintenanceWindow(cluster, "2020-01-01T00:00:00Z", "2020-01-02T00:00:00Z"),
},
{
ResourceName: resourceName,
ImportStateIdPrefix: "us-central1-a/",
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccContainerCluster_withExclusion_RecurringMaintenanceWindow(cluster, "2019-01-01T00:00:00Z", "2019-01-02T00:00:00Z", "2019-05-01T00:00:00Z", "2019-05-02T00:00:00Z"),
},
{
ResourceName: resourceName,
ImportStateIdPrefix: "us-central1-a/",
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccContainerCluster_withExclusion_NoMaintenanceWindow(cluster, "2020-01-01T00:00:00Z", "2020-01-02T00:00:00Z"),
},
{
ResourceName: resourceName,
ImportStateIdPrefix: "us-central1-a/",
ImportState: true,
ImportStateVerify: true,
},
},
})
}

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

Expand Down Expand Up @@ -2844,6 +2885,25 @@ resource "google_container_cluster" "with_maintenance_exclusion_window" {
`, clusterName, w1startTime, w1endTime, w1startTime, w1endTime, w2startTime, w2endTime)
}

func testAccContainerCluster_withExclusion_NoMaintenanceWindow(clusterName string, w1startTime, w1endTime string) string {

return fmt.Sprintf(`
resource "google_container_cluster" "with_maintenance_exclusion_window" {
name = "%s"
location = "us-central1-a"
initial_node_count = 1
maintenance_policy {
recurring_window {
start_time = "%s"
end_time = "%s"
recurrence = "FREQ=DAILY"
}
}
}
`, clusterName, w1startTime, w1endTime)
}

func testAccContainerCluster_withExclusion_DailyMaintenanceWindow(clusterName string, w1startTime, w1endTime string) string {

return fmt.Sprintf(`
Expand Down

0 comments on commit 43e0024

Please sign in to comment.