configs/configschema: Introduce the NestingGroup mode for blocks #20949
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In study of existing providers we've found a pattern we weren't previously accounting for of using a nested block type to represent a group of arguments that relate to a particular feature that is always enabled but where it improves configuration readability to group all of its settings together in a nested block.
The existing
NestingSingle
is not a good fit for this because it is designed under the assumption that the presence or absence of the block has some significance in enabling or disabling the relevant feature, and so for these always-active cases we'd generate a misleading plan where the settings for the feature appear totally absent, rather than showing the default values that will be selected.NestingGroup
is, therefore, a slight variation ofNestingSingle
where presence vs. absence of the block is not distinguishable (it's never null) and instead its contents are treated as unset when the block is absent. This then in turn causes any default values associated with the nested arguments to be honored and displayed in the plan whenever the block is not explicitly configured.The current SDK cannot activate this mode, but that's okay because its "legacy type system" opt-out flag allows it to force a block to be processed in this way anyway.
I didn't want to add this in right now, but I couldn't think of a reasonable way to defer adding it without requiring a breaking change later. Therefore I've tested this carefully with both some tests shown in the changeset here and with a special test provider (not using the current SDK) that allowed me to exercise this feature in a more open-ended way. One result of that open-ended testing is shown in the following screenshot:
In this test resource type, the
access
block was defined asNestingGroup
and then I ranterraform apply
with no explicit block present in configuration. WithNestingSingle
we would've seen no mention of that block in the plan at all, but now withNestingGroup
we can see the default block fully expanded with the defaultpolicy
value of{}
.This will be essentially dead code in real-world use for the time being, until we release an updated SDK with support for activating this mode. But having the mechanisms in place to deal with it now means it should be safe to release that SDK later without making a breaking change to the plugin protocol.
The diff seems large because I visited every usage of
configschema.NestingSingle
to determine what would be the suitable behavior forconfigschema.NestingGroup
in that scenario. In many cases, we treat it as equivalent toNestingSingle
because the main handling of theNestingGroup
behavior happens at decode time.