@@ -298,16 +298,67 @@ resolution and up to nine fractional digits.`,
298
298
},
299
299
},
300
300
},
301
+ "persistence_config" : {
302
+ Type : schema .TypeList ,
303
+ Computed : true ,
304
+ Optional : true ,
305
+ Description : `Maintenance policy for an instance.` ,
306
+ MaxItems : 1 ,
307
+ Elem : & schema.Resource {
308
+ Schema : map [string ]* schema.Schema {
309
+ "persistence_mode" : {
310
+ Type : schema .TypeString ,
311
+ Computed : true ,
312
+ Optional : true ,
313
+ ValidateFunc : validateEnum ([]string {"DISABLED" , "RDB" }),
314
+ Description : `Optional. Controls whether Persistence features are enabled. If not provided, the existing value will be used.
315
+
316
+ - DISABLED: Persistence is disabled for the instance, and any existing snapshots are deleted.
317
+ - RDB: RDB based Persistence is enabled. Possible values: ["DISABLED", "RDB"]` ,
318
+ },
319
+ "rdb_snapshot_period" : {
320
+ Type : schema .TypeString ,
321
+ Required : true ,
322
+ ValidateFunc : validateEnum ([]string {"ONE_HOUR" , "SIX_HOURS" , "TWELVE_HOURS" , "TWENTY_FOUR_HOURS" }),
323
+ Description : `Optional. Available snapshot periods for scheduling.
324
+
325
+ - ONE_HOUR: Snapshot every 1 hour.
326
+ - SIX_HOURS: Snapshot every 6 hours.
327
+ - TWELVE_HOURS: Snapshot every 12 hours.
328
+ - TWENTY_FOUR_HOURS: Snapshot every 24 horus. Possible values: ["ONE_HOUR", "SIX_HOURS", "TWELVE_HOURS", "TWENTY_FOUR_HOURS"]` ,
329
+ },
330
+ "rdb_snapshot_start_time" : {
331
+ Type : schema .TypeString ,
332
+ Computed : true ,
333
+ Optional : true ,
334
+ Description : `Optional. Date and time that the first snapshot was/will be attempted,
335
+ and to which future snapshots will be aligned. If not provided,
336
+ the current time will be used.
337
+ A timestamp in RFC3339 UTC "Zulu" format, with nanosecond resolution
338
+ and up to nine fractional digits.
339
+ Examples: "2014-10-02T15:01:23Z" and "2014-10-02T15:01:23.045123456Z".` ,
340
+ },
341
+ "rdb_next_snapshot_time" : {
342
+ Type : schema .TypeString ,
343
+ Computed : true ,
344
+ Description : `Output only. The next time that a snapshot attempt is scheduled to occur.
345
+ A timestamp in RFC3339 UTC "Zulu" format, with nanosecond resolution and up
346
+ to nine fractional digits.
347
+ Examples: "2014-10-02T15:01:23Z" and "2014-10-02T15:01:23.045123456Z".` ,
348
+ },
349
+ },
350
+ },
351
+ },
301
352
"read_replicas_mode" : {
302
353
Type : schema .TypeString ,
303
354
Computed : true ,
304
355
Optional : true ,
305
356
ValidateFunc : validateEnum ([]string {"READ_REPLICAS_DISABLED" , "READ_REPLICAS_ENABLED" , "" }),
306
357
Description : `Optional. Read replica mode. Can only be specified when trying to create the instance.
307
358
If not set, Memorystore Redis backend will default to READ_REPLICAS_DISABLED.
308
- - READ_REPLICAS_DISABLED: If disabled, read endpoint will not be provided and the
359
+ - READ_REPLICAS_DISABLED: If disabled, read endpoint will not be provided and the
309
360
instance cannot scale up or down the number of replicas.
310
- - READ_REPLICAS_ENABLED: If enabled, read endpoint will be provided and the instance
361
+ - READ_REPLICAS_ENABLED: If enabled, read endpoint will be provided and the instance
311
362
can scale up and down the number of replicas. Possible values: ["READ_REPLICAS_DISABLED", "READ_REPLICAS_ENABLED"]` ,
312
363
},
313
364
"redis_configs" : {
@@ -323,7 +374,7 @@ https://cloud.google.com/memorystore/docs/redis/reference/rest/v1/projects.locat
323
374
Computed : true ,
324
375
Optional : true ,
325
376
Description : `The version of Redis software. If not provided, latest supported
326
- version will be used. Please check the API documentation linked
377
+ version will be used. Please check the API documentation linked
327
378
at the top for the latest valid values.` ,
328
379
},
329
380
"region" : {
@@ -337,9 +388,9 @@ at the top for the latest valid values.`,
337
388
Type : schema .TypeInt ,
338
389
Computed : true ,
339
390
Optional : true ,
340
- Description : `Optional. The number of replica nodes. The valid range for the Standard Tier with
391
+ Description : `Optional. The number of replica nodes. The valid range for the Standard Tier with
341
392
read replicas enabled is [1-5] and defaults to 2. If read replicas are not enabled
342
- for a Standard Tier instance, the only valid value is 1 and the default is 1.
393
+ for a Standard Tier instance, the only valid value is 1 and the default is 1.
343
394
The valid value for basic tier is 0 and the default is also 0.` ,
344
395
},
345
396
"reserved_ip_range" : {
@@ -360,7 +411,7 @@ network.`,
360
411
DiffSuppressFunc : secondaryIpDiffSuppress ,
361
412
Description : `Optional. Additional IP range for node placement. Required when enabling read replicas on
362
413
an existing instance. For DIRECT_PEERING mode value must be a CIDR range of size /28, or
363
- "auto". For PRIVATE_SERVICE_ACCESS mode value must be the name of an allocated address
414
+ "auto". For PRIVATE_SERVICE_ACCESS mode value must be the name of an allocated address
364
415
range associated with the private service access connection, or "auto".` ,
365
416
},
366
417
"tier" : {
@@ -447,7 +498,7 @@ will exhibit some lag behind the primary. Write requests must target 'host'.`,
447
498
"read_endpoint_port" : {
448
499
Type : schema .TypeInt ,
449
500
Computed : true ,
450
- Description : `Output only. The port number of the exposed readonly redis endpoint. Standard tier only.
501
+ Description : `Output only. The port number of the exposed readonly redis endpoint. Standard tier only.
451
502
Write requests should target 'port'.` ,
452
503
},
453
504
"server_ca_certs" : {
@@ -563,6 +614,12 @@ func resourceRedisInstanceCreate(d *schema.ResourceData, meta interface{}) error
563
614
} else if v , ok := d .GetOkExists ("name" ); ! isEmptyValue (reflect .ValueOf (nameProp )) && (ok || ! reflect .DeepEqual (v , nameProp )) {
564
615
obj ["name" ] = nameProp
565
616
}
617
+ persistenceConfigProp , err := expandRedisInstancePersistenceConfig (d .Get ("persistence_config" ), d , config )
618
+ if err != nil {
619
+ return err
620
+ } else if v , ok := d .GetOkExists ("persistence_config" ); ! isEmptyValue (reflect .ValueOf (persistenceConfigProp )) && (ok || ! reflect .DeepEqual (v , persistenceConfigProp )) {
621
+ obj ["persistenceConfig" ] = persistenceConfigProp
622
+ }
566
623
maintenancePolicyProp , err := expandRedisInstanceMaintenancePolicy (d .Get ("maintenance_policy" ), d , config )
567
624
if err != nil {
568
625
return err
@@ -792,6 +849,9 @@ func resourceRedisInstanceRead(d *schema.ResourceData, meta interface{}) error {
792
849
if err := d .Set ("name" , flattenRedisInstanceName (res ["name" ], d , config )); err != nil {
793
850
return fmt .Errorf ("Error reading Instance: %s" , err )
794
851
}
852
+ if err := d .Set ("persistence_config" , flattenRedisInstancePersistenceConfig (res ["persistenceConfig" ], d , config )); err != nil {
853
+ return fmt .Errorf ("Error reading Instance: %s" , err )
854
+ }
795
855
if err := d .Set ("maintenance_policy" , flattenRedisInstanceMaintenancePolicy (res ["maintenancePolicy" ], d , config )); err != nil {
796
856
return fmt .Errorf ("Error reading Instance: %s" , err )
797
857
}
@@ -887,6 +947,12 @@ func resourceRedisInstanceUpdate(d *schema.ResourceData, meta interface{}) error
887
947
} else if v , ok := d .GetOkExists ("redis_configs" ); ! isEmptyValue (reflect .ValueOf (v )) && (ok || ! reflect .DeepEqual (v , redisConfigsProp )) {
888
948
obj ["redisConfigs" ] = redisConfigsProp
889
949
}
950
+ persistenceConfigProp , err := expandRedisInstancePersistenceConfig (d .Get ("persistence_config" ), d , config )
951
+ if err != nil {
952
+ return err
953
+ } else if v , ok := d .GetOkExists ("persistence_config" ); ! isEmptyValue (reflect .ValueOf (v )) && (ok || ! reflect .DeepEqual (v , persistenceConfigProp )) {
954
+ obj ["persistenceConfig" ] = persistenceConfigProp
955
+ }
890
956
maintenancePolicyProp , err := expandRedisInstanceMaintenancePolicy (d .Get ("maintenance_policy" ), d , config )
891
957
if err != nil {
892
958
return err
@@ -953,6 +1019,10 @@ func resourceRedisInstanceUpdate(d *schema.ResourceData, meta interface{}) error
953
1019
updateMask = append (updateMask , "redisConfigs" )
954
1020
}
955
1021
1022
+ if d .HasChange ("persistence_config" ) {
1023
+ updateMask = append (updateMask , "persistenceConfig" )
1024
+ }
1025
+
956
1026
if d .HasChange ("maintenance_policy" ) {
957
1027
updateMask = append (updateMask , "maintenancePolicy" )
958
1028
}
@@ -1165,6 +1235,41 @@ func flattenRedisInstanceName(v interface{}, d *schema.ResourceData, config *Con
1165
1235
return NameFromSelfLinkStateFunc (v )
1166
1236
}
1167
1237
1238
+ func flattenRedisInstancePersistenceConfig (v interface {}, d * schema.ResourceData , config * Config ) interface {} {
1239
+ if v == nil {
1240
+ return nil
1241
+ }
1242
+ original := v .(map [string ]interface {})
1243
+ if len (original ) == 0 {
1244
+ return nil
1245
+ }
1246
+ transformed := make (map [string ]interface {})
1247
+ transformed ["persistence_mode" ] =
1248
+ flattenRedisInstancePersistenceConfigPersistenceMode (original ["persistenceMode" ], d , config )
1249
+ transformed ["rdb_snapshot_period" ] =
1250
+ flattenRedisInstancePersistenceConfigRdbSnapshotPeriod (original ["rdbSnapshotPeriod" ], d , config )
1251
+ transformed ["rdb_next_snapshot_time" ] =
1252
+ flattenRedisInstancePersistenceConfigRdbNextSnapshotTime (original ["rdbNextSnapshotTime" ], d , config )
1253
+ transformed ["rdb_snapshot_start_time" ] =
1254
+ flattenRedisInstancePersistenceConfigRdbSnapshotStartTime (original ["rdbSnapshotStartTime" ], d , config )
1255
+ return []interface {}{transformed }
1256
+ }
1257
+ func flattenRedisInstancePersistenceConfigPersistenceMode (v interface {}, d * schema.ResourceData , config * Config ) interface {} {
1258
+ return v
1259
+ }
1260
+
1261
+ func flattenRedisInstancePersistenceConfigRdbSnapshotPeriod (v interface {}, d * schema.ResourceData , config * Config ) interface {} {
1262
+ return v
1263
+ }
1264
+
1265
+ func flattenRedisInstancePersistenceConfigRdbNextSnapshotTime (v interface {}, d * schema.ResourceData , config * Config ) interface {} {
1266
+ return v
1267
+ }
1268
+
1269
+ func flattenRedisInstancePersistenceConfigRdbSnapshotStartTime (v interface {}, d * schema.ResourceData , config * Config ) interface {} {
1270
+ return v
1271
+ }
1272
+
1168
1273
func flattenRedisInstanceMaintenancePolicy (v interface {}, d * schema.ResourceData , config * Config ) interface {} {
1169
1274
if v == nil {
1170
1275
return nil
@@ -1564,6 +1669,62 @@ func expandRedisInstanceName(v interface{}, d TerraformResourceData, config *Con
1564
1669
return replaceVars (d , config , "projects/{{project}}/locations/{{region}}/instances/{{name}}" )
1565
1670
}
1566
1671
1672
+ func expandRedisInstancePersistenceConfig (v interface {}, d TerraformResourceData , config * Config ) (interface {}, error ) {
1673
+ l := v .([]interface {})
1674
+ if len (l ) == 0 || l [0 ] == nil {
1675
+ return nil , nil
1676
+ }
1677
+ raw := l [0 ]
1678
+ original := raw .(map [string ]interface {})
1679
+ transformed := make (map [string ]interface {})
1680
+
1681
+ transformedPersistenceMode , err := expandRedisInstancePersistenceConfigPersistenceMode (original ["persistence_mode" ], d , config )
1682
+ if err != nil {
1683
+ return nil , err
1684
+ } else if val := reflect .ValueOf (transformedPersistenceMode ); val .IsValid () && ! isEmptyValue (val ) {
1685
+ transformed ["persistenceMode" ] = transformedPersistenceMode
1686
+ }
1687
+
1688
+ transformedRdbSnapshotPeriod , err := expandRedisInstancePersistenceConfigRdbSnapshotPeriod (original ["rdb_snapshot_period" ], d , config )
1689
+ if err != nil {
1690
+ return nil , err
1691
+ } else if val := reflect .ValueOf (transformedRdbSnapshotPeriod ); val .IsValid () && ! isEmptyValue (val ) {
1692
+ transformed ["rdbSnapshotPeriod" ] = transformedRdbSnapshotPeriod
1693
+ }
1694
+
1695
+ transformedRdbNextSnapshotTime , err := expandRedisInstancePersistenceConfigRdbNextSnapshotTime (original ["rdb_next_snapshot_time" ], d , config )
1696
+ if err != nil {
1697
+ return nil , err
1698
+ } else if val := reflect .ValueOf (transformedRdbNextSnapshotTime ); val .IsValid () && ! isEmptyValue (val ) {
1699
+ transformed ["rdbNextSnapshotTime" ] = transformedRdbNextSnapshotTime
1700
+ }
1701
+
1702
+ transformedRdbSnapshotStartTime , err := expandRedisInstancePersistenceConfigRdbSnapshotStartTime (original ["rdb_snapshot_start_time" ], d , config )
1703
+ if err != nil {
1704
+ return nil , err
1705
+ } else if val := reflect .ValueOf (transformedRdbSnapshotStartTime ); val .IsValid () && ! isEmptyValue (val ) {
1706
+ transformed ["rdbSnapshotStartTime" ] = transformedRdbSnapshotStartTime
1707
+ }
1708
+
1709
+ return transformed , nil
1710
+ }
1711
+
1712
+ func expandRedisInstancePersistenceConfigPersistenceMode (v interface {}, d TerraformResourceData , config * Config ) (interface {}, error ) {
1713
+ return v , nil
1714
+ }
1715
+
1716
+ func expandRedisInstancePersistenceConfigRdbSnapshotPeriod (v interface {}, d TerraformResourceData , config * Config ) (interface {}, error ) {
1717
+ return v , nil
1718
+ }
1719
+
1720
+ func expandRedisInstancePersistenceConfigRdbNextSnapshotTime (v interface {}, d TerraformResourceData , config * Config ) (interface {}, error ) {
1721
+ return v , nil
1722
+ }
1723
+
1724
+ func expandRedisInstancePersistenceConfigRdbSnapshotStartTime (v interface {}, d TerraformResourceData , config * Config ) (interface {}, error ) {
1725
+ return v , nil
1726
+ }
1727
+
1567
1728
func expandRedisInstanceMaintenancePolicy (v interface {}, d TerraformResourceData , config * Config ) (interface {}, error ) {
1568
1729
l := v .([]interface {})
1569
1730
if len (l ) == 0 || l [0 ] == nil {
0 commit comments