Skip to content

Commit

Permalink
Merge pull request #35271 from hashicorp/jbardin/render-uknown-block
Browse files Browse the repository at this point in the history
render entirely unknown blocks in the plan output
  • Loading branch information
jbardin authored Jun 3, 2024
2 parents 611210d + 6b19b9e commit a38be7d
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
7 changes: 7 additions & 0 deletions internal/command/jsonformat/differ/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,13 @@ func ComputeDiffForBlock(change structured.Change, block *jsonprovider.Block) co
afterSensitive := childValue.IsAfterSensitive()
forcesReplacement := childValue.ReplacePaths.Matches()

if unknown, ok := checkForUnknownBlock(childValue, block); ok {
// An unknown block doesn't render any type information, so we can
// render it as a single block rather than switching on all types.
blocks.AddSingleBlock(key, unknown, forcesReplacement, beforeSensitive, afterSensitive)
continue
}

switch NestingMode(blockType.NestingMode) {
case nestingModeSet:
diffs, action := computeBlockDiffsAsSet(childValue, blockType.Block)
Expand Down
35 changes: 35 additions & 0 deletions internal/command/jsonformat/differ/differ_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,41 @@ func TestValue_SimpleBlocks(t *testing.T) {
"normal_attribute": renderers.ValidatePrimitive(nil, "some value", plans.Create, false),
}, nil, nil, nil, nil, plans.Create, false),
},
"create_with_unknown_block": {
input: structured.Change{
Before: nil,
After: map[string]interface{}{
"normal_attribute": "some value",
},
Unknown: map[string]any{
"nested": true,
},
},
block: &jsonprovider.Block{
Attributes: map[string]*jsonprovider.Attribute{
"normal_attribute": {
AttributeType: unmarshalType(t, cty.String),
},
},
BlockTypes: map[string]*jsonprovider.BlockType{
"nested": {
NestingMode: "single",
Block: &jsonprovider.Block{
Attributes: map[string]*jsonprovider.Attribute{
"attr": {
AttributeType: unmarshalType(t, cty.String),
Optional: true,
},
},
},
},
},
},
validate: renderers.ValidateBlock(map[string]renderers.ValidateDiffFunction{
"normal_attribute": renderers.ValidatePrimitive(nil, "some value", plans.Create, false),
}, map[string]renderers.ValidateDiffFunction{
"nested": renderers.ValidateUnknown(nil, plans.Create, false),
}, nil, nil, nil, plans.Create, false)},
}
for name, tc := range tcs {
// Set some default values
Expand Down

0 comments on commit a38be7d

Please sign in to comment.