terraform/configs/depends_on.go

38 lines
1.0 KiB
Go

package configs
import (
"fmt"
"github.com/hashicorp/hcl2/hcl"
)
func decodeDependsOn(attr *hcl.Attribute) ([]hcl.Traversal, hcl.Diagnostics) {
var ret []hcl.Traversal
exprs, diags := hcl.ExprList(attr.Expr)
for _, expr := range exprs {
// A dependency reference was given as a string literal in the legacy
// configuration language and there are lots of examples out there
// showing that usage, so we'll sniff for that situation here and
// produce a specialized error message for it to help users find
// the new correct form.
if exprIsNativeQuotedString(expr) {
diags = append(diags, &hcl.Diagnostic{
Severity: hcl.DiagError,
Summary: "Invalid explicit dependency reference",
Detail: fmt.Sprintf("%s elements must not be given in quotes.", attr.Name),
Subject: attr.Expr.Range().Ptr(),
})
continue
}
traversal, travDiags := hcl.AbsTraversalForExpr(expr)
diags = append(diags, travDiags...)
if len(traversal) != 0 {
ret = append(ret, traversal)
}
}
return ret, diags
}