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

helper/schema: Allow self references with AllowOneOf, ExactlyOneOf, and RequiredWith in InternalValidate #418

Merged
merged 3 commits into from
Apr 30, 2020

Conversation

bflad
Copy link
Contributor

@bflad bflad commented Apr 29, 2020

Reference: #407
Reference: #416

bflad added 2 commits April 29, 2020 09:15
…OneOf/ExactlyOneOf

Reference: hashicorp#407
Reference: hashicorp#416

Includes TODO items for logic that needs adjustment to work as expected. `AtLeastOneOf` and `ExactlyOneOf` at the attribute level should not only allow self-reference, but also require it.
@@ -948,6 +954,11 @@ func checkKeysAgainstSchemaFlags(k string, keys []string, topSchemaMap schemaMap
return fmt.Errorf("%s cannot contain Computed(When) attribute (%s)", k, key)
}
}

if requireSelfReference && !foundSelfReference {
Copy link
Contributor

Choose a reason for hiding this comment

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

AtLeastOneOf and ExactlyOneOf were implemented with an idempotent line that adds itself and removes duplicate, it allows the self reference to be optional. I would change this PR to have a flag for allowSelfRef and ditch the requirement for it, but rather disallow for ConflictsWith (and possibly RequiredWith)

Copy link
Contributor

Choose a reason for hiding this comment

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

Unless we remove that line in validateRequiredWith I would actually ONLY have this error for ConflictsWith, just to be consistent, I will approve either final implementation.

@paultyng
Copy link
Contributor

Per Alex's comment, may be worth referencing back to the RFC, there was some discussion about the requirement of the self reference, I think we landed on not requiring it for a reason, though I can't recall the reason 😂

@bflad
Copy link
Contributor Author

bflad commented Apr 29, 2020

I'll update this to be allow vs require and add RequiresWhen unit testing as well to ensure that new attribute is covered since its not currently (with allowed self-references for it). 👍

…ow, add InternalValidate unit testing for RequiredWhen

Reference: hashicorp#418 (review)
bflad added a commit to bflad/terraform-plugin-sdk that referenced this pull request Apr 30, 2020
…ow, add InternalValidate unit testing for RequiredWhen

Reference: hashicorp#418 (review)
@bflad bflad changed the title helper/schema: Allow and require self references with AllowOneOf and ExactlyOneOf in InternalValidate helper/schema: Allow self references with AllowOneOf, ExactlyOneOf, and RequiredWith in InternalValidate Apr 30, 2020
@bflad
Copy link
Contributor Author

bflad commented Apr 30, 2020

Implementation updated and submitted v1 backport: #423

@appilon appilon merged commit fb7e556 into hashicorp:master Apr 30, 2020
appilon pushed a commit that referenced this pull request Apr 30, 2020
…ow, add InternalValidate unit testing for RequiredWhen

Reference: #418 (review)
@ghost
Copy link

ghost commented May 31, 2020

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 May 31, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants