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 a String contains or includes function that can replace the can(regex(..., ...)) pattern #27198

Closed
Gowiem opened this issue Dec 8, 2020 · 8 comments

Comments

@Gowiem
Copy link

Gowiem commented Dec 8, 2020

Current Terraform Version

0.14.1

Use-cases

The current solution for checking if a string var or local contains a given substring is typically done using can(regex("substring_to_check", var.my_string)) (and there are a number of other ways to do so as well). IMHO, this is pretty unintuitive as it requires using a couple functions and doesn't "read" well.

The end goal of providing a specific function to handle this problem is to provide a cleaner and more concise way to accomplish the same.

Attempted Solutions

As mentioned above, the current solution is typically done with regex and pals. There are many ways to accomplish this.

Proposal

I'm proposing that Terraform provide a native function to handle this instead of the unintuitive ways it's handled now. This can be seen in many programming languages:

  1. Golang strings#Contains
  2. Ruby String#include?
  3. JS string#includes

I believe a new function like contains (problematic because of the Collection contains function?) or includes would solve this problem elegantly. I think this is worth bringing up since this is such common business logic pattern.

References

N/A

@Gowiem Gowiem added enhancement new new issue not yet triaged labels Dec 8, 2020
@apparentlymart apparentlymart added config and removed new new issue not yet triaged labels Dec 9, 2020
@Geartrixy
Copy link

Can the pull request from January be reviewed and incorporated in the next release? :)

@scaswell-hirez
Copy link

Hashicorp, y'all have been sitting on this one for over a year since the last comment; almost 2 years since the PR was submitted. It solves a very common use case. Please expedite its inclusion into the next release.

@Chinikins
Copy link

would love to see this in the next release....

@mward-varonis
Copy link

Any plans on including this in an upcoming release?

Thanks!

@crw
Copy link
Contributor

crw commented Feb 24, 2023

It is very difficult for us to make forward-looking statements, however the linked PR is on the radar for future inclusion.

@bflad
Copy link
Contributor

bflad commented Sep 1, 2023

@crw I believe this was resolved with #33069 introducing the strcontains() function in Terraform 1.5

@crw
Copy link
Contributor

crw commented Sep 7, 2023

Thanks @bflad, I appreciate the callout.

@crw crw closed this as completed Sep 7, 2023
Copy link
Contributor

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 11, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants