Skip to content

Commit

Permalink
Revert Schema.AttributeAtPath implicit parent Attribute handling and …
Browse files Browse the repository at this point in the history
…add unit testing
  • Loading branch information
bflad committed Sep 28, 2021
1 parent ff49f1d commit e8f62d7
Show file tree
Hide file tree
Showing 2 changed files with 773 additions and 10 deletions.
12 changes: 2 additions & 10 deletions tfsdk/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,16 +122,8 @@ func (s Schema) AttributeAtPath(path *tftypes.AttributePath) (Attribute, error)
return Attribute{}, ErrPathInsideAtomicAttribute
}

// list, set, and map nested attributes all return a
// map[string]Attribute when the path points to an element in the list,
// set, or path. We need it to point to an attribute specifically, so
// we're choosing to use the parent attribute in this case, which is
// usually what we want.
if len(path.Steps()) > 1 {
lastStep := path.Steps()[len(path.Steps())-1]
if _, ok := lastStep.(tftypes.AttributeName); !ok {
return s.AttributeAtPath(path.WithoutLastStep())
}
if _, ok := res.(nestedAttributes); ok {
return Attribute{}, ErrPathInsideAtomicAttribute
}

a, ok := res.(Attribute)
Expand Down
Loading

0 comments on commit e8f62d7

Please sign in to comment.