-
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
Bug: Cannot use keys containing hyphens in TypeSet. #1641
Comments
FWIW, it looks like the internal helper hashcode String function enforces non-negative integers. This was enforced by commit a5040ec. https://github.com/hashicorp/terraform/blob/master/helper/hashcode/hashcode.go#L14 If changing existing hash functions is not an option I think enforcing non-negative hashcodes would be a backwards compatible code change. All bets are off for any hashcodes stored in local state. |
The schema you entered is not valid: it is missing the hash function. I'm assuming this is an oversight. But anyways, I still don't see the problem here? We make sure the hash is positive (if its negative we multiple by -1, effectively). How does this affect things? |
Oops. It's definitely an oversight. I copied the schema from some code and redacted a lot of internal stuff for the bug report. After looking at the code a bit more I couldn't trace how the hashcodes are related and added to the set keys. What I observe is that any key that contains a '-' is eventually replaced by the '~' per lines in schema.go@820/835 and it looks like this behavior was deliberately done by design. Unfortunately, I'm not familiar enough with the code to know what the intended behavior is supposed to be. I'll dig a bit further to see if I can find out what is happening in more detail. |
Got it, I have a feeling I know what you're getting at now. Thanks for the clarification! |
I've submitted a pull request that mitigates the issue for arbitrary keys containing hyphens. Let me know if you see any issues with it. |
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. |
It appears you cannot use keys containing hyphens inside of a TypeSet. It appears this behavior is a result of some logic introduced in 83c760f to include item hashcodes within the key.
https://github.com/hashicorp/terraform/blob/master/helper/schema/schema.go#L820
https://github.com/hashicorp/terraform/blob/master/helper/schema/schema.go#L835
I suspect the s/-/~/ magic exists because the hash function signature returns a signed integer.
I've provided a minimum example that can reproduce the behavior.
main.tf:
foo_resource.go:
terraform apply stdout:
The text was updated successfully, but these errors were encountered: