summaryrefslogtreecommitdiff
path: root/vendor/github.com/hashicorp/hil/ast/unknown.go
blob: d6ddaecc78e7cd20129de227552cb2b754e3135c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package ast

// IsUnknown reports whether a variable is unknown or contains any value
// that is unknown. This will recurse into lists and maps and so on.
func IsUnknown(v Variable) bool {
	// If it is unknown itself, return true
	if v.Type == TypeUnknown {
		return true
	}

	// If it is a container type, check the values
	switch v.Type {
	case TypeList:
		for _, el := range v.Value.([]Variable) {
			if IsUnknown(el) {
				return true
			}
		}
	case TypeMap:
		for _, el := range v.Value.(map[string]Variable) {
			if IsUnknown(el) {
				return true
			}
		}
	default:
	}

	// Not a container type or survive the above checks
	return false
}