Skip to content

Commit 1d1a50a

Browse files
Add terraform support for edgecontainer maintenance cluster's exclusion windows (#10804) (#18370)
[upstream:fe5261738873baeb94443099ccd7fdcc1e3ad1c9] Signed-off-by: Modular Magician <magic-modules@google.com>
1 parent cb0aeca commit 1d1a50a

File tree

2 files changed

+193
-0
lines changed

2 files changed

+193
-0
lines changed

google/services/edgecontainer/resource_edgecontainer_cluster.go

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,47 @@ start time.`,
405405
},
406406
},
407407
},
408+
"maintenance_exclusions": {
409+
Type: schema.TypeList,
410+
Optional: true,
411+
Description: `Exclusions to automatic maintenance. Non-emergency maintenance should not occur
412+
in these windows. Each exclusion has a unique name and may be active or expired.
413+
The max number of maintenance exclusions allowed at a given time is 3.`,
414+
Elem: &schema.Resource{
415+
Schema: map[string]*schema.Schema{
416+
"id": {
417+
Type: schema.TypeString,
418+
Computed: true,
419+
Optional: true,
420+
Description: `A unique (per cluster) id for the window.`,
421+
},
422+
"window": {
423+
Type: schema.TypeList,
424+
Computed: true,
425+
Optional: true,
426+
Description: `Represents an arbitrary window of time.`,
427+
MaxItems: 1,
428+
Elem: &schema.Resource{
429+
Schema: map[string]*schema.Schema{
430+
"end_time": {
431+
Type: schema.TypeString,
432+
Computed: true,
433+
Optional: true,
434+
Description: `The time that the window ends. The end time must take place after the
435+
start time.`,
436+
},
437+
"start_time": {
438+
Type: schema.TypeString,
439+
Computed: true,
440+
Optional: true,
441+
Description: `The time that the window first starts.`,
442+
},
443+
},
444+
},
445+
},
446+
},
447+
},
448+
},
408449
},
409450
},
410451
},
@@ -1293,6 +1334,8 @@ func flattenEdgecontainerClusterMaintenancePolicy(v interface{}, d *schema.Resou
12931334
transformed := make(map[string]interface{})
12941335
transformed["window"] =
12951336
flattenEdgecontainerClusterMaintenancePolicyWindow(original["window"], d, config)
1337+
transformed["maintenance_exclusions"] =
1338+
flattenEdgecontainerClusterMaintenancePolicyMaintenanceExclusions(original["maintenanceExclusions"], d, config)
12961339
return []interface{}{transformed}
12971340
}
12981341
func flattenEdgecontainerClusterMaintenancePolicyWindow(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
@@ -1350,6 +1393,52 @@ func flattenEdgecontainerClusterMaintenancePolicyWindowRecurringWindowRecurrence
13501393
return v
13511394
}
13521395

1396+
func flattenEdgecontainerClusterMaintenancePolicyMaintenanceExclusions(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
1397+
if v == nil {
1398+
return v
1399+
}
1400+
l := v.([]interface{})
1401+
transformed := make([]interface{}, 0, len(l))
1402+
for _, raw := range l {
1403+
original := raw.(map[string]interface{})
1404+
if len(original) < 1 {
1405+
// Do not include empty json objects coming back from the api
1406+
continue
1407+
}
1408+
transformed = append(transformed, map[string]interface{}{
1409+
"window": flattenEdgecontainerClusterMaintenancePolicyMaintenanceExclusionsWindow(original["window"], d, config),
1410+
"id": flattenEdgecontainerClusterMaintenancePolicyMaintenanceExclusionsId(original["id"], d, config),
1411+
})
1412+
}
1413+
return transformed
1414+
}
1415+
func flattenEdgecontainerClusterMaintenancePolicyMaintenanceExclusionsWindow(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
1416+
if v == nil {
1417+
return nil
1418+
}
1419+
original := v.(map[string]interface{})
1420+
if len(original) == 0 {
1421+
return nil
1422+
}
1423+
transformed := make(map[string]interface{})
1424+
transformed["start_time"] =
1425+
flattenEdgecontainerClusterMaintenancePolicyMaintenanceExclusionsWindowStartTime(original["startTime"], d, config)
1426+
transformed["end_time"] =
1427+
flattenEdgecontainerClusterMaintenancePolicyMaintenanceExclusionsWindowEndTime(original["endTime"], d, config)
1428+
return []interface{}{transformed}
1429+
}
1430+
func flattenEdgecontainerClusterMaintenancePolicyMaintenanceExclusionsWindowStartTime(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
1431+
return v
1432+
}
1433+
1434+
func flattenEdgecontainerClusterMaintenancePolicyMaintenanceExclusionsWindowEndTime(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
1435+
return v
1436+
}
1437+
1438+
func flattenEdgecontainerClusterMaintenancePolicyMaintenanceExclusionsId(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
1439+
return v
1440+
}
1441+
13531442
func flattenEdgecontainerClusterControlPlaneVersion(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
13541443
return v
13551444
}
@@ -1806,6 +1895,13 @@ func expandEdgecontainerClusterMaintenancePolicy(v interface{}, d tpgresource.Te
18061895
transformed["window"] = transformedWindow
18071896
}
18081897

1898+
transformedMaintenanceExclusions, err := expandEdgecontainerClusterMaintenancePolicyMaintenanceExclusions(original["maintenance_exclusions"], d, config)
1899+
if err != nil {
1900+
return nil, err
1901+
} else if val := reflect.ValueOf(transformedMaintenanceExclusions); val.IsValid() && !tpgresource.IsEmptyValue(val) {
1902+
transformed["maintenanceExclusions"] = transformedMaintenanceExclusions
1903+
}
1904+
18091905
return transformed, nil
18101906
}
18111907

@@ -1892,6 +1988,73 @@ func expandEdgecontainerClusterMaintenancePolicyWindowRecurringWindowRecurrence(
18921988
return v, nil
18931989
}
18941990

1991+
func expandEdgecontainerClusterMaintenancePolicyMaintenanceExclusions(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
1992+
l := v.([]interface{})
1993+
req := make([]interface{}, 0, len(l))
1994+
for _, raw := range l {
1995+
if raw == nil {
1996+
continue
1997+
}
1998+
original := raw.(map[string]interface{})
1999+
transformed := make(map[string]interface{})
2000+
2001+
transformedWindow, err := expandEdgecontainerClusterMaintenancePolicyMaintenanceExclusionsWindow(original["window"], d, config)
2002+
if err != nil {
2003+
return nil, err
2004+
} else if val := reflect.ValueOf(transformedWindow); val.IsValid() && !tpgresource.IsEmptyValue(val) {
2005+
transformed["window"] = transformedWindow
2006+
}
2007+
2008+
transformedId, err := expandEdgecontainerClusterMaintenancePolicyMaintenanceExclusionsId(original["id"], d, config)
2009+
if err != nil {
2010+
return nil, err
2011+
} else if val := reflect.ValueOf(transformedId); val.IsValid() && !tpgresource.IsEmptyValue(val) {
2012+
transformed["id"] = transformedId
2013+
}
2014+
2015+
req = append(req, transformed)
2016+
}
2017+
return req, nil
2018+
}
2019+
2020+
func expandEdgecontainerClusterMaintenancePolicyMaintenanceExclusionsWindow(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
2021+
l := v.([]interface{})
2022+
if len(l) == 0 || l[0] == nil {
2023+
return nil, nil
2024+
}
2025+
raw := l[0]
2026+
original := raw.(map[string]interface{})
2027+
transformed := make(map[string]interface{})
2028+
2029+
transformedStartTime, err := expandEdgecontainerClusterMaintenancePolicyMaintenanceExclusionsWindowStartTime(original["start_time"], d, config)
2030+
if err != nil {
2031+
return nil, err
2032+
} else if val := reflect.ValueOf(transformedStartTime); val.IsValid() && !tpgresource.IsEmptyValue(val) {
2033+
transformed["startTime"] = transformedStartTime
2034+
}
2035+
2036+
transformedEndTime, err := expandEdgecontainerClusterMaintenancePolicyMaintenanceExclusionsWindowEndTime(original["end_time"], d, config)
2037+
if err != nil {
2038+
return nil, err
2039+
} else if val := reflect.ValueOf(transformedEndTime); val.IsValid() && !tpgresource.IsEmptyValue(val) {
2040+
transformed["endTime"] = transformedEndTime
2041+
}
2042+
2043+
return transformed, nil
2044+
}
2045+
2046+
func expandEdgecontainerClusterMaintenancePolicyMaintenanceExclusionsWindowStartTime(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
2047+
return v, nil
2048+
}
2049+
2050+
func expandEdgecontainerClusterMaintenancePolicyMaintenanceExclusionsWindowEndTime(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
2051+
return v, nil
2052+
}
2053+
2054+
func expandEdgecontainerClusterMaintenancePolicyMaintenanceExclusionsId(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
2055+
return v, nil
2056+
}
2057+
18952058
func expandEdgecontainerClusterControlPlane(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
18962059
l := v.([]interface{})
18972060
if len(l) == 0 || l[0] == nil {

website/docs/r/edgecontainer_cluster.html.markdown

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,13 @@ The following arguments are supported:
307307
Specifies the maintenance window in which maintenance may be performed.
308308
Structure is [documented below](#nested_window).
309309

310+
* `maintenance_exclusions` -
311+
(Optional)
312+
Exclusions to automatic maintenance. Non-emergency maintenance should not occur
313+
in these windows. Each exclusion has a unique name and may be active or expired.
314+
The max number of maintenance exclusions allowed at a given time is 3.
315+
Structure is [documented below](#nested_maintenance_exclusions).
316+
310317

311318
<a name="nested_window"></a>The `window` block supports:
312319

@@ -330,6 +337,29 @@ The following arguments are supported:
330337
end time.
331338

332339

340+
<a name="nested_window"></a>The `window` block supports:
341+
342+
* `start_time` -
343+
(Optional)
344+
The time that the window first starts.
345+
346+
* `end_time` -
347+
(Optional)
348+
The time that the window ends. The end time must take place after the
349+
start time.
350+
351+
<a name="nested_maintenance_exclusions"></a>The `maintenance_exclusions` block supports:
352+
353+
* `window` -
354+
(Optional)
355+
Represents an arbitrary window of time.
356+
Structure is [documented below](#nested_window).
357+
358+
* `id` -
359+
(Optional)
360+
A unique (per cluster) id for the window.
361+
362+
333363
<a name="nested_window"></a>The `window` block supports:
334364

335365
* `start_time` -

0 commit comments

Comments
 (0)