@@ -328,6 +328,61 @@ If not set, defaults to 14 days.`,
328
328
Please refer to the field 'effective_labels' for all of the labels present on the resource.` ,
329
329
Elem : & schema.Schema {Type : schema .TypeString },
330
330
},
331
+ "maintenance_update_policy" : {
332
+ Type : schema .TypeList ,
333
+ Optional : true ,
334
+ Description : `MaintenanceUpdatePolicy defines the policy for system updates.` ,
335
+ MaxItems : 1 ,
336
+ Elem : & schema.Resource {
337
+ Schema : map [string ]* schema.Schema {
338
+ "maintenance_windows" : {
339
+ Type : schema .TypeList ,
340
+ Optional : true ,
341
+ Description : `Preferred windows to perform maintenance. Currently limited to 1.` ,
342
+ Elem : & schema.Resource {
343
+ Schema : map [string ]* schema.Schema {
344
+ "day" : {
345
+ Type : schema .TypeString ,
346
+ Required : true ,
347
+ ValidateFunc : verify .ValidateEnum ([]string {"MONDAY" , "TUESDAY" , "WEDNESDAY" , "THURSDAY" , "FRIDAY" , "SATURDAY" , "SUNDAY" }),
348
+ Description : `Preferred day of the week for maintenance, e.g. MONDAY, TUESDAY, etc. Possible values: ["MONDAY", "TUESDAY", "WEDNESDAY", "THURSDAY", "FRIDAY", "SATURDAY", "SUNDAY"]` ,
349
+ },
350
+ "start_time" : {
351
+ Type : schema .TypeList ,
352
+ Required : true ,
353
+ Description : `Preferred time to start the maintenance operation on the specified day. Maintenance will start within 1 hour of this time.` ,
354
+ MaxItems : 1 ,
355
+ Elem : & schema.Resource {
356
+ Schema : map [string ]* schema.Schema {
357
+ "hours" : {
358
+ Type : schema .TypeInt ,
359
+ Required : true ,
360
+ Description : `Hours of day in 24 hour format. Should be from 0 to 23.` ,
361
+ },
362
+ "minutes" : {
363
+ Type : schema .TypeInt ,
364
+ Optional : true ,
365
+ Description : `Minutes of hour of day. Currently, only the value 0 is supported.` ,
366
+ },
367
+ "nanos" : {
368
+ Type : schema .TypeInt ,
369
+ Optional : true ,
370
+ Description : `Fractions of seconds in nanoseconds. Currently, only the value 0 is supported.` ,
371
+ },
372
+ "seconds" : {
373
+ Type : schema .TypeInt ,
374
+ Optional : true ,
375
+ Description : `Seconds of minutes of the time. Currently, only the value 0 is supported.` ,
376
+ },
377
+ },
378
+ },
379
+ },
380
+ },
381
+ },
382
+ },
383
+ },
384
+ },
385
+ },
331
386
"network" : {
332
387
Type : schema .TypeString ,
333
388
Computed : true ,
@@ -677,6 +732,12 @@ func resourceAlloydbClusterCreate(d *schema.ResourceData, meta interface{}) erro
677
732
} else if v , ok := d .GetOkExists ("secondary_config" ); ! tpgresource .IsEmptyValue (reflect .ValueOf (secondaryConfigProp )) && (ok || ! reflect .DeepEqual (v , secondaryConfigProp )) {
678
733
obj ["secondaryConfig" ] = secondaryConfigProp
679
734
}
735
+ maintenanceUpdatePolicyProp , err := expandAlloydbClusterMaintenanceUpdatePolicy (d .Get ("maintenance_update_policy" ), d , config )
736
+ if err != nil {
737
+ return err
738
+ } else if v , ok := d .GetOkExists ("maintenance_update_policy" ); ! tpgresource .IsEmptyValue (reflect .ValueOf (maintenanceUpdatePolicyProp )) && (ok || ! reflect .DeepEqual (v , maintenanceUpdatePolicyProp )) {
739
+ obj ["maintenanceUpdatePolicy" ] = maintenanceUpdatePolicyProp
740
+ }
680
741
labelsProp , err := expandAlloydbClusterEffectiveLabels (d .Get ("effective_labels" ), d , config )
681
742
if err != nil {
682
743
return err
@@ -918,6 +979,9 @@ func resourceAlloydbClusterRead(d *schema.ResourceData, meta interface{}) error
918
979
if err := d .Set ("secondary_config" , flattenAlloydbClusterSecondaryConfig (res ["secondaryConfig" ], d , config )); err != nil {
919
980
return fmt .Errorf ("Error reading Cluster: %s" , err )
920
981
}
982
+ if err := d .Set ("maintenance_update_policy" , flattenAlloydbClusterMaintenanceUpdatePolicy (res ["maintenanceUpdatePolicy" ], d , config )); err != nil {
983
+ return fmt .Errorf ("Error reading Cluster: %s" , err )
984
+ }
921
985
if err := d .Set ("terraform_labels" , flattenAlloydbClusterTerraformLabels (res ["labels" ], d , config )); err != nil {
922
986
return fmt .Errorf ("Error reading Cluster: %s" , err )
923
987
}
@@ -1013,6 +1077,12 @@ func resourceAlloydbClusterUpdate(d *schema.ResourceData, meta interface{}) erro
1013
1077
} else if v , ok := d .GetOkExists ("secondary_config" ); ! tpgresource .IsEmptyValue (reflect .ValueOf (v )) && (ok || ! reflect .DeepEqual (v , secondaryConfigProp )) {
1014
1078
obj ["secondaryConfig" ] = secondaryConfigProp
1015
1079
}
1080
+ maintenanceUpdatePolicyProp , err := expandAlloydbClusterMaintenanceUpdatePolicy (d .Get ("maintenance_update_policy" ), d , config )
1081
+ if err != nil {
1082
+ return err
1083
+ } else if v , ok := d .GetOkExists ("maintenance_update_policy" ); ! tpgresource .IsEmptyValue (reflect .ValueOf (v )) && (ok || ! reflect .DeepEqual (v , maintenanceUpdatePolicyProp )) {
1084
+ obj ["maintenanceUpdatePolicy" ] = maintenanceUpdatePolicyProp
1085
+ }
1016
1086
labelsProp , err := expandAlloydbClusterEffectiveLabels (d .Get ("effective_labels" ), d , config )
1017
1087
if err != nil {
1018
1088
return err
@@ -1079,6 +1149,10 @@ func resourceAlloydbClusterUpdate(d *schema.ResourceData, meta interface{}) erro
1079
1149
updateMask = append (updateMask , "secondaryConfig" )
1080
1150
}
1081
1151
1152
+ if d .HasChange ("maintenance_update_policy" ) {
1153
+ updateMask = append (updateMask , "maintenanceUpdatePolicy" )
1154
+ }
1155
+
1082
1156
if d .HasChange ("effective_labels" ) {
1083
1157
updateMask = append (updateMask , "labels" )
1084
1158
}
@@ -1804,6 +1878,129 @@ func flattenAlloydbClusterSecondaryConfigPrimaryClusterName(v interface{}, d *sc
1804
1878
return v
1805
1879
}
1806
1880
1881
+ func flattenAlloydbClusterMaintenanceUpdatePolicy (v interface {}, d * schema.ResourceData , config * transport_tpg.Config ) interface {} {
1882
+ if v == nil {
1883
+ return nil
1884
+ }
1885
+ original := v .(map [string ]interface {})
1886
+ if len (original ) == 0 {
1887
+ return nil
1888
+ }
1889
+ transformed := make (map [string ]interface {})
1890
+ transformed ["maintenance_windows" ] =
1891
+ flattenAlloydbClusterMaintenanceUpdatePolicyMaintenanceWindows (original ["maintenanceWindows" ], d , config )
1892
+ return []interface {}{transformed }
1893
+ }
1894
+ func flattenAlloydbClusterMaintenanceUpdatePolicyMaintenanceWindows (v interface {}, d * schema.ResourceData , config * transport_tpg.Config ) interface {} {
1895
+ if v == nil {
1896
+ return v
1897
+ }
1898
+ l := v .([]interface {})
1899
+ transformed := make ([]interface {}, 0 , len (l ))
1900
+ for _ , raw := range l {
1901
+ original := raw .(map [string ]interface {})
1902
+ if len (original ) < 1 {
1903
+ // Do not include empty json objects coming back from the api
1904
+ continue
1905
+ }
1906
+ transformed = append (transformed , map [string ]interface {}{
1907
+ "day" : flattenAlloydbClusterMaintenanceUpdatePolicyMaintenanceWindowsDay (original ["day" ], d , config ),
1908
+ "start_time" : flattenAlloydbClusterMaintenanceUpdatePolicyMaintenanceWindowsStartTime (original ["startTime" ], d , config ),
1909
+ })
1910
+ }
1911
+ return transformed
1912
+ }
1913
+ func flattenAlloydbClusterMaintenanceUpdatePolicyMaintenanceWindowsDay (v interface {}, d * schema.ResourceData , config * transport_tpg.Config ) interface {} {
1914
+ return v
1915
+ }
1916
+
1917
+ func flattenAlloydbClusterMaintenanceUpdatePolicyMaintenanceWindowsStartTime (v interface {}, d * schema.ResourceData , config * transport_tpg.Config ) interface {} {
1918
+ if v == nil {
1919
+ return nil
1920
+ }
1921
+ original := v .(map [string ]interface {})
1922
+ if len (original ) == 0 {
1923
+ return nil
1924
+ }
1925
+ transformed := make (map [string ]interface {})
1926
+ transformed ["hours" ] =
1927
+ flattenAlloydbClusterMaintenanceUpdatePolicyMaintenanceWindowsStartTimeHours (original ["hours" ], d , config )
1928
+ transformed ["minutes" ] =
1929
+ flattenAlloydbClusterMaintenanceUpdatePolicyMaintenanceWindowsStartTimeMinutes (original ["minutes" ], d , config )
1930
+ transformed ["seconds" ] =
1931
+ flattenAlloydbClusterMaintenanceUpdatePolicyMaintenanceWindowsStartTimeSeconds (original ["seconds" ], d , config )
1932
+ transformed ["nanos" ] =
1933
+ flattenAlloydbClusterMaintenanceUpdatePolicyMaintenanceWindowsStartTimeNanos (original ["nanos" ], d , config )
1934
+ return []interface {}{transformed }
1935
+ }
1936
+ func flattenAlloydbClusterMaintenanceUpdatePolicyMaintenanceWindowsStartTimeHours (v interface {}, d * schema.ResourceData , config * transport_tpg.Config ) interface {} {
1937
+ // Handles the string fixed64 format
1938
+ if strVal , ok := v .(string ); ok {
1939
+ if intVal , err := tpgresource .StringToFixed64 (strVal ); err == nil {
1940
+ return intVal
1941
+ }
1942
+ }
1943
+
1944
+ // number values are represented as float64
1945
+ if floatVal , ok := v .(float64 ); ok {
1946
+ intVal := int (floatVal )
1947
+ return intVal
1948
+ }
1949
+
1950
+ return v // let terraform core handle it otherwise
1951
+ }
1952
+
1953
+ func flattenAlloydbClusterMaintenanceUpdatePolicyMaintenanceWindowsStartTimeMinutes (v interface {}, d * schema.ResourceData , config * transport_tpg.Config ) interface {} {
1954
+ // Handles the string fixed64 format
1955
+ if strVal , ok := v .(string ); ok {
1956
+ if intVal , err := tpgresource .StringToFixed64 (strVal ); err == nil {
1957
+ return intVal
1958
+ }
1959
+ }
1960
+
1961
+ // number values are represented as float64
1962
+ if floatVal , ok := v .(float64 ); ok {
1963
+ intVal := int (floatVal )
1964
+ return intVal
1965
+ }
1966
+
1967
+ return v // let terraform core handle it otherwise
1968
+ }
1969
+
1970
+ func flattenAlloydbClusterMaintenanceUpdatePolicyMaintenanceWindowsStartTimeSeconds (v interface {}, d * schema.ResourceData , config * transport_tpg.Config ) interface {} {
1971
+ // Handles the string fixed64 format
1972
+ if strVal , ok := v .(string ); ok {
1973
+ if intVal , err := tpgresource .StringToFixed64 (strVal ); err == nil {
1974
+ return intVal
1975
+ }
1976
+ }
1977
+
1978
+ // number values are represented as float64
1979
+ if floatVal , ok := v .(float64 ); ok {
1980
+ intVal := int (floatVal )
1981
+ return intVal
1982
+ }
1983
+
1984
+ return v // let terraform core handle it otherwise
1985
+ }
1986
+
1987
+ func flattenAlloydbClusterMaintenanceUpdatePolicyMaintenanceWindowsStartTimeNanos (v interface {}, d * schema.ResourceData , config * transport_tpg.Config ) interface {} {
1988
+ // Handles the string fixed64 format
1989
+ if strVal , ok := v .(string ); ok {
1990
+ if intVal , err := tpgresource .StringToFixed64 (strVal ); err == nil {
1991
+ return intVal
1992
+ }
1993
+ }
1994
+
1995
+ // number values are represented as float64
1996
+ if floatVal , ok := v .(float64 ); ok {
1997
+ intVal := int (floatVal )
1998
+ return intVal
1999
+ }
2000
+
2001
+ return v // let terraform core handle it otherwise
2002
+ }
2003
+
1807
2004
func flattenAlloydbClusterTerraformLabels (v interface {}, d * schema.ResourceData , config * transport_tpg.Config ) interface {} {
1808
2005
if v == nil {
1809
2006
return v
@@ -2331,6 +2528,114 @@ func expandAlloydbClusterSecondaryConfigPrimaryClusterName(v interface{}, d tpgr
2331
2528
return v , nil
2332
2529
}
2333
2530
2531
+ func expandAlloydbClusterMaintenanceUpdatePolicy (v interface {}, d tpgresource.TerraformResourceData , config * transport_tpg.Config ) (interface {}, error ) {
2532
+ l := v .([]interface {})
2533
+ if len (l ) == 0 || l [0 ] == nil {
2534
+ return nil , nil
2535
+ }
2536
+ raw := l [0 ]
2537
+ original := raw .(map [string ]interface {})
2538
+ transformed := make (map [string ]interface {})
2539
+
2540
+ transformedMaintenanceWindows , err := expandAlloydbClusterMaintenanceUpdatePolicyMaintenanceWindows (original ["maintenance_windows" ], d , config )
2541
+ if err != nil {
2542
+ return nil , err
2543
+ } else if val := reflect .ValueOf (transformedMaintenanceWindows ); val .IsValid () && ! tpgresource .IsEmptyValue (val ) {
2544
+ transformed ["maintenanceWindows" ] = transformedMaintenanceWindows
2545
+ }
2546
+
2547
+ return transformed , nil
2548
+ }
2549
+
2550
+ func expandAlloydbClusterMaintenanceUpdatePolicyMaintenanceWindows (v interface {}, d tpgresource.TerraformResourceData , config * transport_tpg.Config ) (interface {}, error ) {
2551
+ l := v .([]interface {})
2552
+ req := make ([]interface {}, 0 , len (l ))
2553
+ for _ , raw := range l {
2554
+ if raw == nil {
2555
+ continue
2556
+ }
2557
+ original := raw .(map [string ]interface {})
2558
+ transformed := make (map [string ]interface {})
2559
+
2560
+ transformedDay , err := expandAlloydbClusterMaintenanceUpdatePolicyMaintenanceWindowsDay (original ["day" ], d , config )
2561
+ if err != nil {
2562
+ return nil , err
2563
+ } else if val := reflect .ValueOf (transformedDay ); val .IsValid () && ! tpgresource .IsEmptyValue (val ) {
2564
+ transformed ["day" ] = transformedDay
2565
+ }
2566
+
2567
+ transformedStartTime , err := expandAlloydbClusterMaintenanceUpdatePolicyMaintenanceWindowsStartTime (original ["start_time" ], d , config )
2568
+ if err != nil {
2569
+ return nil , err
2570
+ } else if val := reflect .ValueOf (transformedStartTime ); val .IsValid () && ! tpgresource .IsEmptyValue (val ) {
2571
+ transformed ["startTime" ] = transformedStartTime
2572
+ }
2573
+
2574
+ req = append (req , transformed )
2575
+ }
2576
+ return req , nil
2577
+ }
2578
+
2579
+ func expandAlloydbClusterMaintenanceUpdatePolicyMaintenanceWindowsDay (v interface {}, d tpgresource.TerraformResourceData , config * transport_tpg.Config ) (interface {}, error ) {
2580
+ return v , nil
2581
+ }
2582
+
2583
+ func expandAlloydbClusterMaintenanceUpdatePolicyMaintenanceWindowsStartTime (v interface {}, d tpgresource.TerraformResourceData , config * transport_tpg.Config ) (interface {}, error ) {
2584
+ l := v .([]interface {})
2585
+ if len (l ) == 0 || l [0 ] == nil {
2586
+ return nil , nil
2587
+ }
2588
+ raw := l [0 ]
2589
+ original := raw .(map [string ]interface {})
2590
+ transformed := make (map [string ]interface {})
2591
+
2592
+ transformedHours , err := expandAlloydbClusterMaintenanceUpdatePolicyMaintenanceWindowsStartTimeHours (original ["hours" ], d , config )
2593
+ if err != nil {
2594
+ return nil , err
2595
+ } else if val := reflect .ValueOf (transformedHours ); val .IsValid () && ! tpgresource .IsEmptyValue (val ) {
2596
+ transformed ["hours" ] = transformedHours
2597
+ }
2598
+
2599
+ transformedMinutes , err := expandAlloydbClusterMaintenanceUpdatePolicyMaintenanceWindowsStartTimeMinutes (original ["minutes" ], d , config )
2600
+ if err != nil {
2601
+ return nil , err
2602
+ } else if val := reflect .ValueOf (transformedMinutes ); val .IsValid () && ! tpgresource .IsEmptyValue (val ) {
2603
+ transformed ["minutes" ] = transformedMinutes
2604
+ }
2605
+
2606
+ transformedSeconds , err := expandAlloydbClusterMaintenanceUpdatePolicyMaintenanceWindowsStartTimeSeconds (original ["seconds" ], d , config )
2607
+ if err != nil {
2608
+ return nil , err
2609
+ } else if val := reflect .ValueOf (transformedSeconds ); val .IsValid () && ! tpgresource .IsEmptyValue (val ) {
2610
+ transformed ["seconds" ] = transformedSeconds
2611
+ }
2612
+
2613
+ transformedNanos , err := expandAlloydbClusterMaintenanceUpdatePolicyMaintenanceWindowsStartTimeNanos (original ["nanos" ], d , config )
2614
+ if err != nil {
2615
+ return nil , err
2616
+ } else if val := reflect .ValueOf (transformedNanos ); val .IsValid () && ! tpgresource .IsEmptyValue (val ) {
2617
+ transformed ["nanos" ] = transformedNanos
2618
+ }
2619
+
2620
+ return transformed , nil
2621
+ }
2622
+
2623
+ func expandAlloydbClusterMaintenanceUpdatePolicyMaintenanceWindowsStartTimeHours (v interface {}, d tpgresource.TerraformResourceData , config * transport_tpg.Config ) (interface {}, error ) {
2624
+ return v , nil
2625
+ }
2626
+
2627
+ func expandAlloydbClusterMaintenanceUpdatePolicyMaintenanceWindowsStartTimeMinutes (v interface {}, d tpgresource.TerraformResourceData , config * transport_tpg.Config ) (interface {}, error ) {
2628
+ return v , nil
2629
+ }
2630
+
2631
+ func expandAlloydbClusterMaintenanceUpdatePolicyMaintenanceWindowsStartTimeSeconds (v interface {}, d tpgresource.TerraformResourceData , config * transport_tpg.Config ) (interface {}, error ) {
2632
+ return v , nil
2633
+ }
2634
+
2635
+ func expandAlloydbClusterMaintenanceUpdatePolicyMaintenanceWindowsStartTimeNanos (v interface {}, d tpgresource.TerraformResourceData , config * transport_tpg.Config ) (interface {}, error ) {
2636
+ return v , nil
2637
+ }
2638
+
2334
2639
func expandAlloydbClusterEffectiveLabels (v interface {}, d tpgresource.TerraformResourceData , config * transport_tpg.Config ) (map [string ]string , error ) {
2335
2640
if v == nil {
2336
2641
return map [string ]string {}, nil
0 commit comments