Skip to content

Commit

Permalink
Merge pull request #31235 from hashicorp/alisdair/json-plan-unknown-o…
Browse files Browse the repository at this point in the history
…utputs

json-output: Extended detail for unknown outputs
  • Loading branch information
alisdair committed Jun 17, 2022
2 parents 7fcf973 + 48d64ea commit c7bc82b
Show file tree
Hide file tree
Showing 3 changed files with 128 additions and 2 deletions.
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"
}
}
}
}
}
}

0 comments on commit c7bc82b

Please sign in to comment.