@@ -18,6 +18,9 @@ import (
1818 "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
1919)
2020
21+ // Default RFC1918 private IP ranges used when public_endpoint_access is false
22+ var defaultPrivateIPRanges = []string {"10.0.0.0/8" , "172.16.0.0/12" , "192.168.0.0/16" , "100.64.0.0/10" }
23+
2124func ResourceRedisCloudProDatabase () * schema.Resource {
2225 return & schema.Resource {
2326 Description : "Creates database resource within a pro subscription in your Redis Enterprise Cloud Account." ,
@@ -472,7 +475,7 @@ func resourceRedisCloudProDatabaseRead(ctx context.Context, d *schema.ResourceDa
472475 return diag .FromErr (err )
473476 }
474477
475- // We are not import this resource, so we can read the subscription_id defined in this resource.
478+ // We are not importing this resource, so we can read the subscription_id defined in this resource.
476479 if subId == 0 {
477480 subId = d .Get ("subscription_id" ).(int )
478481 }
@@ -597,29 +600,9 @@ func resourceRedisCloudProDatabaseRead(ctx context.Context, d *schema.ResourceDa
597600 return diag .FromErr (err )
598601 }
599602
600- // Handle source_ips based on subscription's public_endpoint_access setting
601- // When public_endpoint_access is false and source_ips is empty, API returns private IP ranges
602- // When public_endpoint_access is true and source_ips is empty, API returns ["0.0.0.0/0"]
603- // When source_ips is explicitly set by user, API returns the user's input
604603 var sourceIPs []string
605- privateIPRanges := []string {"10.0.0.0/8" , "172.16.0.0/12" , "192.168.0.0/16" , "100.64.0.0/10" }
606-
607- // Check if the returned source_ips matches default private IP ranges (when public access is blocked)
608- isPrivateIPRange := len (db .Security .SourceIPs ) == len (privateIPRanges )
609- if isPrivateIPRange {
610- for i , ip := range db .Security .SourceIPs {
611- if redis .StringValue (ip ) != privateIPRanges [i ] {
612- isPrivateIPRange = false
613- break
614- }
615- }
616- }
617-
618- // Check if the returned source_ips is the default public access ["0.0.0.0/0"]
619- isDefaultPublicAccess := len (db .Security .SourceIPs ) == 1 && redis .StringValue (db .Security .SourceIPs [0 ]) == "0.0.0.0/0"
620-
621- // Only set source_ips if they were explicitly configured by the user (not defaults)
622- if ! isDefaultPublicAccess && ! isPrivateIPRange {
604+ if ! (len (db .Security .SourceIPs ) == 1 && redis .StringValue (db .Security .SourceIPs [0 ]) == "0.0.0.0/0" ) {
605+ // The API handles an empty list as ["0.0.0.0/0"] but need to be careful to match the input to avoid Terraform detecting drift
623606 sourceIPs = redis .StringSliceValue (db .Security .SourceIPs ... )
624607 }
625608
0 commit comments