Skip to content

Commit 694ad0a

Browse files
committed
add replace parameter to terraform_apply module
1 parent 12072a8 commit 694ad0a

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
### 1.2.1 (Next)
22
- General code improvements.
33
- Improve `changed` detection for `terraform_fmt` module.
4+
- Add `replace` parameter to `terraform_apply` module.
45
- Add `diff` and `write` parameters to `packer_fmt` module.
56

67
### 1.2.0

plugins/module_utils/terraform.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
# dictionary that maps input args to terraform args
3939
ARGS_MAP: Final[dict[str, dict[str, str]]] = dict({
4040
'apply': {
41+
'replace': '',
4142
'target': '',
4243
'var': '',
4344
'var_file': '',

plugins/modules/terraform_apply.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@
3030
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.
3131
required: false
3232
type: path
33+
replace:
34+
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.
35+
required: false
36+
type: list
3337
target:
3438
description: Limit the applying operation to only the given module, resource, or resource instance, and all of its dependencies.
3539
required: false
@@ -97,6 +101,7 @@ def main() -> None:
97101
'config_dir': {'type': 'path', 'required': False, 'default': Path.cwd()},
98102
'destroy': {'type': 'bool', 'required': False},
99103
'plan_file': {'type': 'path', 'required': False},
104+
'replace': {'type': 'list', 'required': False},
100105
'target': {'type': 'list', 'required': False},
101106
'var': {'type': 'list', 'required': False},
102107
'var_file': {'type': 'list', 'required': False}
@@ -108,6 +113,7 @@ def main() -> None:
108113
# initialize
109114
changed: bool = True
110115
config_dir: Path = Path(module.params.get('config_dir'))
116+
replace: list[str] = module.params.get('replace')
111117
target: list[str] = module.params.get('target')
112118
var: list[dict] = module.params.get('var')
113119
var_file: list[Path] = module.params.get('var_file')
@@ -128,6 +134,8 @@ def main() -> None:
128134
# check args
129135
args: dict = {}
130136
# ruff complains so default should protect against falsey with None
137+
if replace:
138+
args.update({'replace': replace})
131139
if target:
132140
args.update({'target': target})
133141
if var:

0 commit comments

Comments
 (0)