Add support for Terraform 1.x+ while maintaining backward compatibility #155
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR adds support for modern Terraform versions (1.x+) to terraform-landscape while maintaining full backward compatibility with Terraform 0.11.x.
Problem
As noted in issue #101, terraform-landscape was designed for Terraform 0.11.x and fails to parse the output from modern Terraform versions due to significant changes in the plan output format.
Key differences in modern Terraform output:
# resource.name will be created
resource "type" "name" { ... }
Solution
This PR enhances the printer module to automatically detect the Terraform version based on output format and apply the appropriate parsing strategy:
Changes Made
lib/terraform_landscape/printer.rb
process_string
method (no separate functions)grammar/terraform_plan.treetop
Testing
Tested with various Terraform operations:
Example Output
Before (raw Terraform 1.x output):
After (terraform-landscape formatted):
Compatibility
Future Considerations
This implementation focuses on supporting the most common Terraform output patterns. Edge cases or provider-specific output formats may require additional enhancements.
References