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

     1  // Copyright (c) HashiCorp, Inc.
     2  // SPDX-License-Identifier: MPL-2.0
     3  
     4  package funcs
     5  
     6  import (
     7  	"fmt"
     8  
     9  	"github.com/terramate-io/tf/lang/marks"
    10  	"github.com/zclconf/go-cty/cty"
    11  )
    12  
    13  func redactIfSensitive(value interface{}, markses ...cty.ValueMarks) string {
    14  	if marks.Has(cty.DynamicVal.WithMarks(markses...), marks.Sensitive) {
    15  		return "(sensitive value)"
    16  	}
    17  	switch v := value.(type) {
    18  	case string:
    19  		return fmt.Sprintf("%q", v)
    20  	default:
    21  		return fmt.Sprintf("%v", v)
    22  	}
    23  }