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

adds ext-state attribute to StateVersion create #416

Merged
merged 1 commit into from Jun 6, 2022

Conversation

brandonc
Copy link
Collaborator

Description

This will be used in future versions of terraform to supply portable state details to the platform

The type, json.RawMessage, is defined as "a raw encoded JSON value. It implements Marshaler and Unmarshaler and can be used to delay JSON decoding or precompute a JSON encoding."

The encoding of the attribute is meant to be "any json object" and the backend does some basic validation on the message (it must have both "format_version" and "values" attributes.)

Testing plan

Output from tests

Including output from tests may require access to a TFE instance. Ignore this section if you have no environment to test against.

$ TF_ACC=1 go test ./... -v -tags integration -run TestStateVersionsCreate

=== RUN   TestStateVersionsCreate
=== RUN   TestStateVersionsCreate/with_valid_options
=== RUN   TestStateVersionsCreate/with_external_state_representation
=== RUN   TestStateVersionsCreate/with_the_force_flag_set
=== RUN   TestStateVersionsCreate/with_a_run_to_associate_with
    state_version_integration_test.go:245: This can only be tested with the run specific token
=== RUN   TestStateVersionsCreate/without_md5_hash
=== RUN   TestStateVersionsCreate/withous_serial
=== RUN   TestStateVersionsCreate/without_state
=== RUN   TestStateVersionsCreate/with_invalid_workspace_id
--- PASS: TestStateVersionsCreate (17.07s)
    --- PASS: TestStateVersionsCreate/with_valid_options (3.59s)
    --- PASS: TestStateVersionsCreate/with_external_state_representation (3.48s)
    --- PASS: TestStateVersionsCreate/with_the_force_flag_set (4.18s)
    --- SKIP: TestStateVersionsCreate/with_a_run_to_associate_with (0.00s)
    --- PASS: TestStateVersionsCreate/without_md5_hash (0.00s)
    --- PASS: TestStateVersionsCreate/withous_serial (0.00s)
    --- PASS: TestStateVersionsCreate/without_state (0.00s)
    --- PASS: TestStateVersionsCreate/with_invalid_workspace_id (0.00s)
PASS

This will be used in future versions of terraform to supply portable state details to the platform
// https://www.terraform.io/internals/json-format#state-representation
// Supplying this state representation can provide more details to the platform
// about the current terraform state.
ExtState json.RawMessage `jsonapi:"attr,ext-state,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

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

What happens if there is an error in the JSON?

Copy link
Contributor

@annawinkler annawinkler 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 straight-forward, but I have one question that I'm curious about 🤔 (see the comment)

Copy link
Contributor

@sebasslash sebasslash left a comment

Choose a reason for hiding this comment

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

Changes look good. One question: where would I be able to fetch the external state representation? Is it available in DownloadURL?

@brandonc
Copy link
Collaborator Author

brandonc commented Jun 3, 2022

@sebasslash no. At first, it won't be available for consumption in the public API and will be added only to the state parser internal API for use on the platform. Over time, as other useful features are identified, it can become a new download url on the state version resource.

@brandonc
Copy link
Collaborator Author

brandonc commented Jun 3, 2022

@annawinkler If the error makes the json unparsable, the API will return a bad request response with details (BaseController L56). I don't think it's worthwhile to try and parse it all in this library as a validation.

Copy link
Contributor

@annawinkler annawinkler left a comment

Choose a reason for hiding this comment

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

:shipit:

@brandonc brandonc merged commit 80dcb17 into main Jun 6, 2022
@brandonc brandonc deleted the brandonc/state_versions_ext_state branch June 6, 2022 21:36
@github-actions
Copy link

github-actions bot commented Jun 6, 2022

Reminder to the contributor that merged this PR: if your changes have added important functionality or fixed a relevant bug, open a follow-up PR to update CHANGELOG.md with a note on your changes.

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.

None yet

3 participants