opentofu/internal/configs/configschema/path.go
Martin Atkins 31349a9c3a Move configs/ to internal/configs/
This is part of a general effort to move all of Terraform's non-library
package surface under internal in order to reinforce that these are for
internal use within Terraform only.

If you were previously importing packages under this prefix into an
external codebase, you could pin to an earlier release tag as an interim
solution until you've make a plan to achieve the same functionality some
other way.
2021-05-17 14:09:07 -07:00

30 lines
701 B
Go

package configschema
import (
"github.com/zclconf/go-cty/cty"
)
// AttributeByPath looks up the Attribute schema which corresponds to the given
// cty.Path. A nil value is returned if the given path does not correspond to a
// specific attribute.
// TODO: this will need to be updated for nested attributes
func (b *Block) AttributeByPath(path cty.Path) *Attribute {
block := b
for _, step := range path {
switch step := step.(type) {
case cty.GetAttrStep:
if attr := block.Attributes[step.Name]; attr != nil {
return attr
}
if nestedBlock := block.BlockTypes[step.Name]; nestedBlock != nil {
block = &nestedBlock.Block
continue
}
return nil
}
}
return nil
}