Skip to content

Commit 36626f7

Browse files
committed
version: Allow parsing of a format_version field, added in v1.17
1 parent f4ef996 commit 36626f7

2 files changed

Lines changed: 34 additions & 0 deletions

File tree

version.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ package tfjson
66
// VersionOutput represents output from the version -json command
77
// added in v0.13
88
type VersionOutput struct {
9+
FormatVersion string `json:"format_version"` // Added in v1.17
10+
911
Version string `json:"terraform_version"`
1012
Revision string `json:"terraform_revision"`
1113
Platform string `json:"platform,omitempty"`

version_test.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,35 @@ func TestVersionOutput_015(t *testing.T) {
6767
t.Fatalf("output mismatch: %s", diff)
6868
}
6969
}
70+
71+
// In TF v1.17 we added the format_version field,
72+
// to match how other static JSON outputs are versioned.
73+
func TestVersionOutput_117(t *testing.T) {
74+
output := `{
75+
"format_version": "1.0",
76+
"terraform_version": "4.5.6-foo",
77+
"platform": "aros_riscv64",
78+
"provider_selections": {
79+
"registry.terraform.io/hashicorp/test1": "7.8.9-beta.2",
80+
"registry.terraform.io/hashicorp/test2": "1.2.3"
81+
},
82+
"terraform_outdated": false
83+
}`
84+
var parsed VersionOutput
85+
if err := json.Unmarshal([]byte(output), &parsed); err != nil {
86+
t.Fatal(err)
87+
}
88+
89+
expected := &VersionOutput{
90+
FormatVersion: "1.0",
91+
Version: "4.5.6-foo",
92+
Platform: "aros_riscv64",
93+
ProviderSelections: map[string]string{
94+
"registry.terraform.io/hashicorp/test1": "7.8.9-beta.2",
95+
"registry.terraform.io/hashicorp/test2": "1.2.3",
96+
},
97+
}
98+
if diff := cmp.Diff(expected, &parsed); diff != "" {
99+
t.Fatalf("output mismatch: %s", diff)
100+
}
101+
}

0 commit comments

Comments
 (0)