github.com/kevinklinger/open_terraform@v1.3.6/noninternal/lang/marks/marks.go (about)

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