File tree Expand file tree Collapse file tree 1 file changed +12
-1
lines changed
Expand file tree Collapse file tree 1 file changed +12
-1
lines changed Original file line number Diff line number Diff line change @@ -5,9 +5,13 @@ import (
55 "strings"
66
77 "github.com/hashicorp/hcl/v2"
8+ "github.com/zclconf/go-cty/cty"
89)
910
1011func ReferenceNames (exp hcl.Expression ) []string {
12+ if exp == nil {
13+ return []string {}
14+ }
1115 allVars := exp .Variables ()
1216 vars := make ([]string , 0 , len (allVars ))
1317
@@ -29,7 +33,14 @@ func CreateDotReferenceFromTraversal(traversals ...hcl.Traversal) string {
2933 case hcl.TraverseAttr :
3034 refParts = append (refParts , part .Name )
3135 case hcl.TraverseIndex :
32- refParts = append (refParts , fmt .Sprintf ("[%s]" , part .Key .AsString ()))
36+ if part .Key .Type ().Equals (cty .String ) {
37+ refParts = append (refParts , fmt .Sprintf ("[%s]" , part .Key .AsString ()))
38+ } else if part .Key .Type ().Equals (cty .Number ) {
39+ idx , _ := part .Key .AsBigFloat ().Int64 ()
40+ refParts = append (refParts , fmt .Sprintf ("[%d]" , idx ))
41+ } else {
42+ refParts = append (refParts , fmt .Sprintf ("[?? %q]" , part .Key .Type ().FriendlyName ()))
43+ }
3344 }
3445 }
3546 }
You can’t perform that action at this time.
0 commit comments