Skip to content

Commit

Permalink
add replace parameter to terraform_apply module
Browse files Browse the repository at this point in the history
  • Loading branch information
mschuchard committed Mar 4, 2025
1 parent 12072a8 commit 694ad0a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
### 1.2.1 (Next)
- General code improvements.
- Improve `changed` detection for `terraform_fmt` module.
- Add `replace` parameter to `terraform_apply` module.
- Add `diff` and `write` parameters to `packer_fmt` module.

### 1.2.0
Expand Down
1 change: 1 addition & 0 deletions plugins/module_utils/terraform.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
# dictionary that maps input args to terraform args
ARGS_MAP: Final[dict[str, dict[str, str]]] = dict({
'apply': {
'replace': '',
'target': '',
'var': '',
'var_file': '',
Expand Down
8 changes: 8 additions & 0 deletions plugins/modules/terraform_apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
description: Location of the output file generated during a plan. Mutually exclusive with all other parameters since the parameters are all defined instead during the plan execution.
required: false
type: path
replace:
description: Force replacement of a particular resource instance using its resource address. If the plan would normally produce an update or no-op action for this instance, then Terraform will plan to replace it instead.
required: false
type: list
target:
description: Limit the applying operation to only the given module, resource, or resource instance, and all of its dependencies.
required: false
Expand Down Expand Up @@ -97,6 +101,7 @@ def main() -> None:
'config_dir': {'type': 'path', 'required': False, 'default': Path.cwd()},
'destroy': {'type': 'bool', 'required': False},
'plan_file': {'type': 'path', 'required': False},
'replace': {'type': 'list', 'required': False},
'target': {'type': 'list', 'required': False},
'var': {'type': 'list', 'required': False},
'var_file': {'type': 'list', 'required': False}
Expand All @@ -108,6 +113,7 @@ def main() -> None:
# initialize
changed: bool = True
config_dir: Path = Path(module.params.get('config_dir'))
replace: list[str] = module.params.get('replace')
target: list[str] = module.params.get('target')
var: list[dict] = module.params.get('var')
var_file: list[Path] = module.params.get('var_file')
Expand All @@ -128,6 +134,8 @@ def main() -> None:
# check args
args: dict = {}
# ruff complains so default should protect against falsey with None
if replace:
args.update({'replace': replace})
if target:
args.update({'target': target})
if var:
Expand Down

0 comments on commit 694ad0a

Please sign in to comment.