Skip to content

tfsdk: Update Config, Plan, and State type GetAttribute methods to use reflection #167

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

Merged
merged 5 commits into from
Oct 28, 2021

Conversation

bflad
Copy link
Contributor

@bflad bflad commented Sep 17, 2021

Closes #134

@bflad bflad added enhancement New feature or request breaking-change This PR introduces a breaking change or the resolution of this issue may require a breaking change. labels Sep 17, 2021
@bflad bflad requested a review from a team September 17, 2021 21:09
bflad added a commit that referenced this pull request Sep 17, 2021
Comment on lines +36 to +62
for idx, valueAsDiag := range valueAsDiags {
if valueAsDiag.Severity() == diag.SeverityError {
valueAsDiags[idx] = diag.NewAttributeErrorDiagnostic(
path,
valueAsDiag.Summary(),
valueAsDiag.Detail(),
)
} else if valueAsDiag.Severity() == diag.SeverityWarning {
valueAsDiags[idx] = diag.NewAttributeWarningDiagnostic(
path,
valueAsDiag.Summary(),
valueAsDiag.Detail(),
)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Eek. Can we add an issue at least to have diag.Diagnostic have a SetPath method to avoid this kind of stuff?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I created #169, but it might require some refactoring to the diag package.

tfsdk/config.go Outdated
func (c Config) GetAttribute(ctx context.Context, path *tftypes.AttributePath, target interface{}) diag.Diagnostics {
attrValue, diags := c.getAttributeValue(ctx, path)

if attrValue == nil || diags.HasError() {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm still 🤔 about the case where attrValue is nil. If error diagnostics are returned, the provider will think that target has been set, when it has not. If error diagnostics are returned, then the check is unnecessary. The only case in which the check helps us avoids a panic but is really hard to debug.

Do we want to catch a nil attrValue and return an error diagnostic for it, instead?

@paddycarver paddycarver added the reflection Issues and PRs about the reflection subsystem used to convert between attr.Values and Go values. label Sep 21, 2021
@bflad bflad requested a review from paddycarver September 21, 2021 19:12
@bflad bflad removed their assignment Sep 21, 2021
@bflad
Copy link
Contributor Author

bflad commented Sep 29, 2021

This may require some light rebase work depending on #185

@bflad bflad force-pushed the bflad-tfsdk-GetAttribute-reflection branch from f8cc3a2 to 862229f Compare October 4, 2021 13:43
@bflad
Copy link
Contributor Author

bflad commented Oct 4, 2021

Rebased after #185

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.

Let's do it.

@bflad bflad added this to the v0.5.0 milestone Oct 28, 2021
@bflad bflad merged commit bf7e2c8 into main Oct 28, 2021
@bflad bflad deleted the bflad-tfsdk-GetAttribute-reflection branch October 28, 2021 13:52
@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 Nov 28, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
breaking-change This PR introduces a breaking change or the resolution of this issue may require a breaking change. enhancement New feature or request reflection Issues and PRs about the reflection subsystem used to convert between attr.Values and Go values.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make GetAttribute use reflection
2 participants