Skip to content

Commit dbd6516

Browse files
committed
chore: adding debug logs
1 parent 0701340 commit dbd6516

File tree

2 files changed

+82
-10
lines changed

2 files changed

+82
-10
lines changed

provider/rediscloud_active_active_database_enable_default_user_test.go

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,8 +257,29 @@ func testCheckEnableDefaultUserInAPI(resourceName string, expectedGlobal bool, e
257257
}
258258

259259
if actualRegionValue != expectedRegionValue {
260-
return fmt.Errorf("API region %s enable_default_user: expected %v, got %v",
261-
regionName, expectedRegionValue, actualRegionValue)
260+
inheritStr := ""
261+
if hasExplicitOverride && expectedValue != nil {
262+
inheritStr = fmt.Sprintf(" (explicit override in config)")
263+
} else {
264+
inheritStr = fmt.Sprintf(" (should inherit from global=%v)", expectedGlobal)
265+
}
266+
267+
// Build a detailed error message showing all regions
268+
errorMsg := fmt.Sprintf("API region %s enable_default_user mismatch:\n", regionName)
269+
errorMsg += fmt.Sprintf(" Expected: %v%s\n", expectedRegionValue, inheritStr)
270+
errorMsg += fmt.Sprintf(" Actual: %v\n", actualRegionValue)
271+
errorMsg += fmt.Sprintf("\nGlobal enable_default_user: %v\n", actualGlobal)
272+
errorMsg += fmt.Sprintf("\nAll regions in API:")
273+
for _, r := range db.CrdbDatabases {
274+
rName := redis.StringValue(r.Region)
275+
rValue := "nil"
276+
if r.Security != nil && r.Security.EnableDefaultUser != nil {
277+
rValue = fmt.Sprintf("%v", redis.BoolValue(r.Security.EnableDefaultUser))
278+
}
279+
errorMsg += fmt.Sprintf("\n - %s: %s", rName, rValue)
280+
}
281+
282+
return fmt.Errorf(errorMsg)
262283
}
263284
}
264285

provider/resource_rediscloud_active_active_database.go

Lines changed: 59 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package provider
22

33
import (
44
"context"
5+
"fmt"
56
"log"
67
"regexp"
78
"strings"
@@ -681,10 +682,12 @@ func resourceRedisCloudActiveActiveDatabaseRead(ctx context.Context, d *schema.R
681682
globalEnableDefaultUser := redis.BoolValue(db.GlobalEnableDefaultUser)
682683
regionEnableDefaultUser := redis.BoolValue(regionDb.Security.EnableDefaultUser)
683684

684-
log.Printf("[DEBUG] Read enable_default_user for region %s: region=%v, global=%v", region, regionEnableDefaultUser, globalEnableDefaultUser)
685+
log.Printf("[DEBUG] ========== Read: Processing enable_default_user for region %s ==========", region)
686+
log.Printf("[DEBUG] Read: API returned - region.enable_default_user=%v, global_enable_default_user=%v", regionEnableDefaultUser, globalEnableDefaultUser)
685687

686688
// Detect operation mode to determine how to handle enable_default_user
687689
mode := detectReadOperationMode(d)
690+
log.Printf("[DEBUG] Read: Detected operation mode: %s", mode.String())
688691

689692
shouldInclude := false
690693
var reason string
@@ -693,40 +696,51 @@ func resourceRedisCloudActiveActiveDatabaseRead(ctx context.Context, d *schema.R
693696
case readModeApply:
694697
// Apply/Update mode: Check if explicitly set in config
695698
wasExplicitlySet := isEnableDefaultUserExplicitlySetInConfig(d, region)
696-
log.Printf("[DEBUG] Apply/Update mode for region %s: wasExplicitlySet=%v", region, wasExplicitlySet)
699+
log.Printf("[DEBUG] Read: Apply/Update mode for region %s", region)
700+
log.Printf("[DEBUG] Read: isEnableDefaultUserExplicitlySetInConfig returned: %v", wasExplicitlySet)
697701

698702
if wasExplicitlySet {
699703
shouldInclude = true
700704
reason = "explicitly set in config"
705+
log.Printf("[DEBUG] Read: Decision - INCLUDE field (user explicitly set it in config)")
701706
} else if regionEnableDefaultUser != globalEnableDefaultUser {
702707
shouldInclude = true
703708
reason = "differs from global (API override)"
709+
log.Printf("[DEBUG] Read: Decision - INCLUDE field (not in config but API has override: region=%v != global=%v)", regionEnableDefaultUser, globalEnableDefaultUser)
704710
} else {
705711
shouldInclude = false
706712
reason = "not in config and matches global (inherited)"
713+
log.Printf("[DEBUG] Read: Decision - EXCLUDE field (not in config, region matches global: both=%v)", regionEnableDefaultUser)
707714
}
708715

709716
case readModeRefresh, readModeImport:
710717
// Refresh/Import mode: Check if was in actual persisted state
711718
fieldWasInActualState := isEnableDefaultUserInActualPersistedState(d, region)
712-
log.Printf("[DEBUG] %s mode for region %s: fieldWasInActualState=%v", mode.String(), region, fieldWasInActualState)
719+
log.Printf("[DEBUG] Read: %s mode for region %s", mode.String(), region)
720+
log.Printf("[DEBUG] Read: isEnableDefaultUserInActualPersistedState returned: %v", fieldWasInActualState)
713721

714722
if fieldWasInActualState {
715723
shouldInclude = true
716724
reason = "was in state, preserving (user explicit)"
725+
log.Printf("[DEBUG] Read: Decision - INCLUDE field (was in persisted state, preserving user's explicit setting)")
717726
} else if regionEnableDefaultUser != globalEnableDefaultUser {
718727
shouldInclude = true
719728
reason = "not in state but differs from global (API override)"
729+
log.Printf("[DEBUG] Read: Decision - INCLUDE field (not in state but API has override: region=%v != global=%v)", regionEnableDefaultUser, globalEnableDefaultUser)
720730
} else {
721731
shouldInclude = false
722732
reason = "not in state and matches global (inherited)"
733+
log.Printf("[DEBUG] Read: Decision - EXCLUDE field (not in state, region matches global: both=%v)", regionEnableDefaultUser)
723734
}
724735
}
725736

726-
log.Printf("[DEBUG] enable_default_user decision for region %s: shouldInclude=%v, reason=%s", region, shouldInclude, reason)
737+
log.Printf("[DEBUG] Read: FINAL DECISION for region %s: shouldInclude=%v, reason=%s", region, shouldInclude, reason)
727738

728739
if shouldInclude {
729740
regionDbConfig["enable_default_user"] = regionEnableDefaultUser
741+
log.Printf("[DEBUG] Read: Field INCLUDED in state for region %s with value %v", region, regionEnableDefaultUser)
742+
} else {
743+
log.Printf("[DEBUG] Read: Field EXCLUDED from state for region %s (will be inherited from global=%v)", region, globalEnableDefaultUser)
730744
}
731745
}
732746

@@ -852,15 +866,21 @@ func resourceRedisCloudActiveActiveDatabaseUpdate(ctx context.Context, d *schema
852866
// Handle enable_default_user: Only send if explicitly set in config
853867
// With Default removed from schema, we use GetRawConfig to detect explicit setting
854868
regionName := dbRegion["name"].(string)
855-
if isEnableDefaultUserExplicitlySetInConfig(d, regionName) {
869+
explicitlySet := isEnableDefaultUserExplicitlySetInConfig(d, regionName)
870+
log.Printf("[DEBUG] Update: Region %s - isEnableDefaultUserExplicitlySetInConfig returned: %v", regionName, explicitlySet)
871+
log.Printf("[DEBUG] Update: Region %s - dbRegion map contains: %+v", regionName, dbRegion)
872+
873+
if explicitlySet {
856874
// User explicitly set it in config - send the value
857875
if val, exists := dbRegion["enable_default_user"]; exists && val != nil {
858876
regionProps.EnableDefaultUser = redis.Bool(val.(bool))
859-
log.Printf("[DEBUG] Update: Sending enable_default_user=%v for region %s (explicitly set)", val, regionName)
877+
log.Printf("[DEBUG] Update: Region %s - Sending enable_default_user=%v to API (explicitly set in config)", regionName, val)
878+
} else {
879+
log.Printf("[DEBUG] Update: Region %s - Field marked as explicit but not found in dbRegion map (exists=%v, val=%v)", regionName, exists, val)
860880
}
861881
} else {
862882
// Not explicitly set - don't send field, API will use global
863-
log.Printf("[DEBUG] Update: NOT sending enable_default_user for region %s (inherits from global)", regionName)
883+
log.Printf("[DEBUG] Update: Region %s - NOT sending enable_default_user field to API (inherits from global=%v)", regionName, d.Get("global_enable_default_user").(bool))
864884
}
865885

866886
if len(overrideAlerts) > 0 {
@@ -891,6 +911,13 @@ func resourceRedisCloudActiveActiveDatabaseUpdate(ctx context.Context, d *schema
891911

892912
regionProps.RemoteBackup = pro.BuildBackupPlan(dbRegion["remote_backup"], nil)
893913

914+
// Log final region properties being sent to API
915+
enableDefaultUserValue := "nil (not set - will inherit)"
916+
if regionProps.EnableDefaultUser != nil {
917+
enableDefaultUserValue = fmt.Sprintf("%v", *regionProps.EnableDefaultUser)
918+
}
919+
log.Printf("[DEBUG] Update: Region %s - Final regionProps.EnableDefaultUser being sent to API: %s", regionName, enableDefaultUserValue)
920+
894921
regions = append(regions, regionProps)
895922
}
896923

@@ -964,6 +991,21 @@ func resourceRedisCloudActiveActiveDatabaseUpdate(ctx context.Context, d *schema
964991
}
965992
}
966993

994+
// Log the full update request being sent to API
995+
log.Printf("[DEBUG] Update: About to call ActiveActiveUpdate API")
996+
log.Printf("[DEBUG] Update: GlobalEnableDefaultUser = %v", *update.GlobalEnableDefaultUser)
997+
for i, region := range update.Regions {
998+
regionName := ""
999+
if region.Region != nil {
1000+
regionName = *region.Region
1001+
}
1002+
enableDefaultUserValue := "nil (not set - will inherit from global)"
1003+
if region.EnableDefaultUser != nil {
1004+
enableDefaultUserValue = fmt.Sprintf("%v", *region.EnableDefaultUser)
1005+
}
1006+
log.Printf("[DEBUG] Update: Regions[%d] %s - EnableDefaultUser = %s", i, regionName, enableDefaultUserValue)
1007+
}
1008+
9671009
err = api.Client.Database.ActiveActiveUpdate(ctx, subId, dbId, update)
9681010
if err != nil {
9691011
return diag.FromErr(err)
@@ -1067,6 +1109,8 @@ func flattenModulesToNames(modules []*databases.Module) []string {
10671109
// Returns the field's cty.Value and true if found, or cty.NilVal and false if not found.
10681110
// This helper is used by both config and state detection functions.
10691111
func findRegionFieldInCtyValue(ctyVal cty.Value, regionName string, fieldName string) (cty.Value, bool) {
1112+
log.Printf("[DEBUG] findRegionFieldInCtyValue: Starting search for field '%s' in region '%s'", fieldName, regionName)
1113+
10701114
// Check if ctyVal is null or unknown
10711115
if ctyVal.IsNull() || !ctyVal.IsKnown() {
10721116
log.Printf("[DEBUG] findRegionFieldInCtyValue: cty.Value is null or unknown for region=%s field=%s", regionName, fieldName)
@@ -1138,7 +1182,14 @@ func findRegionFieldInCtyValue(ctyVal cty.Value, regionName string, fieldName st
11381182
}
11391183
}
11401184

1141-
log.Printf("[DEBUG] findRegionFieldInCtyValue: Found field %s for region %s", fieldName, regionName)
1185+
// Log the value if it's a simple type
1186+
fieldValueStr := "complex type"
1187+
if fieldAttr.Type() == cty.Bool {
1188+
fieldValueStr = fmt.Sprintf("%v", fieldAttr.True())
1189+
} else if fieldAttr.Type() == cty.String {
1190+
fieldValueStr = fmt.Sprintf("%q", fieldAttr.AsString())
1191+
}
1192+
log.Printf("[DEBUG] findRegionFieldInCtyValue: Found field %s for region %s with value: %s", fieldName, regionName, fieldValueStr)
11421193
return fieldAttr, true
11431194
}
11441195

0 commit comments

Comments
 (0)