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

Mildwonkey/nested type format #27793

Merged
merged 6 commits into from
Feb 18, 2021
Merged

Conversation

mildwonkey
Copy link
Contributor

This PR builds on #27699 . It introduces a small change to the diff formatter, so we don't inadvertently print NestedType attributes with nested sensitive attributes. This is a temporary workaround until a bespoke NestedType diff format implementation is created.

I added an attribute with a NestedType to the TestResourceChange_nestedList test suite, and one test for sensitivity. This pattern needs to be extended to the other tests, and some updated when the bespoke formatter is implemented, but I think it's a good start that's worth getting into the code base now rather than waiting for the end product.

This work very helpfully uncovered a bug in the ImpliedType() function in configschema, which is fixed here. The last commit modifies a test to prove this fix - the issue was specifically with returning an ObjectWithOptionalAttrs too early.

@codecov
Copy link

codecov bot commented Feb 16, 2021

Codecov Report

Merging #27793 (3c6860c) into master (04b5c7d) will increase coverage by 0.00%.
The diff coverage is 92.30%.

Impacted Files Coverage Δ
command/format/diff.go 90.57% <80.00%> (-0.07%) ⬇️
configs/configschema/implied_type.go 81.08% <100.00%> (+1.66%) ⬆️

@mildwonkey mildwonkey changed the base branch from mildwonkey/protocolv6 to master February 16, 2021 19:52
@mildwonkey mildwonkey requested a review from a team February 16, 2021 19:53
Eventually, the diff formatter will need to be updated to properly
handle NestedTypes, but for now we can let the existing function deal
with them as regular cty.Object-type attributes.

To avoid printing sensitive nested attributes, we will treat any
attribute with at least one sensitive nested attribute as an entirely
sensitive attribute.
ImpliedType() was returning too early when the given object had optional
attributes, therefore skipping the incredibly important step of
accounting for the nesting mode when returning said type.
types

This commit is a small bit of setup for upcoming work on the format
printer for attributes with NestedTypes. I added an attribute with
NestedType + NestingMode NestingList to the
TestResourceChange_nestedList suite of tests to confirm that the output
looks good enough for now, and added some comments about what still
needs to be done and what tests _should_ fail once the diff printing is
improved.

This is admittedly not a very high-value commit, but I'd rather get the
tests committed now than risk losing them; these are especially tedious
to hand-craft.
Copy link
Contributor

@alisdair alisdair left a comment

Choose a reason for hiding this comment

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

This looks good to me!

The updated tests with explanation comments for how they should fail when implemented are great. I left a note inline asking for one additional comment about the writeNestedAttrDiff method, if possible. But not a blocker to merge.

@@ -4311,3 +4342,34 @@ func outputChange(name string, before, after cty.Value, sensitive bool) *plans.O

return changeSrc
}

// A basic test schema using NestingList for one attribute and one block
var testSchemaNestingList = &configschema.Block{
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for spotting & extracting this!

@@ -361,6 +374,10 @@ func (p *blockBodyDiffPrinter) writeAttrDiff(name string, attrS *configschema.At
return false
}

func (p *blockBodyDiffPrinter) writeNestedAttrDiff(name string, attrS *configschema.Attribute, old, new cty.Value, nameLen, indent int, path cty.Path) bool {
panic("not implemented")
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This uncalled method confused me a bit, and I couldn't quite see where you'd go next with it. Would it be possible to add a short FIXME comment explaining where this would be called from and some of the next steps?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated! the new comment should make it easier to link the TBD new function, where it's going to be called inside writeAttrDiff, and the tests with FIXME comments that show the current, less desirable, output.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you! 🙇

@ghost
Copy link

ghost commented Mar 21, 2021

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.

@ghost ghost locked as resolved and limited conversation to collaborators Mar 21, 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.

2 participants