Skip to content
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

Add list-remove module #14

Merged
merged 2 commits into from Apr 19, 2019
Merged

Add list-remove module #14

merged 2 commits into from Apr 19, 2019

Conversation

yorinasub17
Copy link
Contributor

This implements a list-remove module, which can be used to do list subtraction. In other words, this is a module to be able to remove specific items from a list in terraform.

Note: This was inspired from a conversation with a customer in slack.

Copy link
Member

@brikis98 brikis98 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Handy module!

# b) distinct will discard duplicate items in the order they are found
# => If you slice the new list from the point of the length of the first list in the concat, then you will get the
# second list of concat with all the elements from the first list removed.
# Inspired by https://github.com/hashicorp/terraform/issues/16044#issuecomment-392269246
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haha, that's super clever 😁

@@ -0,0 +1,27 @@
# List Remove Module

This is a module that can be used to remove items in a given list from another list.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might want to mention this is not yet built into Terraform's interpolation functions

terraform.InitAndApply(t, terratestOptions)

assertOutputEquals(t, "output_list_as_csv", "us-east-1a,us-east-1d,us-east-1e", terratestOptions)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may want to make the inputs to that example configurable and run through a few more test cases:

  • Two empty lists
  • One filled list, one empty
  • Two identical lists
  • Two lists with no overlap

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea!

@yorinasub17
Copy link
Contributor Author

UPDATE 8798f61 :

  • Added more test cases
  • Added note that this will not work if you need duplicate items in the input list.

Will merge and cut release if the build passes.

@yorinasub17
Copy link
Contributor Author

Ok build passed. Merging. Thanks for the review!

@yorinasub17 yorinasub17 merged commit 6ab5364 into master Apr 19, 2019
@yorinasub17 yorinasub17 deleted the yori-list-remove branch April 19, 2019 15:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants