Skip to content
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

allow resources exclusion if required #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
9 changes: 9 additions & 0 deletions main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,14 @@
name: terraform_environment
tasks_from: prepare

- name: exclude resources if required
import_role:
name: exclude_resources
tasks_from: exclude_resources
when:
- excluded_resources is defined
- terraform_plan_state == 'absent'

- name: Execute Terraform Plan
import_role:
name: terraform_environment
Expand Down Expand Up @@ -133,3 +141,4 @@
{{ msg.split('STRING_TO_SPLIT') }}
{%- endif -%}
failed_when: terraform_plan_execution is failed

6 changes: 6 additions & 0 deletions plugin.spec
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,9 @@ subparsers:
help: |
List of files containing terraform backend configuration.
ansible_variable: 'terraform_backend_config_files'
exclude-resources:
type: Value
help: |
A string that specifies resources to exclude from deletion.
ansible_variable: 'excluded_resources'

5 changes: 5 additions & 0 deletions roles/exclude_resources/tasks/exclude_resources.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---

- name: remove resources from plan to exclude them from delete
command: terraform state rm "{{ excluded_resources }}"