Skip to main content
Terraform Utility Modules 0.10.5Last updated in version 0.10.5

Executable Dependency

View Source Release Notes

This is a module that can be used to check if an executable is already installed, and if it's not, download it from a URL. This is useful if your Terraform code has an external dependency and you want that dependency to be auto installed if it's not installed already: e.g., terraform-aws-eks expects the kubergrunt binary to be installed, and executable-dependency allows terraform-aws-eks to automatically download kubergrunt if it's not already available.

NOTE: This module requires that Python 3 is installed on your system.

Example code

See the executable-dependency example for working sample code.

Usage

Use the module in your Terraform code, replacing <VERSION> with the latest version from the releases page:

module "path" {
source = "git::git@github.com:gruntwork-io/terraform-aws-utilities.git//modules/executable-dependency?ref=<VERSION>"

executable = "kubergrunt"
download_url = "https://github.com/gruntwork-io/kubergrunt/releases/download/v0.5.13/kubergrunt"
append_os_arch = true
}

The arguments to pass are:

  • executable: The executable to look for on the system PATH and in install_dir. If not found, this executable will be downloaded from download_url.

  • download_url: The URL to download the executable from if executable is not found on the system PATH or install_dir.

  • append_os_arch: If set to true, append the operating system and architecture to the URL. E.g., Append linux_amd64 if this code is being run on a 64 bit Linux OS. This is useful to download the proper binary (specifically, a binary using the Go naming conventions) for the current operating system and CPU.

  • install_dir: The folder to copy the executable to after downloading it from download_url. If set to null (the default), the executable will be copied to a folder in the system temp directory. The folder will be named based on an md5 hash of download_url, so for each download_url, the executable will only have to be downloaded once.

This module has a single output, executable_path, which is the path you should use to run the executable. The value will either be the path of the executable on the system PATH or a path in install_dir.

Sample Usage

main.tf

# ------------------------------------------------------------------------------------------------------
# DEPLOY GRUNTWORK'S EXECUTABLE-DEPENDENCY MODULE
# ------------------------------------------------------------------------------------------------------

module "executable_dependency" {

source = "git::git@github.com:gruntwork-io/terraform-aws-utilities.git//modules/executable-dependency?ref=v0.10.5"

# ----------------------------------------------------------------------------------------------------
# REQUIRED VARIABLES
# ----------------------------------------------------------------------------------------------------

# The URL to download the executable from if var.executable is not found on
# the system PATH or in var.install_dir.
download_url = <string>

# The executable to look for on the system PATH and in var.install_dir. If not
# found, this executable will be downloaded from var.download_url.
executable = <string>

# ----------------------------------------------------------------------------------------------------
# OPTIONAL VARIABLES
# ----------------------------------------------------------------------------------------------------

# If set to true, append the operating system and architecture to the URL.
# E.g., Append linux_amd64 if this code is being run on a 64 bit Linux OS.
append_os_arch = true

# Set to false to have disable this module, so it does not try to download the
# executable, and always returns its path unchanged. This weird parameter
# exists solely because Terraform does not support conditional modules.
# Therefore, this is a hack to allow you to conditionally decide if this
# module should run or not.
enabled = true

# The folder to copy the executable to after downloading it from
# var.download_url. If set to null (the default), the executable will be
# copied to a folder in the system temp directory. The folder will be named
# based on an md5 hash of var.download_url, so for each var.download_url, the
# executable will only have to be downloaded once.
install_dir = null

}


Reference

Required

download_urlstringrequired

The URL to download the executable from if executable is not found on the system PATH or in install_dir.

executablestringrequired

The executable to look for on the system PATH and in install_dir. If not found, this executable will be downloaded from download_url.

Optional

append_os_archbooloptional

If set to true, append the operating system and architecture to the URL. E.g., Append linux_amd64 if this code is being run on a 64 bit Linux OS.

true
enabledbooloptional

Set to false to have disable this module, so it does not try to download the executable, and always returns its path unchanged. This weird parameter exists solely because Terraform does not support conditional modules. Therefore, this is a hack to allow you to conditionally decide if this module should run or not.

true
install_dirstringoptional

The folder to copy the executable to after downloading it from download_url. If set to null (the default), the executable will be copied to a folder in the system temp directory. The folder will be named based on an md5 hash of download_url, so for each download_url, the executable will only have to be downloaded once.

null