Nicer error when list/map assigned to string argument #3009
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.
For example:
Previous this would return the following sort of error:
This is the raw error returned by the underlying mapstructure library. This is not a helpful error message for anyone who doesn't know Go's type system, and it exposes Terraform's internals to the UI.
Instead, catch these cases before we try to use mapstructure and return a more straightforward message.
This also fixes a crash caused when a computed list is assigned to a string attribute. Previously this was not caught at all due to the short-circuit for computed attributes, but now we check for lists and maps before we check for computed, and so we can fail in a nicer way in this case rather than crashing during the later
Diff
operation. This is safe because a computed list is materially different than a computed primitive: it's a[]interface{}
with some of the values being interpolated strings, instead of just a single interpolated string.This issue was exposed by #2984.