Skip to content

fix: S3 backend config detection with multiple terraform blocks #74

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

hazi
Copy link

@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

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.

1 participant