Require Executable Module
This is a module that can be used to ensure particular executables is available in the PATH
. This module will search
the OS PATH
for the provided named executables and validate that it exists, as well as making sure the OS user running
terraform has permissions to run the named executable.
This module will exit with an error if any executable in the list does not exist, printing an error message indicating which executables were missing.
This module uses Python under the hood, so Python must be installed and available on the OS.
Example code
See the require-executable example for working sample code.
Conditional check
Sometimes you might want to guard the check for a required executable on a condition (e.g only check if an executable exists if a particular input flag is set). However, Terraform currently does not support conditional module blocks.
For this reason, this module will accept and noop on empty strings as a workaround. For example, suppose you want to
check if go
is installed based on the condition validate_go
. You can achieve this with the following terraform code:
module "require_executables" {
source = "git::git@github.com:gruntwork-io/terraform-aws-utilities.git//modules/require-executable?ref=v1.0.8"
required_executables = ["${var.validate_go ? "go" : ""}"]
}
Sample Usage
- Terraform
- Terragrunt
# ------------------------------------------------------------------------------------------------------
# DEPLOY GRUNTWORK'S REQUIRE-EXECUTABLE MODULE
# ------------------------------------------------------------------------------------------------------
module "require_executable" {
source = "git::git@github.com:gruntwork-io/terraform-aws-utilities.git//modules/require-executable?ref=v0.10.5"
# ----------------------------------------------------------------------------------------------------
# REQUIRED VARIABLES
# ----------------------------------------------------------------------------------------------------
# A list of named executables that should exist on the OS PATH.
required_executables = <list(string)>
# ----------------------------------------------------------------------------------------------------
# OPTIONAL VARIABLES
# ----------------------------------------------------------------------------------------------------
# Error message to show if the required executable is not found. This is
# printed for each executable that was not found. The module will make the
# following substitutions in the string: `__EXECUTABLE_NAME__` will become the
# name of the executable that was not found.
error_message = "Not found: __EXECUTABLE_NAME__"
}
# ------------------------------------------------------------------------------------------------------
# DEPLOY GRUNTWORK'S REQUIRE-EXECUTABLE MODULE
# ------------------------------------------------------------------------------------------------------
terraform {
source = "git::git@github.com:gruntwork-io/terraform-aws-utilities.git//modules/require-executable?ref=v0.10.5"
}
inputs = {
# ----------------------------------------------------------------------------------------------------
# REQUIRED VARIABLES
# ----------------------------------------------------------------------------------------------------
# A list of named executables that should exist on the OS PATH.
required_executables = <list(string)>
# ----------------------------------------------------------------------------------------------------
# OPTIONAL VARIABLES
# ----------------------------------------------------------------------------------------------------
# Error message to show if the required executable is not found. This is
# printed for each executable that was not found. The module will make the
# following substitutions in the string: `__EXECUTABLE_NAME__` will become the
# name of the executable that was not found.
error_message = "Not found: __EXECUTABLE_NAME__"
}
Reference
- Inputs
- Outputs
Required
required_executables
list(string)A list of named executables that should exist on the OS PATH.
Optional
error_message
stringError message to show if the required executable is not found. This is printed for each executable that was not found. The module will make the following substitutions in the string: __EXECUTABLE_NAME__
will become the name of the executable that was not found.
"Not found: __EXECUTABLE_NAME__"
A map of the executables to the resolved path where they reside.