Exec

The exec resource allows the execution of arbitrary commands and scripts. Depending on the parameters specified, the commands are executed either on the local machine or inside of a container.

When either the image or target fields are specified, the command is executed inside of a container. When neither of these fields are specified, the command is executed on the local machine.

Local execution

When running on the local machine, the command runs in the local user space, and has access to all the environment variables that the user executing jumppad run has access too. Additional environment variables, and the working directory for the command can be specified as part of the resource.

Remote execution

Execution can either be in a stand alone container or can target an existing and running container. When targeting an existing container, the target field must be specified. When running in a stand alone container, the image block must be specified.

Setting outputs

Output variables for the exec resource can be set by echoing a key value pair to the output file inside the script. An environment variable ${EXEC_OUTPUT} is automatically added to the environment of the script and points to the output.

Any outputs set in the script are automatically parsed into a map and are available via the output parameter.

Examples

Output from Exec

The following example demonstrates how to set an output variable in a script.

resource "exec" "inline" {
  script = <<-EOF
  #!/bin/bash
  ls -lha

  echo "FOO=BAR" > ${EXEC_OUTPUT}
  EOF
}

output "foo" {
  value = resource.exec.inline.output.FOO
}

Last updated