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

helper/resource: Refresh during plan rather than separately and remove state shimming when possible #223

Merged
merged 3 commits into from
Nov 29, 2023

Conversation

bflad
Copy link
Contributor

@bflad bflad commented Nov 22, 2023

Reference: hashicorp/terraform-plugin-sdk#515
Reference: #194
Reference: #222
Reference: https://developer.hashicorp.com/terraform/cli/commands/refresh

This change replaces the usage of explicit refresh commands by instead calling the next command with the relevant refresh flags. Separating the refresh from plan was previously done with the idea that the testing logic may introduce further assertion hooks based on that explicit refresh. Over time though, the Terraform recommendations for refreshing and planning have solidified around always recommending to use a plan with behavior changing flags as necessary. Even the Terraform CLI implementation of the refresh command itself has been shifted to call a plan with special flags.

This should reduce testing times decently as it means that the testing logic will skip spinning up and tearing down any relevant providers two times per TestStep and whatever time would be associated with Terraform CLI loading for those commands. Comparing the testing performed across this Go module:

Prior: TF_ACC=1 go test -count=1 ./... 111.07s user 59.37s system 233% cpu 1:12.99 total
Now: TF_ACC=1 go test -count=1 ./... 90.81s user 48.25s system 229% cpu 1:00.54 total

The separated refresh also prevented PreApply plan checks from catching certain situations because the refreshed state could cause the plan to be missing changes.

…e state shimming when possible

Reference: hashicorp/terraform-plugin-sdk#515
Reference: #194
Reference: #222
Reference: https://developer.hashicorp.com/terraform/cli/commands/refresh

This change replaces the usage of explicit refresh commands by instead calling the next command with the relevant refresh flags. Separating the refresh from plan was previously done with the idea that the testing logic may introduce further assertion hooks based on that explicit refresh. Over time though, the Terraform recommendations for refreshing and planning have solidified around always recommending to use a plan with behavior changing flags as necessary. Even the Terraform CLI implementation of the refresh command itself has been shifted to call a plan with special flags.

This should reduce testing times decently as it means that the testing logic will skip spinning up and tearing down any relevant providers two times per `TestStep` and whatever time would be associated with Terraform CLI loading for those commands. Comparing the testing performed across this Go module:

Prior: `TF_ACC=1 go test -count=1 ./...  111.07s user 59.37s system 233% cpu 1:12.99 total`
Now: `TF_ACC=1 go test -count=1 ./...  90.81s user 48.25s system 229% cpu 1:00.54 total`

The separated refresh also prevented `PreApply` plan checks from catching certain situations because the refreshed state could cause the plan to be missing changes.
@bflad bflad requested a review from a team as a code owner November 22, 2023 16:51
@bflad bflad added the enhancement New feature or request label Nov 22, 2023
Copy link
Contributor

@bendbennett bendbennett left a comment

Choose a reason for hiding this comment

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

LGTM 🚀

@bflad bflad added this to the v1.6.0 milestone Nov 27, 2023
@bflad bflad self-assigned this Nov 27, 2023
@bflad
Copy link
Contributor Author

bflad commented Nov 27, 2023

If they have time, I'm soliciting a hashicorp/aws acceptance test run with this change before merging to feel even more confident about it.

@bflad
Copy link
Contributor Author

bflad commented Nov 29, 2023

If any bugs are caused by this change, please open a bug report and we will take a look.

@bflad bflad merged commit f256ef9 into main Nov 29, 2023
26 checks passed
@bflad bflad deleted the bflad/remove-refresh branch November 29, 2023 19:27
bflad added a commit that referenced this pull request Dec 26, 2023
Reference: #223
Reference: #237
Reference: #256

Post-release update to the v1.6.0 CHANGELOG to capture now-known situations that would affect existing provider testing. This update ensures developers upgrading to v1.6.0 will receive the latest guidance and the guidance will remain for this version after future releases. If approved and merged, the v1.6.0 GitHub Release description will also be updated with the same additional content.
bflad added a commit that referenced this pull request Dec 28, 2023
Reference: #223
Reference: #237
Reference: #256

Post-release update to the v1.6.0 CHANGELOG to capture now-known situations that would affect existing provider testing. This update ensures developers upgrading to v1.6.0 will receive the latest guidance and the guidance will remain for this version after future releases. If approved and merged, the v1.6.0 GitHub Release description will also be updated with the same additional content.
Copy link

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 30, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants