Skip to content

Conversation

@lgallard
Copy link
Owner

@lgallard lgallard commented Jul 17, 2025

Summary

Fixes the "Cannot use a null value in for_each" error reported in issue #174.

Changes

  • Replace try() with coalesce(try(..., null), {}) pattern for all condition dynamic blocks
  • Applied to all three backup selection resources:
    • aws_backup_selection.ab_selection
    • aws_backup_selection.ab_selections
    • aws_backup_selection.plan_selections
  • Affects 12 for_each statements total (4 per resource)

Technical Details

The issue occurred when condition.value["string_equals"] (and similar keys) evaluated to null, causing Terraform's for_each to fail. The fix uses coalesce() to convert null values to empty maps {}, which for_each can handle properly.

Testing

  • ✅ Terraform validate: Success
  • ✅ Pre-commit hooks: Core validation passed
  • ✅ Example configurations: Valid
  • ✅ No breaking changes

Consistency

This change uses the same pattern already implemented elsewhere in the file (lines 104, 165), ensuring consistency across the codebase.

Fixes #174

- Replace try() with coalesce(try(..., null), {}) for all condition dynamic blocks
- Fixes "Cannot use a null value in for_each" error in issue #174
- Applied to all three backup selection resources:
  - aws_backup_selection.ab_selection
  - aws_backup_selection.ab_selections
  - aws_backup_selection.plan_selections
- Consistent with existing pattern used elsewhere in the file
- Maintains backward compatibility while improving null handling

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@lgallard
Copy link
Owner Author

bugbot run

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ BugBot reviewed your changes and found no bugs!


BugBot free trial expires on July 22, 2025
Learn more in the Cursor dashboard.

Was this report helpful? Give feedback by reacting with 👍 or 👎

@lgallard lgallard merged commit 54484af into master Jul 17, 2025
37 checks passed
@lgallard lgallard deleted the issue-174 branch July 17, 2025 09:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

selection null error

2 participants