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 'StringDoesNotContainAny' validation function #212

Merged
merged 1 commit into from
Nov 6, 2019
Merged

Add 'StringDoesNotContainAny' validation function #212

merged 1 commit into from
Nov 6, 2019

Conversation

ewbankkit
Copy link
Contributor

Add StringDoesNotContainAny(), a validator to ensure that the provided value does not contain any of the specified Unicode code points in chars.

$ make test
==> Checking that code complies with gofmt requirements...
go generate ./...
ok  	github.com/hashicorp/terraform-plugin-sdk/helper/acctest	0.016s
ok  	github.com/hashicorp/terraform-plugin-sdk/helper/customdiff	0.017s
?   	github.com/hashicorp/terraform-plugin-sdk/helper/encryption	[no test files]
ok  	github.com/hashicorp/terraform-plugin-sdk/helper/hashcode	0.001s
?   	github.com/hashicorp/terraform-plugin-sdk/helper/logging	[no test files]
ok  	github.com/hashicorp/terraform-plugin-sdk/helper/mutexkv	0.052s
ok  	github.com/hashicorp/terraform-plugin-sdk/helper/pathorcontents	0.008s
ok  	github.com/hashicorp/terraform-plugin-sdk/helper/resource	3.039s
ok  	github.com/hashicorp/terraform-plugin-sdk/helper/schema	0.063s
ok  	github.com/hashicorp/terraform-plugin-sdk/helper/structure	0.030s
ok  	github.com/hashicorp/terraform-plugin-sdk/helper/validation	0.016s
ok  	github.com/hashicorp/terraform-plugin-sdk/httpclient	0.005s
ok  	github.com/hashicorp/terraform-plugin-sdk/internal/addrs	0.014s
ok  	github.com/hashicorp/terraform-plugin-sdk/internal/command/format	0.020s
ok  	github.com/hashicorp/terraform-plugin-sdk/internal/configs	0.025s
ok  	github.com/hashicorp/terraform-plugin-sdk/internal/configs/configload	0.012s
ok  	github.com/hashicorp/terraform-plugin-sdk/internal/configs/configschema	0.008s
ok  	github.com/hashicorp/terraform-plugin-sdk/internal/configs/hcl2shim	0.010s
ok  	github.com/hashicorp/terraform-plugin-sdk/internal/dag	1.411s
?   	github.com/hashicorp/terraform-plugin-sdk/internal/earlyconfig	[no test files]
ok  	github.com/hashicorp/terraform-plugin-sdk/internal/flatmap	0.009s
ok  	github.com/hashicorp/terraform-plugin-sdk/internal/helper/config	0.028s
ok  	github.com/hashicorp/terraform-plugin-sdk/internal/helper/didyoumean	0.001s
ok  	github.com/hashicorp/terraform-plugin-sdk/internal/helper/experiment	0.014s
ok  	github.com/hashicorp/terraform-plugin-sdk/internal/helper/plugin	0.031s
ok  	github.com/hashicorp/terraform-plugin-sdk/internal/httpclient	0.004s
ok  	github.com/hashicorp/terraform-plugin-sdk/internal/initwd	0.020s
ok  	github.com/hashicorp/terraform-plugin-sdk/internal/lang	0.040s
ok  	github.com/hashicorp/terraform-plugin-sdk/internal/lang/blocktoattr	0.024s
ok  	github.com/hashicorp/terraform-plugin-sdk/internal/lang/funcs	0.140s
?   	github.com/hashicorp/terraform-plugin-sdk/internal/modsdir	[no test files]
ok  	github.com/hashicorp/terraform-plugin-sdk/internal/moduledeps	0.011s
ok  	github.com/hashicorp/terraform-plugin-sdk/internal/plans	0.010s
?   	github.com/hashicorp/terraform-plugin-sdk/internal/plans/internal/planproto	[no test files]
ok  	github.com/hashicorp/terraform-plugin-sdk/internal/plans/objchange	0.013s
ok  	github.com/hashicorp/terraform-plugin-sdk/internal/plans/planfile	0.013s
ok  	github.com/hashicorp/terraform-plugin-sdk/internal/plugin/convert	0.011s
ok  	github.com/hashicorp/terraform-plugin-sdk/internal/plugin/discovery	0.029s
?   	github.com/hashicorp/terraform-plugin-sdk/internal/plugin/mock_proto	[no test files]
ok  	github.com/hashicorp/terraform-plugin-sdk/internal/providers	0.020s
?   	github.com/hashicorp/terraform-plugin-sdk/internal/provisioners	[no test files]
ok  	github.com/hashicorp/terraform-plugin-sdk/internal/registry	0.009s
ok  	github.com/hashicorp/terraform-plugin-sdk/internal/registry/regsrc	0.003s
ok  	github.com/hashicorp/terraform-plugin-sdk/internal/registry/response	0.002s
?   	github.com/hashicorp/terraform-plugin-sdk/internal/registry/test	[no test files]
ok  	github.com/hashicorp/terraform-plugin-sdk/internal/states	0.003s
ok  	github.com/hashicorp/terraform-plugin-sdk/internal/states/statefile	0.008s
ok  	github.com/hashicorp/terraform-plugin-sdk/internal/svchost	0.003s
ok  	github.com/hashicorp/terraform-plugin-sdk/internal/svchost/auth	0.608s
ok  	github.com/hashicorp/terraform-plugin-sdk/internal/svchost/disco	0.040s
ok  	github.com/hashicorp/terraform-plugin-sdk/internal/tfdiags	0.010s
?   	github.com/hashicorp/terraform-plugin-sdk/internal/tfplugin5	[no test files]
ok  	github.com/hashicorp/terraform-plugin-sdk/internal/vault/helper/pgpkeys	0.243s
ok  	github.com/hashicorp/terraform-plugin-sdk/internal/vault/sdk/helper/compressutil	0.004s
ok  	github.com/hashicorp/terraform-plugin-sdk/internal/vault/sdk/helper/jsonutil	0.011s
?   	github.com/hashicorp/terraform-plugin-sdk/internal/version	[no test files]
?   	github.com/hashicorp/terraform-plugin-sdk/meta	[no test files]
ok  	github.com/hashicorp/terraform-plugin-sdk/plugin	0.075s
ok  	github.com/hashicorp/terraform-plugin-sdk/terraform	3.644s

helper/validation/validation.go Show resolved Hide resolved
@appilon appilon requested a review from a team October 31, 2019 22:24
@radeksimko radeksimko requested review from appilon and removed request for a team November 4, 2019 11:40
@appilon
Copy link
Contributor

appilon commented Nov 6, 2019

@ewbankkit I took the liberty to push to your branch to add a subtle feature. My apologies if you would prefer I not do that in future. @radeksimko I have added a new feature so that validation functions can receive flags in a backwards compatible way in the future. Now a NOT flag can be passed to the newly named StringContainsAny.

ValidateFunc: validation.StringContainsAny("|:/", validation.NOT)

The nicety of the variadic arg is it can support no flags

ValidateFunc: validation.StringContainsAny("|:/")

This can allow the other validation functions to add support without creating a breaking change.

ValidateFunc: validation.IntBetween(5, 10, validation.NOT)

@appilon appilon changed the title Add 'StringDoesNotContainAny' validation function Add 'StringContainsAny' validation function and support negation flag Nov 6, 2019
@appilon appilon requested a review from radeksimko November 6, 2019 03:29
@ewbankkit
Copy link
Contributor Author

@appilon No worries; a nice enhancement.

@appilon
Copy link
Contributor

appilon commented Nov 6, 2019

@ewbankkit Sorry for the back and forth. My attempt at adding a NOT feature is more trouble than it's worth. Just going to revert back to your original commit and get it across the finish line. Thank you for your contribution!

@appilon appilon changed the title Add 'StringContainsAny' validation function and support negation flag Add 'StringDoesNotContainAny' validation function Nov 6, 2019
@appilon appilon merged commit 1202e6a into hashicorp:master Nov 6, 2019
@ewbankkit ewbankkit deleted the add-string-does-not-contain-any branch November 6, 2019 19:31
@belperite
Copy link

Hi,
I'm trying to use this for the first time but am getting the following error when building:
undefined: validation.StringDoesNotContainAny

I'm importing like this:

       "github.com/hashicorp/terraform-plugin-sdk/helper/schema"

        "github.com/hashicorp/terraform-plugin-sdk/helper/validation"

then using like this:

                        "contact_group": &schema.Schema{
                                Type:        schema.TypeString,
                                Description: "The name of the contact group. Required.",
                                Required:    true,
                                ValidateFunc: validation.StringDoesNotContainAny(" "),
                        },

Am definitely using the up-to-date version of the sdk because I can see the function defined in validation.go. I've also cleared all the Go caches I can think of. Any ideas?

Cheers,
Rich

@appilon
Copy link
Contributor

appilon commented Nov 12, 2019

Hello @belperite what provider are you working on? My best guess is you have the go module in your cache and your editor maybe is configured for go modules, but most of our providers actually still use vendoring and have their deps checked into the vendor/ folder. If the project indeed still uses vendoring make sure the module is present in vendor/

$ go get github.com/hashicorp/terraform-plugin-sdk@v1.3.0
$ go mod tidy
$ go mod vendor

@belperite
Copy link

Hi @appilon thanks for getting back to me, what you suggested worked!

I'm working on a custom provider for my employer that I'm sadly unable to share.

I'd previously updated to the latest terraform-plugin-sdk (or so I'd thought) and ran the two go mod commands. The only difference as far as I could see this time was that I specified the version at the end of go get.

Thanks again :)

@ghost
Copy link

ghost commented Dec 7, 2019

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.

@ghost ghost locked and limited conversation to collaborators Dec 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants