Skip to content

plan: Introduce -minimal-refresh flag to only refresh resources that have proposed changes - #38953

Open
austinvalle wants to merge 4 commits into
mainfrom
av/targeted-refresh-in-plan
Open

plan: Introduce -minimal-refresh flag to only refresh resources that have proposed changes#38953
austinvalle wants to merge 4 commits into
mainfrom
av/targeted-refresh-in-plan

Conversation

@austinvalle

@austinvalle austinvalle commented Jul 30, 2026

Copy link
Copy Markdown
Member

Closes #35290

This PR introduces a new -minimal-refresh planning option, which will skip refreshing resources that do not produce a change with the given state + configuration.

Notes

  • Each resource instance chooses whether it will refresh in isolation based on it's own plan, so a refresh on one resource will not cause other resources that depend on it to refresh.
  • As providers help determine if a change to a Terraform configuration is meaningful or not during the plan (for example, changing whitespace might be deemed a no-op), this solution uses an initial plan call as the indicator of whether we need to perform the refresh for a particular resource instance. If a change is produced for a resource using this flag, we discard that initial plan, do a refresh, and plan again.
  • If a resource schema is upgraded, we will always refresh to ensure the resource state is fully updated before planning.
  • Destroy plans + deposed/orphaned resources will not refresh using this flag. There is nothing in the plan that could indicate whether a refresh is needed or not, as the main function of this refresh is to potentially remove resources from state that are already deleted. Since this flag is an optimization we opt to always skip 👍🏻

Target Release

1.17.x

Rollback Plan

  • If a change needs to be reverted, we will roll out an update to the code within 7 days.

Changes to Security Controls

Are there any changes to security controls (access controls, encryption, logging) in this pull request? If so, explain.

CHANGELOG entry

  • This change is user-facing and I added a changelog entry.
  • This change is not user-facing.

@austinvalle
austinvalle requested review from a team as code owners July 30, 2026 14:34
createBeforeDestroy bool,
forceReplace bool,
keyData instances.RepetitionData,
suppressSideEffects bool,

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I went with the least impactful change here to try and avoid side effects of calling this plan method multiple times 😅

}

func (*NilHook) PreDiff(id HookResourceIdentity, dk addrs.DeposedKey, priorState, proposedNewState cty.Value, err error) (HookAction, error) {
func (*NilHook) PreDiff(id HookResourceIdentity, dk addrs.DeposedKey, err error) (HookAction, error) {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

These state values were unused in the PreDiff + PostDiff hooks and it was putting us in an awkward spot in internal/terraform/node_resource_plan_instance.go where we want to only call PreDiff once but we're not yet sure if the plan we are running will be the plan we use.

Since it wasn't being used, easy option was to remove it 🧹

@austinvalle
austinvalle force-pushed the av/targeted-refresh-in-plan branch 2 times, most recently from 94e8174 to 3a38cfd Compare August 6, 2026 20:50
@austinvalle austinvalle changed the title plan: Introduce -refresh-on-change flag to only refresh resources that have proposed changes plan: Introduce -minimal-refresh flag to only refresh resources that have proposed changes Aug 6, 2026
))
}

// TODO:@austinvalle: This will eventually be added to HCPT / go-tfe and should be removed

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

👀

@austinvalle
austinvalle force-pushed the av/targeted-refresh-in-plan branch from e678f91 to fe2d1d1 Compare August 7, 2026 13:51
Comment thread internal/terraform/node_resource_plan_instance.go Outdated
Comment thread internal/terraform/node_resource_plan_instance.go Outdated
Comment thread internal/terraform/node_resource_plan_instance.go Outdated
Comment thread internal/terraform/node_resource_plan_instance.go Outdated
@austinvalle
austinvalle requested a review from jbardin August 10, 2026 14:54
@austinvalle
austinvalle force-pushed the av/targeted-refresh-in-plan branch from f09ddaa to f351539 Compare August 10, 2026 14:56
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.

terraform plan -light

2 participants