github.com/graywolf-at-work-2/terraform-vendor@v1.4.5/internal/command/jsonformat/differ/unknown.go (about) 1 package differ 2 3 import ( 4 "github.com/zclconf/go-cty/cty" 5 6 "github.com/hashicorp/terraform/internal/command/jsonformat/computed" 7 8 "github.com/hashicorp/terraform/internal/command/jsonformat/computed/renderers" 9 10 "github.com/hashicorp/terraform/internal/command/jsonprovider" 11 ) 12 13 func (change Change) checkForUnknownType(ctype cty.Type) (computed.Diff, bool) { 14 return change.checkForUnknown(false, func(value Change) computed.Diff { 15 return value.ComputeDiffForType(ctype) 16 }) 17 } 18 func (change Change) checkForUnknownNestedAttribute(attribute *jsonprovider.NestedType) (computed.Diff, bool) { 19 20 // We want our child attributes to show up as computed instead of deleted. 21 // Let's populate that here. 22 childUnknown := make(map[string]interface{}) 23 for key := range attribute.Attributes { 24 childUnknown[key] = true 25 } 26 27 return change.checkForUnknown(childUnknown, func(value Change) computed.Diff { 28 return value.computeDiffForNestedAttribute(attribute) 29 }) 30 } 31 32 func (change Change) checkForUnknownBlock(block *jsonprovider.Block) (computed.Diff, bool) { 33 34 // We want our child attributes to show up as computed instead of deleted. 35 // Let's populate that here. 36 childUnknown := make(map[string]interface{}) 37 for key := range block.Attributes { 38 childUnknown[key] = true 39 } 40 41 return change.checkForUnknown(childUnknown, func(value Change) computed.Diff { 42 return value.ComputeDiffForBlock(block) 43 }) 44 } 45 46 func (change Change) checkForUnknown(childUnknown interface{}, computeDiff func(value Change) computed.Diff) (computed.Diff, bool) { 47 unknown := change.isUnknown() 48 49 if !unknown { 50 return computed.Diff{}, false 51 } 52 53 // No matter what we do here, we want to treat the after value as explicit. 54 // This is because it is going to be null in the value, and we don't want 55 // the functions in this package to assume this means it has been deleted. 56 change.AfterExplicit = true 57 58 if change.Before == nil { 59 return change.asDiff(renderers.Unknown(computed.Diff{})), true 60 } 61 62 // If we get here, then we have a before value. We're going to model a 63 // delete operation and our renderer later can render the overall change 64 // accurately. 65 66 beforeValue := Change{ 67 Before: change.Before, 68 BeforeSensitive: change.BeforeSensitive, 69 Unknown: childUnknown, 70 ReplacePaths: change.ReplacePaths, 71 RelevantAttributes: change.RelevantAttributes, 72 } 73 return change.asDiff(renderers.Unknown(computeDiff(beforeValue))), true 74 } 75 76 func (change Change) isUnknown() bool { 77 if unknown, ok := change.Unknown.(bool); ok { 78 return unknown 79 } 80 return false 81 }