github.com/terramate-io/tf@v0.0.0-20230830114523-fce866b4dfcd/lang/marks/marks.go (about)

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