Skip to content

Conversation

bbasata
Copy link
Collaborator

@bbasata bbasata commented Mar 31, 2025

Internally, resource.getState trades a tfjson.State struct for a terraform.InstanceState struct. As discussed in #467 (comment), it would be super helpful to operate on the tfjson struct without translation.

This pull request adds a return value to this unexported function. So this PR is a refactoring with no functional changes. I've added one logging statement to make the compiler and linter happy that there are no unused variables or parameters.

@bbasata bbasata requested a review from a team as a code owner March 31, 2025 17:08
@bbasata bbasata enabled auto-merge (squash) March 31, 2025 17:09
@bbasata
Copy link
Collaborator Author

bbasata commented Mar 31, 2025

Test failures disappeared upon re-running. I will track issues for follow-up.

This is ready for review.

var err error
err = runProviderCommand(ctx, t, func() error {
statePreDestroy, err = getState(ctx, t, wd)
_, statePreDestroy, err = getState(ctx, t, wd)
Copy link
Contributor

Choose a reason for hiding this comment

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

Subtle difference to keep track of, good thing the IDE helps

}

// TODO: this statement is a placeholder -- it simply prevents stateJSON from being unused
logging.HelperResourceTrace(ctx, fmt.Sprintf("State before import: values %v", stateJSON.Values != nil))
Copy link
Contributor

Choose a reason for hiding this comment

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

I should also use placeholders more

// Explicitly ensure prior state exists before refresh.
err = runProviderCommand(ctx, t, func() error {
_, err = getState(ctx, t, wd)
_, _, err = getState(ctx, t, wd)
Copy link
Contributor

Choose a reason for hiding this comment

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

Kind of funny to look at

@bbasata bbasata merged commit b3a26dc into main Apr 1, 2025
39 checks passed
@bbasata bbasata deleted the get-state-json branch April 1, 2025 20:19
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 1, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants