@@ -59,6 +59,14 @@ func isRedisVersionDecreasingFunc(old, new interface{}) bool {
5959 return newVersion < oldVersion
6060}
6161
62+ // returns true if old=new or old='auto'
63+ func secondaryIpDiffSuppress (_ , old , new string , _ * schema.ResourceData ) bool {
64+ if (strings .ToLower (new ) == "auto" && old != "" ) || old == new {
65+ return true
66+ }
67+ return false
68+ }
69+
6270func resourceRedisInstance () * schema.Resource {
6371 return & schema.Resource {
6472 Create : resourceRedisInstanceCreate ,
@@ -287,7 +295,6 @@ resolution and up to nine fractional digits.`,
287295 Type : schema .TypeString ,
288296 Computed : true ,
289297 Optional : true ,
290- ForceNew : true ,
291298 ValidateFunc : validateEnum ([]string {"READ_REPLICAS_DISABLED" , "READ_REPLICAS_ENABLED" , "" }),
292299 Description : `Optional. Read replica mode. Can only be specified when trying to create the instance.
293300If not set, Memorystore Redis backend will default to READ_REPLICAS_DISABLED.
@@ -338,6 +345,16 @@ instance. If not provided, the service will choose an unused /29
338345block, for example, 10.0.0.0/29 or 192.168.0.0/29. Ranges must be
339346unique and non-overlapping with existing subnets in an authorized
340347network.` ,
348+ },
349+ "secondary_ip_range" : {
350+ Type : schema .TypeString ,
351+ Computed : true ,
352+ Optional : true ,
353+ DiffSuppressFunc : secondaryIpDiffSuppress ,
354+ Description : `Optional. Additional IP range for node placement. Required when enabling read replicas on
355+ an existing instance. For DIRECT_PEERING mode value must be a CIDR range of size /28, or
356+ "auto". For PRIVATE_SERVICE_ACCESS mode value must be the name of an allocated address
357+ range associated with the private service access connection, or "auto".` ,
341358 },
342359 "tier" : {
343360 Type : schema .TypeString ,
@@ -593,6 +610,12 @@ func resourceRedisInstanceCreate(d *schema.ResourceData, meta interface{}) error
593610 } else if v , ok := d .GetOkExists ("read_replicas_mode" ); ! isEmptyValue (reflect .ValueOf (readReplicasModeProp )) && (ok || ! reflect .DeepEqual (v , readReplicasModeProp )) {
594611 obj ["readReplicasMode" ] = readReplicasModeProp
595612 }
613+ secondaryIpRangeProp , err := expandRedisInstanceSecondaryIpRange (d .Get ("secondary_ip_range" ), d , config )
614+ if err != nil {
615+ return err
616+ } else if v , ok := d .GetOkExists ("secondary_ip_range" ); ! isEmptyValue (reflect .ValueOf (secondaryIpRangeProp )) && (ok || ! reflect .DeepEqual (v , secondaryIpRangeProp )) {
617+ obj ["secondaryIpRange" ] = secondaryIpRangeProp
618+ }
596619
597620 obj , err = resourceRedisInstanceEncoder (d , meta , obj )
598621 if err != nil {
@@ -801,6 +824,9 @@ func resourceRedisInstanceRead(d *schema.ResourceData, meta interface{}) error {
801824 if err := d .Set ("read_replicas_mode" , flattenRedisInstanceReadReplicasMode (res ["readReplicasMode" ], d , config )); err != nil {
802825 return fmt .Errorf ("Error reading Instance: %s" , err )
803826 }
827+ if err := d .Set ("secondary_ip_range" , flattenRedisInstanceSecondaryIpRange (res ["secondaryIpRange" ], d , config )); err != nil {
828+ return fmt .Errorf ("Error reading Instance: %s" , err )
829+ }
804830
805831 return nil
806832}
@@ -869,6 +895,18 @@ func resourceRedisInstanceUpdate(d *schema.ResourceData, meta interface{}) error
869895 } else if v , ok := d .GetOkExists ("replica_count" ); ! isEmptyValue (reflect .ValueOf (v )) && (ok || ! reflect .DeepEqual (v , replicaCountProp )) {
870896 obj ["replicaCount" ] = replicaCountProp
871897 }
898+ readReplicasModeProp , err := expandRedisInstanceReadReplicasMode (d .Get ("read_replicas_mode" ), d , config )
899+ if err != nil {
900+ return err
901+ } else if v , ok := d .GetOkExists ("read_replicas_mode" ); ! isEmptyValue (reflect .ValueOf (v )) && (ok || ! reflect .DeepEqual (v , readReplicasModeProp )) {
902+ obj ["readReplicasMode" ] = readReplicasModeProp
903+ }
904+ secondaryIpRangeProp , err := expandRedisInstanceSecondaryIpRange (d .Get ("secondary_ip_range" ), d , config )
905+ if err != nil {
906+ return err
907+ } else if v , ok := d .GetOkExists ("secondary_ip_range" ); ! isEmptyValue (reflect .ValueOf (v )) && (ok || ! reflect .DeepEqual (v , secondaryIpRangeProp )) {
908+ obj ["secondaryIpRange" ] = secondaryIpRangeProp
909+ }
872910
873911 obj , err = resourceRedisInstanceEncoder (d , meta , obj )
874912 if err != nil {
@@ -914,6 +952,14 @@ func resourceRedisInstanceUpdate(d *schema.ResourceData, meta interface{}) error
914952 if d .HasChange ("replica_count" ) {
915953 updateMask = append (updateMask , "replicaCount" )
916954 }
955+
956+ if d .HasChange ("read_replicas_mode" ) {
957+ updateMask = append (updateMask , "readReplicasMode" )
958+ }
959+
960+ if d .HasChange ("secondary_ip_range" ) {
961+ updateMask = append (updateMask , "secondaryIpRange" )
962+ }
917963 // updateMask is a URL parameter but not present in the schema, so replaceVars
918964 // won't set it
919965 url , err = addQueryParams (url , map [string ]string {"updateMask" : strings .Join (updateMask , "," )})
@@ -1440,6 +1486,10 @@ func flattenRedisInstanceReadReplicasMode(v interface{}, d *schema.ResourceData,
14401486 return v
14411487}
14421488
1489+ func flattenRedisInstanceSecondaryIpRange (v interface {}, d * schema.ResourceData , config * Config ) interface {} {
1490+ return v
1491+ }
1492+
14431493func expandRedisInstanceAlternativeLocationId (v interface {}, d TerraformResourceData , config * Config ) (interface {}, error ) {
14441494 return v , nil
14451495}
@@ -1724,6 +1774,10 @@ func expandRedisInstanceReadReplicasMode(v interface{}, d TerraformResourceData,
17241774 return v , nil
17251775}
17261776
1777+ func expandRedisInstanceSecondaryIpRange (v interface {}, d TerraformResourceData , config * Config ) (interface {}, error ) {
1778+ return v , nil
1779+ }
1780+
17271781func resourceRedisInstanceEncoder (d * schema.ResourceData , meta interface {}, obj map [string ]interface {}) (map [string ]interface {}, error ) {
17281782 config := meta .(* Config )
17291783 region , err := getRegionFromSchema ("region" , "location_id" , d , config )
0 commit comments