I create Azure resources using ansible playbook which triggers terraform code. I want to destroy the resources. Below is the code for creation and destroy.
Create
- block:
- name: Run virtual-machine terraform - Planned
terraform:
project_path: xxxx
state: planned
force_init: true
plan_file: "xxxx.plan"
backend_config:
resource_group_name: "rg-poc-automation"
storage_account_name: "smartopsazureautomation"
container_name: "terraformstatefile"
key: "{{ _customer }}-{{ enviornment }}-vm-config.tfstate"
- name: Run virtual-machine terraform - Present
terraform:
project_path: xxxxx
state: present
force_init: true
plan_file: "xxxxx.plan"
backend_config:
resource_group_name: "rg-poc-automation"
storage_account_name: "smartopsazureautomation"
container_name: "terraformstatefile"
key: "{{ _customer }}-{{ enviornment }}-vm-config.tfstate"
Destroy
- block:
- name: Run virtual-machine terraform - Absent
terraform:
project_path: xxxxx
state: absent
force_init: false
plan_file: "xxxx.plan"
backend_config:
resource_group_name: "rg-poc-automation"
storage_account_name: "smartopsazureautomation"
container_name: "terraformstatefile"
key: "{{ _customer }}-{{ enviornment }}-vm-config.tfstate"
environment: "{{ env }}"
We get the below error while destroy. This is because of terraform latest version has decprecated -force and playbook is somehow taking it. Is there any way around it or any solution to this?
It worked after we upgraded our ansible version as the old version didn't have the latest terraform version changes