github.com/opentofu/opentofu@v1.7.1/internal/lang/marks/marks.go (about) 1 // Copyright (c) The OpenTofu Authors 2 // SPDX-License-Identifier: MPL-2.0 3 // Copyright (c) 2023 HashiCorp, Inc. 4 // SPDX-License-Identifier: MPL-2.0 5 6 package marks 7 8 import ( 9 "github.com/zclconf/go-cty/cty" 10 ) 11 12 // valueMarks allow creating strictly typed values for use as cty.Value marks. 13 // Each distinct mark value must be a constant in this package whose value 14 // is a valueMark whose underlying string matches the name of the variable. 15 type valueMark string 16 17 func (m valueMark) GoString() string { 18 return "marks." + string(m) 19 } 20 21 // Has returns true if and only if the cty.Value has the given mark. 22 func Has(val cty.Value, mark valueMark) bool { 23 return val.HasMark(mark) 24 } 25 26 // Contains returns true if the cty.Value or any any value within it contains 27 // the given mark. 28 func Contains(val cty.Value, mark valueMark) bool { 29 ret := false 30 cty.Walk(val, func(_ cty.Path, v cty.Value) (bool, error) { 31 if v.HasMark(mark) { 32 ret = true 33 return false, nil 34 } 35 return true, nil 36 }) 37 return ret 38 } 39 40 // Sensitive indicates that this value is marked as sensitive in the context of 41 // OpenTofu. 42 const Sensitive = valueMark("Sensitive") 43 44 // TypeType is used to indicate that the value contains a representation of 45 // another value's type. This is part of the implementation of the console-only 46 // `type` function. 47 const TypeType = valueMark("TypeType")