Skip to content

Conversation

@hazi
Copy link
Contributor

@hazi hazi commented Apr 30, 2025

Issue

The generate_s3_backend_config function had a bug where it would exit the loop after finding the first terraform block with a backend configuration, ignoring any subsequent terraform blocks that might contain the actual backend configuration.

This could cause issues in configurations with multiple terraform blocks across different files, where the function might not find the correct backend configuration.

Fix

Introduced a temporary variable tmp_backend_config to properly handle multiple terraform blocks. The function now correctly finds the first valid backend configuration and stops searching after that point, ensuring it doesn't miss backend configurations in subsequent terraform blocks.

Testing

I've verified this fix works correctly with configurations that have multiple terraform blocks.

A rough test case to reproduce this issue is available in a separate branch for review. While the test code is not very clean, it demonstrates the issue and confirms the fix works as expected.

https://github.com/hazi/terraform-local/commits/reproduce_bug_in_backend_config/

https://github.com/hazi/terraform-local/blob/df3f6d0111b093a4e06a7e15e964ecea78f67a30/tests/test_apply.py#L456-L472

@bentsku bentsku self-requested a review May 21, 2025 23:54
Copy link
Contributor

@bentsku bentsku left a comment

Choose a reason for hiding this comment

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

Sorry for the delay in reviewing, but this seems like a good fix! I'll add tests in a follow-up PR in #79, I have some refactoring of the S3 backend ongoing, but wanted to welcome you to the list of contributors before that as you had the original fix!

Thanks again for the contribution 🙏

@bentsku bentsku merged commit 9ceb16e into localstack:main May 22, 2025
3 checks passed
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.

2 participants