Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

json-output: Extended detail for unknown outputs #31235

Merged
merged 1 commit into from Jun 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 13 additions & 2 deletions internal/command/jsonplan/plan.go
Expand Up @@ -442,7 +442,8 @@ func (p *plan) marshalOutputChanges(changes *plans.Changes) error {
changeV.After, _ = changeV.After.UnmarkDeep()

var before, after []byte
afterUnknown := cty.False
var afterUnknown cty.Value

if changeV.Before != cty.NilVal {
before, err = ctyjson.Marshal(changeV.Before, changeV.Before.Type())
if err != nil {
Expand All @@ -455,8 +456,18 @@ func (p *plan) marshalOutputChanges(changes *plans.Changes) error {
if err != nil {
return err
}
afterUnknown = cty.False
} else {
afterUnknown = cty.True
filteredAfter := omitUnknowns(changeV.After)
if filteredAfter.IsNull() {
after = nil
} else {
after, err = ctyjson.Marshal(filteredAfter, filteredAfter.Type())
if err != nil {
return err
}
}
afterUnknown = unknownAsBool(changeV.After)
}
}

Expand Down
19 changes: 19 additions & 0 deletions internal/command/testdata/show-json/unknown-output/main.tf
@@ -0,0 +1,19 @@
output "foo" {
value = "hello"
}

output "bar" {
value = tolist([
"hello",
timestamp(),
"world",
])
}

output "baz" {
value = {
greeting: "hello",
time: timestamp(),
subject: "world",
}
}
96 changes: 96 additions & 0 deletions internal/command/testdata/show-json/unknown-output/output.json
@@ -0,0 +1,96 @@
{
"format_version": "1.1",
"terraform_version": "1.3.0-dev",
"planned_values": {
"outputs": {
"bar": {
"sensitive": false
},
"baz": {
"sensitive": false
},
"foo": {
"sensitive": false,
"type": "string",
"value": "hello"
}
},
"root_module": {}
},
"output_changes": {
"bar": {
"actions": [
"create"
],
"before": null,
"after": [
"hello",
null,
"world"
],
"after_unknown": [
false,
true,
false
],
"before_sensitive": false,
"after_sensitive": false
},
"baz": {
"actions": [
"create"
],
"before": null,
"after": {
"greeting": "hello",
"subject": "world"
},
"after_unknown": {
"time": true
},
"before_sensitive": false,
"after_sensitive": false
},
"foo": {
"actions": [
"create"
],
"before": null,
"after": "hello",
"after_unknown": false,
"before_sensitive": false,
"after_sensitive": false
}
},
"prior_state": {
"format_version": "1.0",
"terraform_version": "1.3.0",
"values": {
"outputs": {
"foo": {
"sensitive": false,
"value": "hello",
"type": "string"
}
},
"root_module": {}
}
},
"configuration": {
"root_module": {
"outputs": {
"bar": {
"expression": {}
},
"baz": {
"expression": {}
},
"foo": {
"expression": {
"constant_value": "hello"
}
}
}
}
}
}