Skip to content

Commit

Permalink
upd pre_hook/post_hook description in shell unit
Browse files Browse the repository at this point in the history
  • Loading branch information
anastyakulyk committed Aug 23, 2024
1 parent bf14214 commit 385e5f4
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions docs/units-shell.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Executes Shell commands and scripts.

## Example usage

Example of a `shell` unit that creates an index.html file with a greeting message and downloads the file into an S3 bucket. The bucket name is passed as a variable:
Example of a `shell` unit that creates an `index.html` file with a greeting message and downloads the file into an S3 bucket. The bucket name is passed as a variable:

```yaml
units:
Expand Down Expand Up @@ -52,6 +52,16 @@ units:
regexp_value: "regexp"
separator: "="
command: terraform output -json
pre_hook:
on_apply: true
on_destroy: true
command: |
cat ./main.tf
post_hook:
on_apply: false
on_destroy: true
command: |
terraform output
create_files:
- file: ./my_text_file.txt
mode: 0644
Expand All @@ -78,7 +88,7 @@ units:

* `create_files` - *list of files*, *optional*. The list of files that have to be saved in the state in case of their changing.

* [`pre_hook` and `post_hook` blocks](#pre_hook-and-post_hook-blocks): describe the shell commands to be executed before and after the unit, respectively. The commands will be executed in the same context as the actions of the unit. Environment variables are common to the shell commands, the pre_hook and post_hook scripts, and the unit execution. You can export a variable in the pre_hook and it will be available in the post_hook or in the unit. For details see below.
* [`pre_hook` and `post_hook` blocks](#pre_hook-and-post_hook-blocks): describe shell commands to be executed before and after the unit, respectively. The commands will be executed in the same context as the actions of the unit. Environment variables are common to shell commands, the `pre_hook` and `post_hook` scripts, and unit execution. You can export a variable in the `pre_hook` and it will be available in the `post_hook` or in the unit. For details see below.

### `apply`

Expand All @@ -104,7 +114,7 @@ units:

* `JSON` - if the `type` is defined as JSON, outputs will be parsed as key-value JSON. This type of output makes all other options not required.

* `regexp` - if the `type` is defined as regexp, this introduces an additional required option `regexp`. Regexp is a regular expression which defines how to parse each line in the module output. Example:
* `regexp` - if the `type` is defined as `regexp`, this introduces an additional required option `regexp`: a regular expression which defines how to parse each line in the module output. Example:

```yaml
outputs: # how to get outputs
Expand All @@ -128,9 +138,19 @@ units:

### `pre_hook` and `post_hook` blocks

* `command` - *string*. Shell command in text format. Will be executed in Bash -c "command". Can be used if the "script" option is not used. One of `command` or `script` is required.
Example usage:

```yaml
units:
....
pre_hook:
on_apply: true
on_destroy: true
command: |
cat ./main.tf
```

* `script` - *string*. Path to shell script file which is relative to template directory. Can be used if the "command" option is not used. One of `command` or `script` is required.
* `command` - *string*. Shell command in text format. Will be executed in Bash -c "command". Can be used if the "script" option is not used. One of `command` or `script` is required.

* `on_apply` *bool*, *optional*. Turn off/on when unit applying. **Default: "true"**.

Expand Down

0 comments on commit 385e5f4

Please sign in to comment.