Plan renderer: Support users indexing integer paths with stringified numbers #33475
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.
Terraform allows users to specify indexes as strings as long as the string can be converted into a number. For example, the following are equivalent:
test_resource.resource.list[0].attribute
test_resource.resource.list["0"].attribute
test_resource.resource.list["0.0"].attribute
While the following would all raise validation errors.
test_resource.resource.list[0.5].attribute
test_resource.resource.list["not a number"].attribute
test_resource.resource.list["0.5"].attribute
The plan renderer currently makes an assumption that the indices will be the appropriate type. This causes a panic when attributes like those listed above are included in the relevant attributes data, as the renderer will attempt to cast them into the wrong type.
This PR updates the logic for parsing paths within the renderer so that it will attempt to convert strings into integers and panic if it can't. The panic should be okay and never triggered as Terraform will fail earlier if the index is actually invalid.
Fixes #33472
Target Release
1.5.3
Draft CHANGELOG entry
BUG FIXES