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

AtMostOneOf #735

Closed
arxeiss opened this issue Apr 6, 2021 · 2 comments · Fixed by #912
Closed

AtMostOneOf #735

arxeiss opened this issue Apr 6, 2021 · 2 comments · Fixed by #912
Assignees
Labels
documentation Improvements or additions to documentation
Milestone

Comments

@arxeiss
Copy link

arxeiss commented Apr 6, 2021

SDK version

github.com/hashicorp/terraform-plugin-sdk/v2 v2.4.4

Use-cases

I have some optional attributes, but only one of them can be set. Something like ExactlyOneOf but accept also none of them.

Proposal

Maybe add something like AtMostOneOf similar to ExactlyOneOf.

References

I saw there was first attempt to create this in #225 but then it was changed to ExactlyOneOf

@arxeiss arxeiss added the enhancement New feature or request label Apr 6, 2021
@arxeiss
Copy link
Author

arxeiss commented Apr 6, 2021

OK, I have found, that ConflictsWith is exactly what I want. So there is no need to add AtMostOneOf or something like that.

However I think, the documentation could be fixed a little bit. There is written this:

// ConflictsWith is a set of schema keys that conflict with this schema.
// This will only check that they're set in the _config_. This will not
// raise an error for a malfunctioning resource that sets a conflicting key.

Which I understood is just checking I have the correct schema. Ie raising error during this, because category_id conflicts with department_id, which does not exist in the schema.

return &schema.Resource{
	Schema: map[string]*schema.Schema{
		"category_id": &schema.Schema{
			Type:          schema.TypeString,
			ConflictsWith: []string{"department_id"}
		}
		// "department_id": &schema.Schema{
		//	Type:          schema.TypeString,
		//	ConflictsWith: []string{"category_id"}
		// }
	}
}

@bflad bflad added documentation Improvements or additions to documentation and removed enhancement New feature or request labels Mar 15, 2022
@bflad bflad modified the milestones: v2.12.0, v2.13.0 Mar 15, 2022
@bflad bflad self-assigned this Mar 23, 2022
bflad added a commit that referenced this issue Mar 23, 2022
Reference: #467
Reference: #601
Reference: #735

This also spends some cycles fixing the Go documentation for struct fields to be aligned with each field individually, so pkg.go.dev and the Go language server can appropriately show the matching documentation.
bflad added a commit that referenced this issue Mar 23, 2022
…pes (#912)

Reference: #467
Reference: #601
Reference: #705
Reference: #735

This also spends some cycles fixing the Go documentation for struct fields to be aligned with each field individually, so pkg.go.dev and the Go language server can appropriately show the matching documentation.
@github-actions
Copy link

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 Apr 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
documentation Improvements or additions to documentation
Projects
None yet
2 participants