Skip to content

Commit d5c62af

Browse files
committed
fix: source_ips showing erronous drift when not in same order
1 parent 7623606 commit d5c62af

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

provider/pro/resource_rediscloud_pro_database.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -623,11 +623,18 @@ func resourceRedisCloudProDatabaseRead(ctx context.Context, d *schema.ResourceDa
623623
// Check if returned source_ips matches default public access ["0.0.0.0/0"]
624624
isDefaultPublicAccess := len(db.Security.SourceIPs) == 1 && redis.StringValue(db.Security.SourceIPs[0]) == "0.0.0.0/0"
625625

626-
// Check if returned source_ips matches default RFC1918 private ranges
627-
isDefaultPrivateRanges := len(db.Security.SourceIPs) == len(defaultPrivateIPRanges)
628-
if isDefaultPrivateRanges {
629-
for i, ip := range db.Security.SourceIPs {
630-
if redis.StringValue(ip) != defaultPrivateIPRanges[i] {
626+
// Check if returned source_ips matches default RFC1918 private ranges (order-independent)
627+
isDefaultPrivateRanges := false
628+
if len(db.Security.SourceIPs) == len(defaultPrivateIPRanges) {
629+
// Create a map for O(1) lookup
630+
defaultRangesMap := make(map[string]bool)
631+
for _, cidr := range defaultPrivateIPRanges {
632+
defaultRangesMap[cidr] = true
633+
}
634+
// Check if all API-returned IPs are in the defaults map
635+
isDefaultPrivateRanges = true
636+
for _, ip := range db.Security.SourceIPs {
637+
if !defaultRangesMap[redis.StringValue(ip)] {
631638
isDefaultPrivateRanges = false
632639
break
633640
}

0 commit comments

Comments
 (0)