-1

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? Error

Maya Ray
  • 523
  • 1
  • 7
  • 21
  • 2
    What is your version of that module? `ansible-galaxy collection list | grep community.general`, as it seems that the deprecation of the `-force` parameter has been in the code of the module since quite some time already: https://github.com/ansible-collections/community.general/blob/485834526fda158b20130b7e7ee48a8ac5fa0622/plugins/modules/cloud/misc/terraform.py#L401 – β.εηοιτ.βε Jul 11 '22 at 10:59

1 Answers1

0

It worked after we upgraded our ansible version as the old version didn't have the latest terraform version changes

Maya Ray
  • 523
  • 1
  • 7
  • 21