You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
action: Add new local_command action to invoke a local executable with provided input (#450)
* initial implementation
* update the config directory to work running manually
* add count
* add test
* add tests
* don't encode null arguments
* add copyright headers
* add documentation and example
* remove the tests temporarily for the CI
* lint
* use rc1 for generating docs
* add changelog and fix tests for windows
* add vscode gitignore
* refactor
* update docs
* replace unreleased plugin testing code w/ TODOs and normal `Check` funcs
Invokes an executable on the local machine. All environment variables visible to the Terraform process are passed through to the child process. After the child process successfully executes, the stdout will be returned for Terraform to display to the user.
5
+
Any non-zero exit code will be treated as an error and will return a diagnostic to Terraform containing the stderr message if available.
6
+
---
7
+
8
+
# local_command (Action)
9
+
10
+
Invokes an executable on the local machine. All environment variables visible to the Terraform process are passed through to the child process. After the child process successfully executes, the `stdout` will be returned for Terraform to display to the user.
11
+
12
+
Any non-zero exit code will be treated as an error and will return a diagnostic to Terraform containing the `stderr` message if available.
13
+
14
+
## Example Usage
15
+
16
+
For the following bash script (`example_script.sh`):
17
+
```bash
18
+
#!/bin/bash
19
+
20
+
DATA=$(</dev/stdin)
21
+
echo"stdin: $DATA, args: $@"
22
+
```
23
+
24
+
Here is an example configuration that will run the script after a resource is created:
25
+
26
+
```terraform
27
+
resource "terraform_data" "test" {
28
+
lifecycle {
29
+
action_trigger {
30
+
events = [after_create]
31
+
actions = [action.local_command.bash_example]
32
+
}
33
+
}
34
+
}
35
+
36
+
action "local_command" "bash_example" {
37
+
config {
38
+
command = "bash"
39
+
arguments = ["example_script.sh", "arg1", "arg2"]
40
+
stdin = jsonencode({
41
+
"key1" : "value1"
42
+
"key2" : "value2"
43
+
})
44
+
}
45
+
}
46
+
```
47
+
48
+
The `stdout` will be displayed when the action is invoked:
49
+
```bash
50
+
$ terraform apply -auto-approve
51
+
52
+
# .. Terraform CLI output truncated for example purposes
53
+
54
+
Plan: 1 to add, 0 to change, 0 to destroy. Actions: 1 to invoke.
55
+
terraform_data.test: Creating...
56
+
terraform_data.test: Creation complete after 0s [id=4b41b541-5550-590a-9949-657e91baa346]
57
+
Action started: action.local_command.bash_example (triggered by terraform_data.test)
58
+
Action action.local_command.bash_example (triggered by terraform_data.test):
-`command` (String) Executable name to be discovered on the PATH or absolute path to executable.
74
+
75
+
### Optional
76
+
77
+
-`arguments` (List of String) Arguments to be passed to the given command. Any `null` arguments will be removed from the list.
78
+
-`stdin` (String) Data to be passed to the given command's standard input.
79
+
-`working_directory` (String) The directory path where the command should be executed, either an absolute path or relative to the Terraform working directory. If not provided, defaults to the Terraform working directory.
0 commit comments