Issue between ansible 2.10.15 with terraform 1.0.x


I was using terraform 0.14.9 and ansible 2.10.15 to create ressources.
it’s working well !

I install the last terraform version (1.0.9) and it seems that there is an issue with the terraform module inside ansible & the “terraform validate” part.

Here my ansible code to launch terraform (work perfectly with terraform 0.14.x).

- name: Apply Terraform for OS creation
    binary_path: "/usr/bin/terraform"
    project_path: "{{ playbook_dir }}/roles/os/terraform"
    force_init: yes
    variables_file: "{{ playbook_dir }}/vars/os/{{ reg }}/common.tfvars"
      week_number: "{{ week_number }}"
  when: ope == "create"

With terraform 1.0.9, i have this issue now :

fatal: [localhost]: FAILED! => {"changed": false, **"cmd": “/usr/bin/terraform validate -var week_number=43 -var-file /home/test-user/test-Terraform/vars/os/paris/common.tfvars”

- Error: Failed to parse command-line flags flag provided but not defined: -var
- Error: Too many command line arguments Expected at most one positional argument. For more help on using this command, run: terraform validate -help, "rc": 1, "stderr": Failed to parse command-line flags flag provided but not defined: -var

It seems that the error is coming from the “terraform validate” that dont take “-var” or “-var-file” as parameter since 0.15.x release, but ansible still try to apply it.

Is there a way to bypass/correct this evolution ?

Thanks for your help.


Hi @antoine.granger,

It’s correct that terraform validate doesn’t accept variables. Input variables are part of the planning options and thus only meaningful when creating a plan.

As far as I can tell from what you’ve shared, this issue seems to be in whatever component is responsible for building this command line, and I’m not super familiar with Ansible but I’m guessing what you’re using here is the “terraform” module in Ansible. Is that right?

From what I can tell, that module itself is not available in the latest version of Ansible and so I wasn’t able to find the source code for the version you’re running, but I did find what seems to be its replacement – community.general.terraform – and can see in its source code some logic that seems to be intending to handle this change where Terraform switched from ignoring to actually rejecting variable arguments on terraform validate:

With that said then, it seems like the best answer here would be to upgrade to a newer version of that Ansible module that is compatible with Terraform v1.0.


Hello @apparentlymart,

I replaced the terraform: module by the community.general.terraform: and it works fine now.

Thank you