mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
Allow for nested fields with checkKey on ResourceDiffs.
When checking if a ResourceDiff key is valid, allow for keys that exist on sub-blocks. This allows things like diff.Clear to be called on sub-block fields, instead of just on top-level fields.
This commit is contained in:
parent
c886869a8c
commit
7ee4339555
@ -536,11 +536,15 @@ func childAddrOf(child, parent string) bool {
|
|||||||
|
|
||||||
// checkKey checks the key to make sure it exists and is computed.
|
// checkKey checks the key to make sure it exists and is computed.
|
||||||
func (d *ResourceDiff) checkKey(key, caller string) error {
|
func (d *ResourceDiff) checkKey(key, caller string) error {
|
||||||
s, ok := d.schema[key]
|
keyParts := strings.Split(key, ".")
|
||||||
if !ok {
|
var schema *Schema
|
||||||
|
schemaL := addrToSchema(keyParts, d.schema)
|
||||||
|
if len(schemaL) > 0 {
|
||||||
|
schema = schemaL[len(schemaL)-1]
|
||||||
|
} else {
|
||||||
return fmt.Errorf("%s: invalid key: %s", caller, key)
|
return fmt.Errorf("%s: invalid key: %s", caller, key)
|
||||||
}
|
}
|
||||||
if !s.Computed {
|
if !schema.Computed {
|
||||||
return fmt.Errorf("%s only operates on computed keys - %s is not one", caller, key)
|
return fmt.Errorf("%s only operates on computed keys - %s is not one", caller, key)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
Loading…
Reference in New Issue
Block a user