github.com/hugorut/terraform@v1.1.3/src/lang/marks/marks.go (about)

     1  package marks
     2  
     3  import (
     4  	"strings"
     5  
     6  	"github.com/zclconf/go-cty/cty"
     7  )
     8  
     9  // valueMarks allow creating strictly typed values for use as cty.Value marks.
    10  // The variable name for new values should be the title-cased format of the
    11  // value to better match the GoString output for debugging.
    12  type valueMark string
    13  
    14  func (m valueMark) GoString() string {
    15  	return "marks." + strings.Title(string(m))
    16  }
    17  
    18  // Has returns true if and only if the cty.Value has the given mark.
    19  func Has(val cty.Value, mark valueMark) bool {
    20  	return val.HasMark(mark)
    21  }
    22  
    23  // Contains returns true if the cty.Value or any any value within it contains
    24  // the given mark.
    25  func Contains(val cty.Value, mark valueMark) bool {
    26  	ret := false
    27  	cty.Walk(val, func(_ cty.Path, v cty.Value) (bool, error) {
    28  		if v.HasMark(mark) {
    29  			ret = true
    30  			return false, nil
    31  		}
    32  		return true, nil
    33  	})
    34  	return ret
    35  }
    36  
    37  // Sensitive indicates that this value is marked as sensitive in the context of
    38  // Terraform.
    39  var Sensitive = valueMark("sensitive")
    40  
    41  // Raw is used to indicate to the repl that the value should be written without
    42  // any formatting.
    43  var Raw = valueMark("raw")