mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
Merge pull request #71 from opentffoundation/update-json-format
This commit is contained in:
commit
36b43c7c28
internal/command/jsonformat
@ -1,10 +1,10 @@
|
||||
# jsonformat
|
||||
|
||||
This package contains functionality around formatting and displaying the JSON
|
||||
structured output produced by adding the `-json` flag to various Terraform
|
||||
structured output produced by adding the `-json` flag to various OpenTF
|
||||
commands.
|
||||
|
||||
## Terraform Structured Plan Renderer
|
||||
## OpenTF Structured Plan Renderer
|
||||
|
||||
As of January 2023, this package contains only a single structure: the
|
||||
`Renderer`.
|
||||
@ -32,7 +32,7 @@ concerned with the complex diff calculations.
|
||||
The `differ` package operates on `Change` objects. These are produced from
|
||||
`jsonplan.Change` objects (which are produced by the `opentf show` command).
|
||||
Each `jsonplan.Change` object represents a single resource within the overall
|
||||
Terraform configuration.
|
||||
OpenTF configuration.
|
||||
|
||||
The `differ` package will iterate through the `Change` objects and produce a
|
||||
single `Diff` that represents a processed summary of the changes described by
|
||||
|
@ -2,7 +2,7 @@
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
// Package computed contains types that represent the computed diffs for
|
||||
// Terraform blocks, attributes, and outputs.
|
||||
// OpenTF blocks, attributes, and outputs.
|
||||
//
|
||||
// Each Diff struct is made up of a renderer, an action, and a boolean
|
||||
// describing the diff. The renderer internally holds child diffs or concrete
|
||||
|
@ -2743,7 +2743,7 @@ func TestSpecificCases(t *testing.T) {
|
||||
}, nil, nil, nil, nil, plans.Create, false),
|
||||
},
|
||||
|
||||
// The following tests are from issue 33472. Basically Terraform allows
|
||||
// The following tests are from issue 33472. Basically OpenTF allows
|
||||
// callers to treat numbers as strings in references and expects us
|
||||
// to coerce the strings into numbers. For example the following are
|
||||
// equivalent.
|
||||
|
@ -26,7 +26,7 @@ func computeAttributeDiffAsList(change structured.Change, elementType cty.Type)
|
||||
// we just treat all children of a relevant list or set as also
|
||||
// relevant.
|
||||
//
|
||||
// Interestingly the terraform plan builder also agrees with this, and
|
||||
// Interestingly the opentf plan builder also agrees with this, and
|
||||
// never sets relevant attributes beneath lists or sets. We're just
|
||||
// going to enforce this logic here as well. If the collection is
|
||||
// relevant (decided elsewhere), then every element in the collection is
|
||||
|
@ -90,7 +90,7 @@ func processSet(change structured.Change, process func(value structured.Change))
|
||||
// we just treat all children of a relevant list or set as also
|
||||
// relevant.
|
||||
//
|
||||
// Interestingly the terraform plan builder also agrees with this, and
|
||||
// Interestingly the opentf plan builder also agrees with this, and
|
||||
// never sets relevant attributes beneath lists or sets. We're just
|
||||
// going to enforce this logic here as well. If the collection is
|
||||
// relevant (decided elsewhere), then every element in the collection is
|
||||
|
@ -108,7 +108,7 @@ func (opts JsonOpts) processArray(change structured.ChangeSlice) computed.Diff {
|
||||
// we just treat all children of a relevant list as also relevant, so we
|
||||
// ignore the relevant attributes field.
|
||||
//
|
||||
// Interestingly the terraform plan builder also agrees with this, and
|
||||
// Interestingly the opentf plan builder also agrees with this, and
|
||||
// never sets relevant attributes beneath lists or sets. We're just
|
||||
// going to enforce this logic here as well. If the list is relevant
|
||||
// (decided elsewhere), then every element in the list is also relevant.
|
||||
|
@ -85,7 +85,7 @@ type Renderer struct {
|
||||
func (renderer Renderer) RenderHumanPlan(plan Plan, mode plans.Mode, opts ...plans.Quality) {
|
||||
if incompatibleVersions(jsonplan.FormatVersion, plan.PlanFormatVersion) || incompatibleVersions(jsonprovider.FormatVersion, plan.ProviderFormatVersion) {
|
||||
renderer.Streams.Println(format.WordWrap(
|
||||
renderer.Colorize.Color("\n[bold][red]Warning:[reset][bold] This plan was generated using a different version of Terraform, the diff presented here may be missing representations of recent features."),
|
||||
renderer.Colorize.Color("\n[bold][red]Warning:[reset][bold] This plan was generated using a different version of OpenTF, the diff presented here may be missing representations of recent features."),
|
||||
renderer.Streams.Stdout.Columns()))
|
||||
}
|
||||
|
||||
@ -95,7 +95,7 @@ func (renderer Renderer) RenderHumanPlan(plan Plan, mode plans.Mode, opts ...pla
|
||||
func (renderer Renderer) RenderHumanState(state State) {
|
||||
if incompatibleVersions(jsonstate.FormatVersion, state.StateFormatVersion) || incompatibleVersions(jsonprovider.FormatVersion, state.ProviderFormatVersion) {
|
||||
renderer.Streams.Println(format.WordWrap(
|
||||
renderer.Colorize.Color("\n[bold][red]Warning:[reset][bold] This state was retrieved using a different version of Terraform, the state presented here maybe missing representations of recent features."),
|
||||
renderer.Colorize.Color("\n[bold][red]Warning:[reset][bold] This state was retrieved using a different version of OpenTF, the state presented here maybe missing representations of recent features."),
|
||||
renderer.Streams.Stdout.Columns()))
|
||||
}
|
||||
|
||||
|
@ -177,13 +177,13 @@ func (p *PathMatcher) GetChildWithIndex(index int) Matcher {
|
||||
continue
|
||||
}
|
||||
|
||||
// Terraform actually allows user to provide strings into indexes as
|
||||
// OpenTF actually allows user to provide strings into indexes as
|
||||
// long as the string can be interpreted into a number. For example, the
|
||||
// following are equivalent and we need to support them.
|
||||
// - test_resource.resource.list[0].attribute
|
||||
// - test_resource.resource.list["0"].attribute
|
||||
//
|
||||
// Note, that Terraform will raise a validation error if the string
|
||||
// Note, that OpenTF will raise a validation error if the string
|
||||
// can't be coerced into a number, so we will panic here if anything
|
||||
// goes wrong safe in the knowledge the validation should stop this from
|
||||
// happening.
|
||||
@ -196,13 +196,13 @@ func (p *PathMatcher) GetChildWithIndex(index int) Matcher {
|
||||
case string:
|
||||
f, err := strconv.ParseFloat(val, 64)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("found invalid type within path (%v:%T), the validation shouldn't have allowed this to happen; this is a bug in Terraform, please report it", val, val))
|
||||
panic(fmt.Errorf("found invalid type within path (%v:%T), the validation shouldn't have allowed this to happen; this is a bug in OpenTF, please report it", val, val))
|
||||
}
|
||||
if int(f) == index {
|
||||
child.Paths = append(child.Paths, path[1:])
|
||||
}
|
||||
default:
|
||||
panic(fmt.Errorf("found invalid type within path (%v:%T), the validation shouldn't have allowed this to happen; this is a bug in Terraform, please report it", val, val))
|
||||
panic(fmt.Errorf("found invalid type within path (%v:%T), the validation shouldn't have allowed this to happen; this is a bug in OpenTF, please report it", val, val))
|
||||
}
|
||||
}
|
||||
return child
|
||||
|
Loading…
Reference in New Issue
Block a user