Skip to content

Commit

Permalink
add traversalToPath func
Browse files Browse the repository at this point in the history
  • Loading branch information
kmoe committed Feb 14, 2022
1 parent 41c6a20 commit 7b6faac
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 34 deletions.
43 changes: 24 additions & 19 deletions internal/terraform/node_resource_abstract_instance.go
Expand Up @@ -1146,30 +1146,35 @@ func (n *NodeAbstractResource) processIgnoreChanges(prior, config cty.Value) (ct
func traversalsToPaths(traversals []hcl.Traversal) []cty.Path {
paths := make([]cty.Path, len(traversals))
for i, traversal := range traversals {
path := make(cty.Path, len(traversal))
for si, step := range traversal {
switch ts := step.(type) {
case hcl.TraverseRoot:
path[si] = cty.GetAttrStep{
Name: ts.Name,
}
case hcl.TraverseAttr:
path[si] = cty.GetAttrStep{
Name: ts.Name,
}
case hcl.TraverseIndex:
path[si] = cty.IndexStep{
Key: ts.Key,
}
default:
panic(fmt.Sprintf("unsupported traversal step %#v", step))
}
}
path := traversalToPath(traversal)
paths[i] = path
}
return paths
}

func traversalToPath(traversal hcl.Traversal) cty.Path {
path := make(cty.Path, len(traversal))
for si, step := range traversal {
switch ts := step.(type) {
case hcl.TraverseRoot:
path[si] = cty.GetAttrStep{
Name: ts.Name,
}
case hcl.TraverseAttr:
path[si] = cty.GetAttrStep{
Name: ts.Name,
}
case hcl.TraverseIndex:
path[si] = cty.IndexStep{
Key: ts.Key,
}
default:
panic(fmt.Sprintf("unsupported traversal step %#v", step))
}
}
return path
}

func processIgnoreChangesIndividual(prior, config cty.Value, ignoreChangesPath []cty.Path) (cty.Value, tfdiags.Diagnostics) {
type ignoreChange struct {
// Path is the full path, minus any trailing map index
Expand Down
16 changes: 1 addition & 15 deletions internal/terraform/node_resource_validate.go
Expand Up @@ -388,21 +388,7 @@ func (n *NodeValidatableResource) validateResource(ctx EvalContext) tfdiags.Diag
// If the traversal was valid, convert it to a cty.Path and
// use that to check whether the Attribute is Computed.
if !diags.HasErrors() {
path := make(cty.Path, len(traversal))
for si, step := range traversal {
switch ts := step.(type) {
case hcl.TraverseAttr:
path[si] = cty.GetAttrStep{
Name: ts.Name,
}
case hcl.TraverseIndex:
path[si] = cty.IndexStep{
Key: ts.Key,
}
default:
panic(fmt.Sprintf("unsupported traversal step %#v", step))
}
}
path := traversalToPath(traversal)

attrSchema := schema.AttributeByPath(path)

Expand Down

0 comments on commit 7b6faac

Please sign in to comment.