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

Fix SingleNestedAttribute validation failure #118

Merged
merged 6 commits into from
Sep 8, 2021
Merged

Fix SingleNestedAttribute validation failure #118

merged 6 commits into from
Sep 8, 2021

Conversation

ewbankkit
Copy link
Contributor

@ewbankkit ewbankkit commented Aug 25, 2021

Closes #112.

Don't attempt validation if the attribute is missing from configuration.

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.

Could we also add a .changelog entry? https://github.com/hashicorp/engineering-docs/blob/master/terraform/sdk/changelog.md

(I know that link is to a private repo, I'll open an issue to get it added to our contributing guide)


resp.Diagnostics = nestedAttrResp.Diagnostics
if len(o.Attrs) > 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason this became necessary?

The for loop should cover this case, by just not entering the for loop, which it looks like is what this does?

Unless this is to cover the case where the schema has attributes defined, but Terraform sends a value omitting those attributes, which as far as I know, should never happen?

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 think, as @kmoe mentions in #112 (comment), it's the call to tftypes.WalkAttributePath in Config.GetAttribute called from Attribute.validate on the nested Null Attribute value that fails.

Copy link
Contributor

Choose a reason for hiding this comment

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

Could we use o.Null then, instead of checking the number of attributes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let me take a look...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes !o.Null works just as well.
Commit pushed.

Choose a reason for hiding this comment

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

Just tested this and hit a failure with unknown attributes; it looks like you'll need to add a check for !o.Unknown too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will do; thanks

.changelog/118.txt Outdated Show resolved Hide resolved
nestedAttr.validate(ctx, nestedAttrReq, nestedAttrResp)
if !ok {
err := fmt.Errorf("unknown attribute value type (%T) for nesting mode (%T) at path: %s", req.AttributeConfig, nm, req.AttributePath)
resp.Diagnostics = append(resp.Diagnostics, &tfprotov6.Diagnostic{
Copy link
Contributor

Choose a reason for hiding this comment

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

Really sorry to do this to you, @ewbankkit, but could you update to use the helpers added by #110? Just want to keep our consistency @bflad worked so hard to introduce. 😦

Sorry, ping me in chat when you do that and we'll get it merged straightaway before something else comes up. Thanks so much for the patience on this.

@paddycarver paddycarver merged commit 3c27da0 into hashicorp:main Sep 8, 2021
@ewbankkit ewbankkit deleted the b-SingleNestedAttribut-validation-failure branch September 8, 2021 15:53
@github-actions
Copy link

github-actions bot commented Oct 9, 2021

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 9, 2021
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.

SingleNestedAttributes validation failure if the attribute is not present in configuration
4 participants