Skip to content

Commit

Permalink
Merge pull request #31813 from hashicorp/uk1288-redact-output-sensiti…
Browse files Browse the repository at this point in the history
…ve-values

omit sensitive output values in logs from terraform apply json command
  • Loading branch information
Uk1288 committed Sep 23, 2022
2 parents 6448d7b + 7b34e3e commit a5926f1
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 6 deletions.
1 change: 0 additions & 1 deletion internal/command/views/apply_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,6 @@ func TestApplyJSON_outputs(t *testing.T) {
},
"password": map[string]interface{}{
"sensitive": true,
"value": "horse-battery",
"type": "string",
},
},
Expand Down
7 changes: 6 additions & 1 deletion internal/command/views/json/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,15 @@ func OutputsFromMap(outputValues map[string]*states.OutputValue) (Outputs, tfdia
return nil, diags
}

var redactedValue json.RawMessage
if !ov.Sensitive {
redactedValue = json.RawMessage(value)
}

outputs[name] = Output{
Sensitive: ov.Sensitive,
Type: json.RawMessage(valueType),
Value: json.RawMessage(value),
Value: redactedValue,
}
}

Expand Down
2 changes: 0 additions & 2 deletions internal/command/views/json/output_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,10 @@ func TestOutputsFromMap(t *testing.T) {
"beep": {
Sensitive: true,
Type: json.RawMessage(`"string"`),
Value: json.RawMessage(`"horse-battery"`),
},
"blorp": {
Sensitive: true,
Type: json.RawMessage(`["object",{"a":["object",{"b":["object",{"c":"string"}]}]}]`),
Value: json.RawMessage(`{"a":{"b":{"c":"oh, hi"}}}`),
},
"honk": {
Sensitive: false,
Expand Down
2 changes: 1 addition & 1 deletion internal/command/views/json_view.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
// This version describes the schema of JSON UI messages. This version must be
// updated after making any changes to this view, the jsonHook, or any of the
// command/views/json package.
const JSON_UI_VERSION = "1.0"
const JSON_UI_VERSION = "1.1"

func NewJSONView(view *View) *JSONView {
log := hclog.New(&hclog.LoggerOptions{
Expand Down
1 change: 0 additions & 1 deletion internal/command/views/refresh_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ func TestRefreshJSON_outputs(t *testing.T) {
},
"password": map[string]interface{}{
"sensitive": true,
"value": "horse-battery",
"type": "string",
},
},
Expand Down

0 comments on commit a5926f1

Please sign in to comment.