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

Add support for format versions 1.0 and above #41

Merged
merged 1 commit into from
Sep 14, 2021

Conversation

alisdair
Copy link
Contributor

A future release of Terraform will ship with a 1.0 format version for all stable JSON formats, which will be backwards compatible with the existing format. This will also mark a release where the JSON compatibility guarantee is more clearly defined, and so format versions less than 2.0 should always be backwards compatible with consumers which support 1.0.

This commit prepares for that change by adding support for version constraints rather than supported fixed sets of versions. This is done using the go-version package.

Includes test data from a pre-release of Terraform 1.1 which includes the planned JSON format version changes (this branch).

@radeksimko radeksimko self-requested a review September 13, 2021 15:17
Copy link
Member

@radeksimko radeksimko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks pretty good to me! Thank you for raising the PR.

I left some relatively minor comments in-line.

The next logical step would be perhaps trying it out in the context of terraform-exec where you can run the E2E tests against a custom build via

TFEXEC_E2ETEST_VERSIONS=refs/heads/alisdair/json-format-version-1.0 go test ./tfexec/internal/e2etest/...

go.mod Outdated Show resolved Hide resolved
plan.go Outdated Show resolved Hide resolved
plan.go Outdated Show resolved Hide resolved
schemas.go Outdated Show resolved Hide resolved
schemas.go Outdated Show resolved Hide resolved
state.go Outdated Show resolved Hide resolved
state.go Outdated Show resolved Hide resolved
validate.go Outdated Show resolved Hide resolved
validate.go Outdated Show resolved Hide resolved
testdata/110_basic/.terraform.lock.hcl Show resolved Hide resolved
A future release of Terraform will ship with a 1.0 format version for
all stable JSON formats, which will be backwards compatible with the
existing format. This will also mark a release where the JSON
compatibility guarantee is more clearly defined, and so format versions
less than 2.0 should always be backwards compatible with consumers which
support 1.0.

This commit prepares for that change by adding support for version
constraints rather than supported fixed sets of versions. This is done
using the go-version package.

Includes test data from a pre-release of Terraform 1.1 which includes
the planned JSON format version changes.
@alisdair alisdair force-pushed the terraform-json-version-1.0 branch from d93236f to 5dd30a1 Compare September 14, 2021 17:29
@alisdair
Copy link
Contributor Author

I tried running terraform-exec tests against the relevant branches, and it fails in what I think is a reasonable way:

$ go mod edit -replace github.com/hashicorp/terraform-json=/Users/alisdair/code/terraform-json
$ TFEXEC_E2ETEST_VERSIONS=refs/heads/alisdair/json-format-version-1.0 go test ./tfexec/internal/e2etest/...
2021/09/14 14:21:29
--- FAIL: TestProvidersSchema (1.63s)
    --- FAIL: TestProvidersSchema/0_basic (1.43s)
        --- FAIL: TestProvidersSchema/0_basic/basic-refs/heads/alisdair/json-format-version-1.0 (1.43s)
            util_test.go:112: [INFO] running Terraform command: /var/folders/2p/ys5rmmyd02b4f74gzxlv5nj00000gp/T/tfinstall607081317/gitref-refs-heads-alisdair-json-format-version-1.0/terraform2149754593 init -no-color -force-copy -input=false -backend=true -get=true -upgrade=false
            util_test.go:112: [INFO] running Terraform command: /var/folders/2p/ys5rmmyd02b4f74gzxlv5nj00000gp/T/tfinstall607081317/gitref-refs-heads-alisdair-json-format-version-1.0/terraform2149754593 providers schema -json -no-color
            providers_schema_test.go:324: mismatch (-want +got):
                  &tfjson.ProviderSchemas{
                - 	FormatVersion: "0.2",
                + 	FormatVersion: "1.0",

(and some similar errors).

At first glance it seems like updating those assertions accordingly would be a reasonable step once 1.1 is released.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants