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 value.IsNullOrUnknown() function #1060

Open
zliang-akamai opened this issue Nov 20, 2024 · 2 comments
Open

Add value.IsNullOrUnknown() function #1060

zliang-akamai opened this issue Nov 20, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@zliang-akamai
Copy link
Contributor

zliang-akamai commented Nov 20, 2024

Does this make sense for checking whether the value has a real value?

I have an optional but non-computed attribute, I usually think I can safely assume the plan will never be an Unknown value but am worried about someone change the schema to computed in the future and this can become a side-effect.

Writing s.IsNull() || s.IsUnknown() is verbose in provider code, IMO.

func (s StringValue) IsNullOrUnknown() bool {
	return s.IsNull() || s.IsUnknown()
}

Kind of like if someAttr, ok := d.GetOk("some_attr"); ok {} in SDKv2

@zliang-akamai zliang-akamai added the enhancement New feature or request label Nov 20, 2024
@zliang-akamai zliang-akamai changed the title Add value.IsNullOrUnknown Add value.IsNullOrUnknown() function Nov 20, 2024
@chrismarget-j
Copy link

chrismarget-j commented Nov 20, 2024

I've often wished that the attr.Value interface included a HasValue() bool method for the same reason.

think I can safely assume the plan will never be an Unknown value

A mistake that I seem to make regularly is forgetting that while the planned value cannot be unknown for a non-Computed attribute, the config (as used exposed to attribute or resource validator) might be unknown.

@zliang-akamai
Copy link
Contributor Author

@chrismarget-j

A mistake that I seem to make regularly is forgetting that while the planned value cannot be unknown for a non-Computed attribute, the config (as used exposed to attribute or resource validator) might be unknown.

True, I made that mistake 😭

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants