Skip to content

Commit

Permalink
Fix wrong initialization of maintenance_exclusion (#4372) (#8126)
Browse files Browse the repository at this point in the history
Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored Jan 6, 2021
1 parent 2ebfe91 commit 90e88fb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
3 changes: 3 additions & 0 deletions .changelog/4372.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
container: Fix crash due to nil exclusions object when updating an existent cluster with maintenance_policy but without exclusions
```
19 changes: 11 additions & 8 deletions google/resource_container_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -2358,16 +2358,19 @@ func expandMaintenancePolicy(d *schema.ResourceData, meta interface{}) *containe
}
cluster, _ := clusterGetCall.Do()
resourceVersion := ""
// If the cluster doesn't exist or if there is a read error of any kind, we will pass in an empty
// resourceVersion. If there happens to be a change to maintenance policy, we will fail at that
// point. This is a compromise between code cleanliness and a slightly worse user experience in
// an unlikely error case - we choose code cleanliness.
exclusions := make(map[string]containerBeta.TimeWindow)
if cluster != nil && cluster.MaintenancePolicy != nil {
// If the cluster doesn't exist or if there is a read error of any kind, we will pass in an empty
// resourceVersion. If there happens to be a change to maintenance policy, we will fail at that
// point. This is a compromise between code cleanliness and a slightly worse user experience in
// an unlikely error case - we choose code cleanliness.
resourceVersion = cluster.MaintenancePolicy.ResourceVersion
}
exclusions := make(map[string]containerBeta.TimeWindow)
if cluster != nil && cluster.MaintenancePolicy != nil && cluster.MaintenancePolicy.Window != nil {
exclusions = cluster.MaintenancePolicy.Window.MaintenanceExclusions

// Having a MaintenancePolicy doesn't mean that you need MaintenanceExclusions, but if they were set,
// they need to be assigned to exclusions.
if cluster.MaintenancePolicy.Window != nil && cluster.MaintenancePolicy.Window.MaintenanceExclusions != nil {
exclusions = cluster.MaintenancePolicy.Window.MaintenanceExclusions
}
}

configured := d.Get("maintenance_policy")
Expand Down

0 comments on commit 90e88fb

Please sign in to comment.