-
Notifications
You must be signed in to change notification settings - Fork 9.5k
/
marks.go
45 lines (37 loc) · 1.24 KB
/
marks.go
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package marks
import (
"github.com/zclconf/go-cty/cty"
)
// valueMarks allow creating strictly typed values for use as cty.Value marks.
// Each distinct mark value must be a constant in this package whose value
// is a valueMark whose underlying string matches the name of the variable.
type valueMark string
func (m valueMark) GoString() string {
return "marks." + string(m)
}
// Has returns true if and only if the cty.Value has the given mark.
func Has(val cty.Value, mark valueMark) bool {
return val.HasMark(mark)
}
// Contains returns true if the cty.Value or any any value within it contains
// the given mark.
func Contains(val cty.Value, mark valueMark) bool {
ret := false
cty.Walk(val, func(_ cty.Path, v cty.Value) (bool, error) {
if v.HasMark(mark) {
ret = true
return false, nil
}
return true, nil
})
return ret
}
// Sensitive indicates that this value is marked as sensitive in the context of
// Terraform.
const Sensitive = valueMark("Sensitive")
// TypeType is used to indicate that the value contains a representation of
// another value's type. This is part of the implementation of the console-only
// `type` function.
const TypeType = valueMark("TypeType")