-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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
core: Change string list representation so we can distinguish empty, single element lists #2504
Conversation
This is the initial pure "all tests passing without a diff" stage. The plan is to change the internal representation of StringList to include a suffix delimiter, which will allow us to recognize empty and single-element lists.
Now the only code that cares about how StringLists are represented lives inside string_list.go ...which gives us the ability to change it! :)
Had to handle a lot of implicit leaning on a few properties of the old representation: * Old representation allowed plain strings to be treated as lists without problem (i.e. shoved into strings.Split), now strings need to be checked whether they are a list before they are treated as one (i.e. shoved into StringList(s).Slice()). * Tested behavior of 0 and 1 length lists in formatlist() was a side effect of the representation. Needs to be special cased now to maintain the behavior. * Found a pretty old context test failure that was wrong in several different ways. It's covered by TestContext2Apply_multiVar so I removed it.
removes treat-lists-as-scalar special casing for formatlist /cc @radeksimko fixes #2240
} | ||
|
||
finalList = append(finalList, argument) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was implicitly relying on the fact that the old representation of StringLists allowed them to be arbitrarily combined with bare elements.
For example, previously: ["foo", "barSLDbaz", "qux"]
would make it through the strings.Join
as a valid list. Now we need to respect the encapsulation of the type and handle it explicitly.
Surprisingly simple. LGTM! |
core: Change string list representation so we can distinguish empty, single element lists
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further. |
This encapsulates and enhances the internal representation of lists within terraform's core.
To work around limitations of the current architecture, lists need to be "flattened" into a string as they're passed around the config interpolation.
Given a list
["foo", "bar", "baz"]
, the previous format for these strings was:foo(special delimiter)bar(special delimiter)baz
.This format made it impossible to distinguish between:
["foo"]
and"foo"
[]
and""
[""]
and""
Here's the new way we use the "string list delimiter" (SLD) as described in a comment: