-
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
config: compact interpolate function #3239
config: compact interpolate function #3239
Conversation
@@ -74,3 +74,16 @@ func (sl StringList) String() string { | |||
func IsStringList(s string) bool { | |||
return strings.Contains(s, stringListDelim) | |||
} | |||
|
|||
func CompactStringList(sl StringList) StringList { |
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.
If you write this signature as func (sl Stringlist) Compact() StringList
then it can be callable as a method, like stringList.Compact()
. Looks like the other StringList
functions further up in this file were defined in this way, so I think it'd be nice for consistency.
(Also looks like those StringList
methods are sorted in alphabetical order, so maybe push this up to its rightful spot in that ordering.)
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.
Thanks, fixed that. The functions in interpolate_funcs.go
were also ordered alphabetically, I had not noticed - fixed that too.
Looks good to me! Thanks! I just noted one minor style thing inline. |
@apparentlymart fixed those things; still no idea why the end result isn't what I expected (i.e. 0 load balancers in that example). Something is still making |
Sorry I didn't look more closely at your cover message when I read this the first time, and missed your question. Nothing obvious is jumping out at me right now but if nobody else figures it out first I'll try to debug a bit later in the week and see where that extra empty item is coming from. |
The compact() function removes empty strings if the list has more than one string. If the list has a single empty string, it does not return an empty list. I think this is because StringList cannot represent empty lists. See #3437 |
@elblivion After applying #3438, I get an empty list output length {
value = "${length(compact(split(",", "")))}"
}
|
01b0168
to
aed3f98
Compare
@svend awesome! But when I merged your change it broke the tests :-/ I notice the Travis build for your PR also failed, how did you get it to compile? |
@radeksimko please take another look. I've removed one failing test which you introduced in #2157 about a splat with two zero-length lists, this now fails because of the change in the StringList Slice function but I don't know enough about what it's doing to fix it. :-( I've incorporated the changes from @svend's PR #3438.
|
This is still not working anyway for my use case of passing an empty list of load_balancers to my AWS ASG module. So it's something else, e.g. what I said here #3239 (comment). 😞 |
Actually it does, I was testing it wrong! 🎉 This is good to go from my side /cc @radeksimko @apparentlymart - hopefully could still make it into 0.6.4. :-) |
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. |
Hi,
After reading #2973 and #2710 I decided to try my hand at writing a
compact()
function to return a StringList devoid of empty strings. This seems to work and passes the unit tests I wrote (caveat: total Go and unit testing n00b), yet when I try to use it on my real world caseterraform plan
still thinks it has to add aload_balancers
field with an empty string:Module config:
main config:
Output of terraform plan: