Skip to content

add module arg corresponding to cli refresh flag #168

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

smemsh
Copy link

@smemsh smemsh commented Jan 21, 2025

This patch adds -refresh=true to the plan generation command line (which is the default if not specified), and adds a module argument refresh with default true value, so user can override and make sure resources are not refreshed for a specific module run. This way, plan can be called with -refresh=false when a user knows they want this.

My use case: while implementing an image bake pipeline that uses Terraform to provision and Ansible to configure a node to be imaged, my play ends by cleaning out the cloud-init identity, shutting down the node, and then imaging the node. Unfortunately, the state refresh that happens prior to imaging wakes up the node, and then it can't be imaged. So I have a chicken-egg situation where I cannot plan the imaging step without waking up the node, whereas waking up the node prevents imaging.

Using -refresh=false during plan phase fixes this for my use case. I think it's a valuable flag to expose to other users of the Ansible Terraform module.

Terraform source code has the first reference to -refresh= flag very early, in June 2014, so don't think we need a version check for this.

Copy link

@smemsh smemsh force-pushed the add-refresh-arg branch from 3b013fe to 6a5da75 Compare May 15, 2025 12:44
Copy link

@smemsh
Copy link
Author

smemsh commented May 15, 2025

Rebased to current main tip after the recent release. Can someone please look at this? Don't know who to ping, but I'll try @GomathiselviS maybe?

P.S. did not know what to use for version_added, will change it once someone lets me know. Would it be perhaps 3.0.1 or 3.1.0 ?

@GomathiselviS GomathiselviS requested a review from abikouo May 15, 2025 13:41
Sometimes we want our task to create a plan without the usual implied
state-refresh.  The default behavior of Terraform (either no-arg, or
'-refresh=true') is to always refresh state sources when the plan is
created.  When the user knows better, they can override, as they can
already on cli.
@smemsh smemsh force-pushed the add-refresh-arg branch from 6a5da75 to cfb2cd6 Compare May 15, 2025 13:50
Copy link

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.

2 participants