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

Allow managing StateVersion and ConfigurationVersion backing data #801

Merged
merged 4 commits into from
Nov 6, 2023

Conversation

mwudka
Copy link
Contributor

@mwudka mwudka commented Nov 1, 2023

Description

Adds support for managing the backing data for state versions and configuration versions.

Testing plan

  1. Ensure tests pass
  2. Write a simple go program that soft deletes, permanently deletes, or restores a state version or configuration version.

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.

$ go test ./... -v -run TestStateVersions
=== RUN   TestStateVersionsList
=== RUN   TestStateVersionsList/without_StateVersionListOptions
=== RUN   TestStateVersionsList/without_list_options
=== RUN   TestStateVersionsList/with_list_options
=== RUN   TestStateVersionsList/without_an_organization
=== RUN   TestStateVersionsList/without_a_workspace
--- PASS: TestStateVersionsList (3.82s)
    --- PASS: TestStateVersionsList/without_StateVersionListOptions (0.00s)
    --- PASS: TestStateVersionsList/without_list_options (0.40s)
    --- PASS: TestStateVersionsList/with_list_options (0.34s)
    --- PASS: TestStateVersionsList/without_an_organization (0.00s)
    --- PASS: TestStateVersionsList/without_a_workspace (0.00s)
=== RUN   TestStateVersionsUpload
=== RUN   TestStateVersionsUpload/can_create_finalized_state_versions
    helper_test.go:1234: Polling state version "sv-3peL2Vh1YwsZmYzj" for status included in ["finalized"] with deadline of 2023-11-02 16:08:41.408598 -0700 PDT m=+36.319620418
    helper_test.go:1241: ...
    helper_test.go:1250: State version "sv-3peL2Vh1YwsZmYzj" had status "finalized"
=== RUN   TestStateVersionsUpload/cannot_provide_base64_state_parameter_when_uploading
=== RUN   TestStateVersionsUpload/RawState_parameter_is_required_when_uploading
--- PASS: TestStateVersionsUpload (5.29s)
    --- PASS: TestStateVersionsUpload/can_create_finalized_state_versions (3.01s)
    --- PASS: TestStateVersionsUpload/cannot_provide_base64_state_parameter_when_uploading (0.00s)
    --- PASS: TestStateVersionsUpload/RawState_parameter_is_required_when_uploading (0.00s)
=== RUN   TestStateVersionsCreate
=== RUN   TestStateVersionsCreate/can_create_pending_state_versions
=== 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:354: This can only be tested with the run specific token
=== RUN   TestStateVersionsCreate/without_md5_hash
=== RUN   TestStateVersionsCreate/without_serial
=== RUN   TestStateVersionsCreate/with_invalid_workspace_id
--- PASS: TestStateVersionsCreate (6.33s)
    --- PASS: TestStateVersionsCreate/can_create_pending_state_versions (0.68s)
    --- PASS: TestStateVersionsCreate/with_valid_options (1.04s)
    --- PASS: TestStateVersionsCreate/with_external_state_representation (1.14s)
    --- PASS: TestStateVersionsCreate/with_the_force_flag_set (1.14s)
    --- SKIP: TestStateVersionsCreate/with_a_run_to_associate_with (0.00s)
    --- PASS: TestStateVersionsCreate/without_md5_hash (0.00s)
    --- PASS: TestStateVersionsCreate/without_serial (0.00s)
    --- PASS: TestStateVersionsCreate/with_invalid_workspace_id (0.00s)
=== RUN   TestStateVersionsRead
=== RUN   TestStateVersionsRead/when_the_state_version_exists
=== RUN   TestStateVersionsRead/when_the_state_version_does_not_exist
=== RUN   TestStateVersionsRead/with_invalid_state_version_id
--- PASS: TestStateVersionsRead (5.80s)
    --- PASS: TestStateVersionsRead/when_the_state_version_exists (3.26s)
    --- PASS: TestStateVersionsRead/when_the_state_version_does_not_exist (0.08s)
    --- PASS: TestStateVersionsRead/with_invalid_state_version_id (0.00s)
=== RUN   TestStateVersionsReadWithOptions
=== RUN   TestStateVersionsReadWithOptions/when_the_state_version_exists
--- PASS: TestStateVersionsReadWithOptions (6.21s)
    --- PASS: TestStateVersionsReadWithOptions/when_the_state_version_exists (0.18s)
=== RUN   TestStateVersionsCurrent
=== RUN   TestStateVersionsCurrent/when_a_state_version_exists
=== RUN   TestStateVersionsCurrent/when_a_state_version_does_not_exist
=== RUN   TestStateVersionsCurrent/with_invalid_workspace_id
--- PASS: TestStateVersionsCurrent (4.70s)
    --- PASS: TestStateVersionsCurrent/when_a_state_version_exists (0.13s)
    --- PASS: TestStateVersionsCurrent/when_a_state_version_does_not_exist (0.10s)
    --- PASS: TestStateVersionsCurrent/with_invalid_workspace_id (0.00s)
=== RUN   TestStateVersionsCurrentWithOptions
=== RUN   TestStateVersionsCurrentWithOptions/when_the_state_version_exists
--- PASS: TestStateVersionsCurrentWithOptions (5.82s)
    --- PASS: TestStateVersionsCurrentWithOptions/when_the_state_version_exists (0.17s)
=== RUN   TestStateVersionsDownload
=== RUN   TestStateVersionsDownload/when_the_state_version_exists
=== RUN   TestStateVersionsDownload/with_an_invalid_url
--- PASS: TestStateVersionsDownload (2.68s)
    --- PASS: TestStateVersionsDownload/when_the_state_version_exists (0.19s)
    --- PASS: TestStateVersionsDownload/with_an_invalid_url (0.08s)
=== RUN   TestStateVersions_ManageBackingData
    state_version_integration_test.go:639: Skipping test related to Terraform Cloud. Set ENABLE_TFE=1 to run.
--- SKIP: TestStateVersions_ManageBackingData (0.00s)
PASS
ok      github.com/hashicorp/go-tfe     (cached)
?       github.com/hashicorp/go-tfe/examples/backing_data       [no test files]
?       github.com/hashicorp/go-tfe/examples/configuration_versions     [no test files]
?       github.com/hashicorp/go-tfe/examples/organizations      [no test files]
?       github.com/hashicorp/go-tfe/examples/registry_modules   [no test files]
?       github.com/hashicorp/go-tfe/examples/run_errors [no test files]
?       github.com/hashicorp/go-tfe/examples/state_versions     [no test files]
?       github.com/hashicorp/go-tfe/examples/users      [no test files]
?       github.com/hashicorp/go-tfe/examples/workspaces [no test files]
?       github.com/hashicorp/go-tfe/mocks       [no test files]

$ go test ./... -v -run TestConfigurationVersions
=== RUN   TestConfigurationVersionsList
=== RUN   TestConfigurationVersionsList/without_list_options
=== RUN   TestConfigurationVersionsList/with_list_options
=== RUN   TestConfigurationVersionsList/without_a_valid_organization
--- PASS: TestConfigurationVersionsList (2.35s)
    --- PASS: TestConfigurationVersionsList/without_list_options (0.30s)
    --- PASS: TestConfigurationVersionsList/with_list_options (0.32s)
    --- PASS: TestConfigurationVersionsList/without_a_valid_organization (0.00s)
=== RUN   TestConfigurationVersionsCreate
=== RUN   TestConfigurationVersionsCreate/with_valid_options
=== RUN   TestConfigurationVersionsCreate/with_invalid_workspace_id
=== RUN   TestConfigurationVersionsCreate/provisional
    configuration_version_integration_test.go:127: 
                Error Trace:    /Users/mwudka/hashicorp/go-tfe/configuration_version_integration_test.go:127
                Error:          Should be true
                Test:           TestConfigurationVersionsCreate/provisional
    configuration_version_integration_test.go:136: 
                Error Trace:    /Users/mwudka/hashicorp/go-tfe/configuration_version_integration_test.go:136
                Error:          Should not be: "cv-vBoMNnwHyTJpspTp"
                Test:           TestConfigurationVersionsCreate/provisional
--- FAIL: TestConfigurationVersionsCreate (2.48s)
    --- PASS: TestConfigurationVersionsCreate/with_valid_options (0.35s)
    --- PASS: TestConfigurationVersionsCreate/with_invalid_workspace_id (0.00s)
    --- FAIL: TestConfigurationVersionsCreate/provisional (0.34s)
=== RUN   TestConfigurationVersionsCreateForRegistryModule
    configuration_version_integration_test.go:141: Skipping test related to a Terraform Cloud beta feature. Set ENABLE_BETA=1 to run.
--- SKIP: TestConfigurationVersionsCreateForRegistryModule (0.00s)
=== RUN   TestConfigurationVersionsRead
=== RUN   TestConfigurationVersionsRead/when_the_configuration_version_exists
=== RUN   TestConfigurationVersionsRead/when_the_configuration_version_does_not_exist
=== RUN   TestConfigurationVersionsRead/with_invalid_configuration_version_id
--- PASS: TestConfigurationVersionsRead (2.58s)
    --- PASS: TestConfigurationVersionsRead/when_the_configuration_version_exists (0.12s)
    --- PASS: TestConfigurationVersionsRead/when_the_configuration_version_does_not_exist (0.07s)
    --- PASS: TestConfigurationVersionsRead/with_invalid_configuration_version_id (0.00s)
=== RUN   TestConfigurationVersionsReadWithOptions
    helper_test.go:904: Export a valid OAUTH_CLIENT_GITHUB_TOKEN before running this test!
--- SKIP: TestConfigurationVersionsReadWithOptions (1.30s)
=== RUN   TestConfigurationVersionsUpload
=== RUN   TestConfigurationVersionsUpload/with_valid_options
=== RUN   TestConfigurationVersionsUpload/without_a_valid_upload_URL
=== RUN   TestConfigurationVersionsUpload/without_a_valid_path
--- PASS: TestConfigurationVersionsUpload (1.94s)
    --- PASS: TestConfigurationVersionsUpload/with_valid_options (0.20s)
    --- PASS: TestConfigurationVersionsUpload/without_a_valid_upload_URL (0.06s)
    --- PASS: TestConfigurationVersionsUpload/without_a_valid_path (0.00s)
=== RUN   TestConfigurationVersionsUploadTarGzip
=== RUN   TestConfigurationVersionsUploadTarGzip/with_custom_go-slug
=== RUN   TestConfigurationVersionsUploadTarGzip/with_custom_tar_archive
--- PASS: TestConfigurationVersionsUploadTarGzip (2.19s)
    --- PASS: TestConfigurationVersionsUploadTarGzip/with_custom_go-slug (0.09s)
    --- PASS: TestConfigurationVersionsUploadTarGzip/with_custom_tar_archive (0.08s)
=== RUN   TestConfigurationVersionsArchive
=== RUN   TestConfigurationVersionsArchive/when_the_configuration_version_exists_and_has_been_uploaded
=== RUN   TestConfigurationVersionsArchive/when_the_configuration_version_does_not_exist
=== RUN   TestConfigurationVersionsArchive/with_invalid_configuration_version_id
--- PASS: TestConfigurationVersionsArchive (3.18s)
    --- PASS: TestConfigurationVersionsArchive/when_the_configuration_version_exists_and_has_been_uploaded (1.08s)
    --- PASS: TestConfigurationVersionsArchive/when_the_configuration_version_does_not_exist (0.08s)
    --- PASS: TestConfigurationVersionsArchive/with_invalid_configuration_version_id (0.00s)
=== RUN   TestConfigurationVersionsDownload
=== RUN   TestConfigurationVersionsDownload/with_a_valid_ID_for_downloadable_configuration_version
=== RUN   TestConfigurationVersionsDownload/with_a_valid_ID_for_a_non_downloadable_configuration_version
=== RUN   TestConfigurationVersionsDownload/with_an_invalid_ID
--- PASS: TestConfigurationVersionsDownload (4.13s)
    --- PASS: TestConfigurationVersionsDownload/with_a_valid_ID_for_downloadable_configuration_version (2.37s)
    --- PASS: TestConfigurationVersionsDownload/with_a_valid_ID_for_a_non_downloadable_configuration_version (1.44s)
    --- PASS: TestConfigurationVersionsDownload/with_an_invalid_ID (0.08s)
=== RUN   TestConfigurationVersions_Unmarshal
--- PASS: TestConfigurationVersions_Unmarshal (0.00s)
=== RUN   TestConfigurationVersions_ManageBackingData
    configuration_version_integration_test.go:477: Skipping test related to Terraform Cloud. Set ENABLE_TFE=1 to run.
--- SKIP: TestConfigurationVersions_ManageBackingData (0.00s)
FAIL
FAIL    github.com/hashicorp/go-tfe     20.798s
?       github.com/hashicorp/go-tfe/examples/backing_data       [no test files]
?       github.com/hashicorp/go-tfe/examples/configuration_versions     [no test files]
?       github.com/hashicorp/go-tfe/examples/organizations      [no test files]
?       github.com/hashicorp/go-tfe/examples/registry_modules   [no test files]
?       github.com/hashicorp/go-tfe/examples/run_errors [no test files]
?       github.com/hashicorp/go-tfe/examples/state_versions     [no test files]
?       github.com/hashicorp/go-tfe/examples/users      [no test files]
?       github.com/hashicorp/go-tfe/examples/workspaces [no test files]
?       github.com/hashicorp/go-tfe/mocks       [no test files]
FAIL

Note: The failing test (TestConfigurationVersionsCreate/provisional) also consistently fails on production, so I don't think it's related to these changes.

@mwudka mwudka force-pushed the mwudka/TF-8621-add-data-retention-policy-support branch from c80cc10 to 3a0a6ae Compare November 1, 2023 20:54
@mwudka mwudka marked this pull request as ready for review November 1, 2023 21:55
@mwudka mwudka requested a review from a team as a code owner November 1, 2023 21:55
brandonc
brandonc previously approved these changes Nov 1, 2023
Copy link
Collaborator

@brandonc brandonc left a comment

Choose a reason for hiding this comment

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

I think the interface is fine as it is. I could imagine these types sharing an interface to simplify your example or adding an error to the example if the specified action was not supported, but these are definitely not blocking feedback.

I didn't run the tests but trust you did!

configuration_version.go Outdated Show resolved Hide resolved
Copy link
Contributor

@nfagerlund nfagerlund left a comment

Choose a reason for hiding this comment

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

Yeah, this looks good. Double-checked the action names in atlas, etc. etc. — I don't see API docs for this yet, but I presume your team's on that elsewhere, yeah?

I'll do the red review for that error name mis-paste, but otherwise this is fine. 👍🏼

configuration_version.go Outdated Show resolved Hide resolved
configuration_version.go Outdated Show resolved Hide resolved
@mwudka mwudka force-pushed the mwudka/TF-8621-add-data-retention-policy-support branch from 3a0a6ae to 70fad6b Compare November 2, 2023 23:06
@mwudka mwudka changed the title Allow managing StateVersion and ConfigurationVersion Allow managing StateVersion and ConfigurationVersion backing data Nov 2, 2023
RestoreBackingData(ctx context.Context, svID string) error

// PermanentlyDeleteBackingData permanently deletes a soft deleted configuration version's backing data
// **Note: This functionality is only available in Terraform Enterprise
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you catch the closing asterisks on the other two of these too? :) Thank you!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops, not sure how I missed that one! I also changed the formatting to match the beta notes.

@mwudka mwudka force-pushed the mwudka/TF-8621-add-data-retention-policy-support branch from 70fad6b to 70dde47 Compare November 4, 2023 00:03
Copy link
Contributor

@nfagerlund nfagerlund left a comment

Choose a reason for hiding this comment

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

👍🏼!

@nfagerlund
Copy link
Contributor

Per conversation in slack, this is ready to merge so I'm merging it.

@nfagerlund nfagerlund merged commit a245d58 into main Nov 6, 2023
10 checks passed
@nfagerlund nfagerlund deleted the mwudka/TF-8621-add-data-retention-policy-support branch November 6, 2023 18:33
Copy link

github-actions bot commented Nov 6, 2023

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