Skip to content

Conversation

@lgallard
Copy link
Owner

@lgallard lgallard commented Jul 16, 2025

Summary

  • Fix conditions variable type from optional(map(any)) to proper nested object structure
  • Update selection_by_conditions example to use conditions instead of selection_tags
  • Add comprehensive test case for conditions variable validation
  • Resolves issue Backup selection using ListOfTags instead of Conditions #169 where conditions caused "attribute types must all match" error

⚠️ Breaking Changes

Type Definition Changes

This PR updates the type definition for all conditions variables from map(any) to a structured object type for better type safety and AWS API compliance.

Variables affected:

  • plans.selections.conditions
  • selection_conditions
  • backup_selections.conditions

Before:

conditions = optional(map(any))

After:

conditions = optional(object({
  string_equals     = optional(map(string))
  string_not_equals = optional(map(string))
  string_like       = optional(map(string))
  string_not_like   = optional(map(string))
}))

Migration Impact

✅ Most users need no changes - If you were using conditions successfully, your code should continue working unchanged.

✅ Fixes broken use cases - Users experiencing "attribute types must all match" errors will now have working code.

⚠️ Potential impact - If you were using conditions in non-standard ways, you may need to update to the structured format.

Migration Example

If you have existing conditions code like:

selections = {
  my_selection = {
    conditions = {
      string_equals = {
        "aws:ResourceTag/Environment" = "prod"
        "aws:ResourceTag/Service"     = "web"
      }
    }
  }
}

No changes needed - this will continue to work.

Changes Made

1. Fixed Variable Type Definition (variables.tf)

Updated all conditions variables to use consistent structured object types that match the AWS Backup API specification.

2. Updated Example (examples/selection_by_conditions/main.tf)

Changed from using selection_tags to properly demonstrating conditions:

selections = {
  selection_by_conditions = {
    conditions = {
      string_equals = {
        "aws:ResourceTag/Environment" = "prod"
        "aws:ResourceTag/Service"     = "web"
      }
    }
  }
}

3. Added Comprehensive Tests

  • Created /test/fixtures/terraform/conditions/ test fixture
  • Added TestConditionsVariableTypes test case
  • Validates that the new structure works without type errors

Problem Solved

Before: Users trying to use conditions would get:

Error: attribute types must all match for conversion to map

After: Users can now use the conditions structure as intended:

selections = {
  selection_tests = {
    conditions = {
      string_equals = {
        "aws:ResourceTag/AutomatedAWSBackup" = "true"
      }
    }
  }
}

Benefits

  • Eliminates type errors - Fixes "attribute types must all match" errors
  • Better type safety - Catches invalid configurations at plan time
  • AWS API compliance - Type structure matches AWS Backup API specification
  • Consistent interface - All conditions variables use the same type definition
  • Better documentation - Clear specification of supported condition types

Test Plan

  • Terraform validate passes on all changes
  • Example updated to demonstrate proper conditions usage
  • New test case validates conditions structure works
  • User's exact example from issue Backup selection using ListOfTags instead of Conditions #169 now works
  • All existing examples continue to validate successfully

Closes

Closes #169

lgallard and others added 2 commits July 16, 2025 15:40
- Fix conditions variable type from optional(map(any)) to proper nested object structure
- Update selection_by_conditions example to use conditions instead of selection_tags
- Add comprehensive test case for conditions variable validation
- Resolves issue #169 where conditions caused "attribute types must all match" error

The conditions variable now properly supports the AWS Backup API structure:
- string_equals: map of key-value pairs for exact matches
- string_not_equals: map of key-value pairs for exclusions
- string_like: map of key-value pairs for pattern matching
- string_not_like: map of key-value pairs for pattern exclusions

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

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

bugbot run

cursor[bot]

This comment was marked as outdated.

- Update selection_conditions variable to use structured object type
- Update backup_selections.conditions to use structured object type
- Ensures consistent type definition across all conditions variables
- Addresses PR review feedback about type inconsistency
@lgallard
Copy link
Owner Author

Thanks for the great feedback! 🎯

I've addressed the type inconsistency by updating all conditions variables to use the same structured object type:

Changes Made

1. ✅ Fixed variable

  • Before:
  • After: Structured object with , , ,

2. ✅ Fixed variable

  • Before:
  • After: Same structured object type

3. ✅ Already fixed

  • Before:
  • After: Same structured object type

Result

Now all three conditions variables use the exact same type definition, providing:

  • Consistent interface across the entire module
  • Better type safety and validation
  • No more "attribute types must all match" errors
  • Clearer documentation of what conditions are supported

The changes maintain backward compatibility while providing much better user experience and type safety.

@lgallard
Copy link
Owner Author

bugbot run

cursor[bot]

This comment was marked as outdated.

@lgallard
Copy link
Owner Author

📝 Breaking Change Documentation Added

I've updated the PR description to properly document this as a breaking change with:

🔍 What's documented:

  • ⚠️ Clear "Breaking Changes" section
  • 📋 All affected variables listed
  • 🔄 Before/after type definitions
  • 📖 Migration guidance for users
  • ✅ Examples showing what needs to change (spoiler: most users need no changes)

🎯 Key points for users:

  • Most users: No migration needed - existing code continues to work
  • Affected users: Those experiencing the original "attribute types must all match" error now have working code
  • Rare edge cases: Users who somehow used conditions in non-standard ways may need to update

📚 Documentation follows project patterns:

  • Matches format used in existing CHANGELOG.md and MIGRATION.md
  • Clear migration examples
  • Emphasizes that this "fixes more than it breaks"

This ensures users understand the change and can migrate smoothly if needed!

Repository owner deleted a comment from cursor bot Jul 16, 2025
@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!


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

@lgallard lgallard merged commit d83a5cf into master Jul 16, 2025
37 checks passed
@lgallard lgallard deleted the fix/conditions-variable-type-error branch July 16, 2025 17:12
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.

Backup selection using ListOfTags instead of Conditions

2 participants