github.com/graywolf-at-work-2/terraform-vendor@v1.4.5/internal/command/jsonformat/computed/renderers/sensitive.go (about)

     1  package renderers
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/hashicorp/terraform/internal/command/jsonformat/computed"
     7  	"github.com/hashicorp/terraform/internal/plans"
     8  )
     9  
    10  var _ computed.DiffRenderer = (*sensitiveRenderer)(nil)
    11  
    12  func Sensitive(change computed.Diff, beforeSensitive, afterSensitive bool) computed.DiffRenderer {
    13  	return &sensitiveRenderer{
    14  		inner:           change,
    15  		beforeSensitive: beforeSensitive,
    16  		afterSensitive:  afterSensitive,
    17  	}
    18  }
    19  
    20  type sensitiveRenderer struct {
    21  	inner computed.Diff
    22  
    23  	beforeSensitive bool
    24  	afterSensitive  bool
    25  }
    26  
    27  func (renderer sensitiveRenderer) RenderHuman(diff computed.Diff, indent int, opts computed.RenderHumanOpts) string {
    28  	return fmt.Sprintf("(sensitive value)%s%s", nullSuffix(diff.Action, opts), forcesReplacement(diff.Replace, opts))
    29  }
    30  
    31  func (renderer sensitiveRenderer) WarningsHuman(diff computed.Diff, indent int, opts computed.RenderHumanOpts) []string {
    32  	if (renderer.beforeSensitive == renderer.afterSensitive) || renderer.inner.Action == plans.Create || renderer.inner.Action == plans.Delete {
    33  		// Only display warnings for sensitive values if they are changing from
    34  		// being sensitive or to being sensitive and if they are not being
    35  		// destroyed or created.
    36  		return []string{}
    37  	}
    38  
    39  	var warning string
    40  	if renderer.beforeSensitive {
    41  		warning = opts.Colorize.Color(fmt.Sprintf("  # [yellow]Warning[reset]: this attribute value will no longer be marked as sensitive\n%s  # after applying this change.", formatIndent(indent)))
    42  	} else {
    43  		warning = opts.Colorize.Color(fmt.Sprintf("  # [yellow]Warning[reset]: this attribute value will be marked as sensitive and will not\n%s  # display in UI output after applying this change.", formatIndent(indent)))
    44  	}
    45  
    46  	if renderer.inner.Action == plans.NoOp {
    47  		return []string{fmt.Sprintf("%s The value is unchanged.", warning)}
    48  	}
    49  	return []string{warning}
    50  }