Debian Codegraph @

ansible_collections/community/general/tests/integration/targets/terraform/tasks/main.yml

raw
1 ---
2 # Copyright (c) Ansible Project
3 # GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
4 # SPDX-License-Identifier: GPL-3.0-or-later
5
6
7 # This block checks and registers Terraform version of the binary found in path.
8
9 - name: Check for existing Terraform in path
10 block:
11 - name: Check if terraform is present in path
12 ansible.builtin.command: "command -v terraform"
13 register: terraform_binary_path
14 ignore_errors: true
15
16 - name: Check Terraform version
17 ansible.builtin.command: terraform version
18 register: terraform_version_output
19 when: terraform_binary_path.rc == 0
20
21 - name: Set terraform version
22 ansible.builtin.set_fact:
23 terraform_version_installed: "{{ terraform_version_output.stdout | regex_search('(?!Terraform.*v)([0-9]+\\.[0-9]+\\.[0-9]+)') }}"
24 when: terraform_version_output.changed
25
26 # This block handles the tasks of installing the Terraform binary. This happens if there is no existing
27 # terraform in $PATH OR version does not match `terraform_version`.
28
29 - name: Execute Terraform install tasks
30 block:
31
32 - name: Install Terraform
33 ansible.builtin.debug:
34 msg: "Installing terraform {{ terraform_version }}, found: {{ terraform_version_installed | default('no terraform binary found') }}."
35
36 - name: Ensure unzip is present
37 ansible.builtin.package:
38 name: unzip
39 state: present
40
41 - name: Install Terraform binary
42 ansible.builtin.unarchive:
43 src: "{{ terraform_url }}"
44 dest: "{{ remote_tmp_dir }}"
45 mode: "0755"
46 remote_src: true
47 validate_certs: "{{ validate_certs }}"
48
49 when: terraform_version_installed is not defined or terraform_version_installed != terraform_version
50
51 # This sets `terraform_binary_path` to coalesced output of first non-empty string in this order:
52 # path from the 'Check if terraform is present in path' task, and lastly, the fallback path.
53
54 - name: Set path to terraform binary
55 ansible.builtin.set_fact:
56 terraform_binary_path: "{{ terraform_binary_path.stdout or remote_tmp_dir ~ '/terraform' }}"
57
58 - name: Loop over provider upgrade test tasks
59 ansible.builtin.include_tasks: test_provider_upgrade.yml
60 vars:
61 tf_provider: "{{ terraform_provider_versions[provider_index] }}"
62 loop: "{{ terraform_provider_versions }}"
63 loop_control:
64 index_var: provider_index
65
66 - name: Test Complex Variables
67 ansible.builtin.include_tasks: complex_variables.yml