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

types: Support Float64, Float64Type, Int64, and Int64Type #166

Merged
merged 3 commits into from
Sep 22, 2021

Conversation

bflad
Copy link
Contributor

@bflad bflad commented Sep 17, 2021

Closes #137

@bflad bflad added enhancement New feature or request sdkv2-parity Issues tracking feature parity with terraform-plugin-sdk v2 and PRs working towards it. labels Sep 17, 2021
@bflad bflad requested a review from a team September 17, 2021 18:42
types/float64.go Outdated
}

// Validation is handled by Validate method.
f, _ := bigF.Float64()
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd say let's still bubble up the error anyways, for when things don't work the way they're supposed to. Error checking in depth. :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You got it!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, I'm not positive of this, but an interesting caveat to this is that this error I think will always be returned first instead of the Validate() diagnostics. I guess the only real difference is the error messaging/formatting, but could be something to consider.

Copy link
Contributor

Choose a reason for hiding this comment

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

Will it? I thought we designed Validate diagnostics to run before trying to create any attr.Values, which is (as far as I can tell) where this gets used? Otherwise, the Validate would take an attr.Value argument, I think?

Copy link
Contributor

Choose a reason for hiding this comment

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

tfValue, err := c.terraformValueAtPath(path)
if err != nil {
diags.AddAttributeError(
path,
"Configuration Read Error",
"An unexpected error was encountered trying to read an attribute from the configuration. This is always an error in the provider. Please report the following to the provider developer:\n\n"+err.Error(),
)
return nil, diags
}
if attrTypeWithValidate, ok := attrType.(attr.TypeWithValidate); ok {
diags.Append(attrTypeWithValidate.Validate(ctx, tfValue, path)...)
if diags.HasError() {
return nil, diags
}
}
attrValue, err := attrType.ValueFromTerraform(ctx, tfValue)
if err != nil {
diags.AddAttributeError(
path,
"Configuration Read Error",
"An unexpected error was encountered trying to read an attribute from the configuration. This is always an error in the provider. Please report the following to the provider developer:\n\n"+err.Error(),
)
return nil, diags
}
This seems to suggest to me, for GetAttribute on Config specifically at least, that the Validate diags will be returned instead of the ValueFromTerraform error when both are returned. I think the reason I'm arguing we should handle it here anyways is as a safeguard in case we ever forget to call Validate or call them in the wrong order or something.

@paddycarver paddycarver added the types Issues and pull requests about our types abstraction and implementations. label Sep 21, 2021
…rs, refactor validate functions into type files
Copy link
Contributor

@paddycarver paddycarver left a comment

Choose a reason for hiding this comment

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

LGTM 👍 🚀

@bflad bflad added this to the v0.4.0 milestone Sep 22, 2021
@bflad bflad merged commit 029511f into main Sep 22, 2021
@bflad bflad deleted the bflad-f-types-Float64-Int64 branch September 22, 2021 14:55
@github-actions
Copy link

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, 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 Oct 23, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request sdkv2-parity Issues tracking feature parity with terraform-plugin-sdk v2 and PRs working towards it. types Issues and pull requests about our types abstraction and implementations.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make a types.Int64 and types.Float64
2 participants