Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions changelogs/changelog.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -186,3 +186,24 @@ releases:
- 20250630-terraform-review-workspace-logic.yaml
- release_summary.yml
release_date: '2025-07-11'
4.0.1:
changes:
breaking_changes:
- terraform - The default value `default` for the `workspace` argument has been
removed (https://github.com/ansible-collections/cloud.terraform/pull/200).
bugfixes:
- inventory/terraform_state - Add support for remote/cloud backends (https://github.com/ansible-collections/cloud.terraform/issues/150).
- inventory/terraform_state - use ``terraform pull`` instead of ``terraform
show`` to parse raw state file to avoid provider versioning constraints (https://github.com/ansible-collections/cloud.terraform/issues/151).
minor_changes:
- inventory/terraform_state - Support for custom Terraform providers (https://github.com/ansible-collections/cloud.terraform/pull/146).
- terraform - Update module logic to determine workspace (https://github.com/ansible-collections/cloud.terraform/pull/200).
release_summary: This major release updates the workspace logic for the Terraform
module and adds some bug fixes.
fragments:
- 20240620-inventory-terraform_state-fix-issue-with-terraform-show.yaml
- 20240628-inventory-terraform_state-custom-providers.yaml
- 20240731-terraform_state-support-remote-cloud-backend.yml
- 20250630-terraform-review-workspace-logic.yaml
- release_summary.yml
release_date: '2025-07-11'
6 changes: 6 additions & 0 deletions plugins/module_utils/terraform_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def apply_plan(
lock: bool,
lock_timeout: Optional[int],
targets: List[str],
excludes: List[str],
needs_application: bool,
) -> Tuple[str, str, str]:
command = ["apply", "-no-color", "-input=false"]
Expand All @@ -75,6 +76,8 @@ def apply_plan(

for t in targets:
command.extend(["-target", t])
for e in excludes:
command.extend(["-exclude", e])

command.append(plan_file_path)

Expand Down Expand Up @@ -129,6 +132,7 @@ def plan(
self,
target_plan_file_path: str,
targets: List[str],
excludes: List[str],
destroy: bool,
state_args: List[str],
variables_args: List[str],
Expand All @@ -144,6 +148,8 @@ def plan(
]
for t in targets:
command.extend(["-target", t])
for e in excludes:
command.extend(["-exclude", e])
if destroy:
command.append("-destroy")
command.extend(state_args)
Expand Down
13 changes: 13 additions & 0 deletions plugins/modules/terraform.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,14 @@
type: bool
default: false
version_added: 1.0.0
excludes:
description:
- A list of specific resources to exclude in this plan/application. The
resources selected here will also auto-exclude any dependencies.
type: list
default: []
elements: str
version_added: 1.0.0
targets:
description:
- A list of specific resources to target in this plan/application. The
Expand Down Expand Up @@ -462,6 +470,7 @@ def main() -> None:
plan_file=dict(type="path"),
state_file=dict(type="path"),
targets=dict(type="list", elements="str", default=[]),
excludes=dict(type='list', elements='str', default=[]),
lock=dict(type="bool", default=True),
lock_timeout=dict(type="int"),
force_init=dict(type="bool", default=False),
Expand All @@ -475,6 +484,8 @@ def main() -> None:
),
required_if=[("state", "planned", ["plan_file"])],
supports_check_mode=True,
mutually_exclusive=[ ['targets', 'excludes'] ],

)

project_path = module.params.get("project_path")
Expand Down Expand Up @@ -591,6 +602,7 @@ def main() -> None:
plan_result_changed, plan_result_any_destroyed, plan_stdout, plan_stderr = terraform.plan(
target_plan_file_path=plan_file_to_apply,
targets=module.params.get("targets"),
excludes=module.params.get("excludes"),
destroy=state == "absent",
state_args=get_state_args(state_file),
variables_args=variables_args,
Expand Down Expand Up @@ -625,6 +637,7 @@ def main() -> None:
lock=module.params.get("lock", False),
lock_timeout=module.params.get("lock_timeout"),
targets=module.params.get("targets") or [],
excludes=module.params.get("excludes") or [],
needs_application=plan_file_needs_application,
)
except TerraformError as e:
Expand Down
Loading