Skip to content

Commit

Permalink
plugin: Add Default Binaries
Browse files Browse the repository at this point in the history
Adding default binaries that will be used during the execution, users
are no longer forced to provide binaries and checksums if they are
planning to execute from supported architectures (aarch64, x86_64 and
arm64).
Infrared plugin will no longer require user to input `binary-archive-url`
and `binary-archive-sha256-checksum` since they can be parsed.
  • Loading branch information
vkhitrin committed Sep 24, 2022
1 parent 2d74090 commit 6b0ef8e
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 19 deletions.
26 changes: 13 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,19 @@ and `hosts_pattern` is supplied.

## Parameters

| Ansible Variable | Infrared CLI Argument | Description | Default | Ansible Example | Infrared Example |
|----------------------------------|------------------------------------|---------------------------------------------------------------------------------------------------------|---------|-----------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------|
| `hosts_pattern` | `--hosts-pattern` | Ansible hosts string. **Required** | `null` | `undercloud` | `--hosts-pattern="undercloud"` |
| `binary_archive_url` | `--binary-archive-url` | URL to terraform binary archive. **Required** | `null` | `https://releases.hashicorp.com/terraform/1.1.5/terraform_1.1.5_darwin_arm64.zip` | `--binary-archive-url='https://releases.hashicorp.com/terraform/1.1.5/terraform_1.1.5_darwin_arm64.zip'` |
| `binary_archive_sha256_checksum` | `--binary-archive-sha256-checksum` | SHA256 checksum of terraform binary archive. **Required** | `null` | `723363af9524c0897e9a7d871d27f0d96f6aafd11990df7e6348f5b45d2dbe2c.` | `--binary-archive-sha256-checksum='723363af9524c0897e9a7d871d27f0d96f6aafd11990df7e6348f5b45d2dbe2c.'` |
| `terraform_plan_state` | `--state` | Terraform infrastructure state. **Required** **Choices:** `['present', 'absent']` | `null` | `null` | `--state='present'` |
| `terraform_check_mode` | `--project-path` | Checks terraform plan. | `False` | `True` | `--check-mode` |
| `terraform_project_path` | `--project-path` | Path to terraform project containing `main.tf`. **Required** | `null` | `/path/to/project` | `--project-path='/path/to/project'` |
| `terraform_plan_variables` | `--variables` | Dictionary of terraform variables. | `null` | var: 'test' var_two: 'test_two' | `--variables='test:test,test2:test'` |
| `terraform_plan_variables_files` | `--variables-files` | List of files containing terraform variables. | `null` | - test - test_two | `--variables-files="test1,test2"` |
| `terraform_backend_config` | `--backend-config` | Dictionary of terraform backend configuration. | `null` | var: 'test' var_two: 'test_two' | `--backend-config='test:test,test2:test2'` |
| `terraform_backend_config_files` | `--backend-config-files` | List of files containing terraform backend configuration. | `null` | - test - test_two | `--backend-config-files="test1,test2"` |
| `use_remote_project` | `--use-remote-project` | Do not upload local project to remote host. Only works when `ansible_host` is not equal to `localhost`. | `False` | `True` | |
| Ansible Variable | Infrared CLI Argument | Description | Default | Ansible Example | Infrared Example |
|----------------------------------|------------------------------------|---------------------------------------------------------------------------------------------------------|------------------------------------------|-----------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------|
| `hosts_pattern` | `--hosts-pattern` | Ansible hosts string. **Required** | `loclahost` | `undercloud` | `--hosts-pattern="undercloud"` |
| `binary_archive_url` | `--binary-archive-url` | URL to terraform binary archive. **Required** | Will be parsed based on CPU architecture | `https://releases.hashicorp.com/terraform/1.1.5/terraform_1.1.5_darwin_arm64.zip` | `--binary-archive-url='https://releases.hashicorp.com/terraform/1.1.5/terraform_1.1.5_darwin_arm64.zip'` |
| `binary_archive_sha256_checksum` | `--binary-archive-sha256-checksum` | SHA256 checksum of terraform binary archive. **Required** | Will be parsed based on CPU architecture | `723363af9524c0897e9a7d871d27f0d96f6aafd11990df7e6348f5b45d2dbe2c.` | `--binary-archive-sha256-checksum='723363af9524c0897e9a7d871d27f0d96f6aafd11990df7e6348f5b45d2dbe2c.'` |
| `terraform_plan_state` | `--state` | Terraform infrastructure state. **Required** **Choices:** `['present', 'absent']` | `null` | `null` | `--state='present'` |
| `terraform_check_mode` | `--project-path` | Checks terraform plan. | `False` | `True` | `--check-mode` |
| `terraform_project_path` | `--project-path` | Path to terraform project containing `main.tf`. **Required** | `null` | `/path/to/project` | `--project-path='/path/to/project'` |
| `terraform_plan_variables` | `--variables` | Dictionary of terraform variables. | `null` | var: 'test' var_two: 'test_two' | `--variables='test:test,test2:test'` |
| `terraform_plan_variables_files` | `--variables-files` | List of files containing terraform variables. | `null` | - test - test_two | `--variables-files="test1,test2"` |
| `terraform_backend_config` | `--backend-config` | Dictionary of terraform backend configuration. | `null` | var: 'test' var_two: 'test_two' | `--backend-config='test:test,test2:test2'` |
| `terraform_backend_config_files` | `--backend-config-files` | List of files containing terraform backend configuration. | `null` | - test - test_two | `--backend-config-files="test1,test2"` |
| `use_remote_project` | `--use-remote-project` | Do not upload local project to remote host. Only works when `ansible_host` is not equal to `localhost`. | `False` | `True` | | |

## Usage

Expand Down
28 changes: 24 additions & 4 deletions main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,34 @@
gather_facts: True
run_once: True
vars:
default_binaries:
'x86_64':
binary_url: 'https://releases.hashicorp.com/terraform/1.3.0/terraform_1.3.0_linux_amd64.zip'
sha256_checksum: '380ca822883176af928c80e5771d1c0ac9d69b13c6d746e6202482aedde7d457'
'aarch64':
binary_url: 'https://releases.hashicorp.com/terraform/1.3.0/terraform_1.3.0_linux_arm64.zip'
sha256_checksum: '0a15de6f934cf2217e5055412e7600d342b4f7dcc133564690776fece6213a9a'
'arm64':
binary_url: 'https://releases.hashicorp.com/terraform/1.3.0/terraform_1.3.0_darwin_arm64.zip'
sha256_checksum: '6a3512a1b1006f2edc6fe5f51add9a6e1ef3967912ecf27e66f22e70b9ad7158'
terraform_check_mode: false
use_remote_project: false
remote_execution: false
pre_tasks:
- name: Fail If Binary Archive URL And Checksum Are Not Provided
fail:
msg:
- "Please ensure binary_archive_url and binary_archive_sha256_checksum are provided."
- name: Use Default Binaries If Not Provided By User
block:
- name: Discover Host CPU Arhitecture If Required
debug:
msg:
- "{{ ansible_architecture }}"
- name: Fail If Current CPU Arhitecture Has No Defaults
fail:
msg: "CPU arhitecture '{{ ansible_architecture }}' has no defaults, user input is required"
when: ansible_architecture not in default_binaries.keys()
- name: Set Binaries Variables
set_fact:
binary_archive_url: "{{ default_binaries[ansible_architecture]['binary_url'] }}"
binary_archive_sha256_checksum: "{{ default_binaries[ansible_architecture]['sha256_checksum'] }}"
when:
- binary_archive_url is not defined
- binary_archive_sha256_checksum is not defined
Expand Down
4 changes: 2 additions & 2 deletions plugin.spec
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ subparsers:
URL to the terraform binary.
Every operating system and architecture has its own compiled binary.
Refer to: https://www.terraform.io/downloads
required: True
required: False
ansible_variable: 'binary_archive_url'
binary-archive-sha256-checksum:
type: Value
help: |
SHA256 checksum of terraform binary.
Refer to: https://www.terraform.io/downloads
required: True
required: False
ansible_variable: 'binary_archive_sha256_checksum'

- title: Terraform arguments
Expand Down

0 comments on commit 6b0ef8e

Please sign in to comment.