Skip to content

Commit

Permalink
added documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
calii23 committed Oct 20, 2021
1 parent 7552809 commit 13af87d
Show file tree
Hide file tree
Showing 5 changed files with 306 additions and 0 deletions.
57 changes: 57 additions & 0 deletions website/docs/index.html.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
---
layout: "process"
page_title: "Provider: Process"
sidebar_current: "docs-process-index"
description: |-
A provider for spawning and using external processes.
---

# Process Provider

The process provider gives the ability to spawn processes. The input and output of the processes can be
used. As well as processes living over the lifetime of other tasks.

Use the navigation to the left to read about the available resources.

## Usage

There is no need for a configuration block for this provider at all.

## Data sources

Every resource from this provider has a data source, which does the same thing.
The only difference is, that the data source will execute the action when reading,
not when creating.

```hcl
resource "process_run" "as_resource" {
# ...
}
data "process_run" "as_datasource" {
# ...
}
```

## `inputs` / `outputs`

All resources and data sources from this provider have a `inputs` and a `outputs` attribute.

The content of the `inputs` will be copied over to `outputs` after the resource
has been executed.

Example:
```hcl
resource "process_run" "io" {
inputs = {
hello = "world"
}
# ...
}
locals {
hello = process_run.io.outputs.hello # world
}
```

This can be used to make other provider configurations dependent on the execution of a process.
58 changes: 58 additions & 0 deletions website/docs/r/process_end.html.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
---
layout: "process"
page_title: "Process: process_end"
sidebar_current: "docs-process-process_end"
description: |-
Ends a background process
---

# process_end

The ``process_end`` resource ends a process which was spawned by ``process_start``. It is highly
recommended using this resource. Not using it can cause Terraform to stop the provider early when
there is nothing left in the plan for it to do. This will kill all process which are spawned by
this provider as well. When placing a ``process_end`` resource which will be executed after the
process is not needed anymore, Terraform will be forced to keep this provider running and not
killing it and its child processes.

**Note:** It is not possible to mix resources and data sources in a pair of `process_start` and
`process_end`. Doing so, will cause in an error when creating the `process_end` instance.

## Usage

### Forwarding a TCP port
```hcl
resource "process_start" "forward_tcp" {
command {
platforms = ["linux", "darwin"]
command = "socat tcp-listen:443,reuseaddr,fork tcp:localhost:4000"
}
}
resource "some_resource" "uses_tcp_port" {
# ...
depends_on = [process_start.forward_tcp]
}
resource "process_end" "forward_tcp_end" {
process_id = process_start.forward_tcp.process_id
depends_on = [some_resource.uses_tcp_port]
}
```

## Argument Reference

The following arguments are supported:

* `process_id` - (Required) The ID of the process from `process_start`.
* `kill` - (Optional, Default: `true`) If set to `true`, the process will be killed rather than waiting
for the process to exit.
* `inputs` - (Optional) Copied into `outputs` (documented on main page)

## Attributes Reference

In addition to all arguments above, the following attributes are exported:

* `error` - True if the process exited with an exit code not equal 0
* `outputs` - Copied from `inputs` (documented on main page)
118 changes: 118 additions & 0 deletions website/docs/r/process_run.html.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
---
layout: "process"
page_title: "Process: process_run"
sidebar_current: "docs-process-process_run"
description: |-
Runs a process.
---

# process_run

The ``process_run`` resource runs a process, and returns its output and status.

## Usage

### Create a file
```hcl
locals {
filename = "test.txt"
}
resource "process_run" "create_file" {
command {
platforms = ["linux", "darwin"]
command = "touch ${local.filename}"
}
command {
platforms = ["windows"]
command = "New-Item ${local.filename}"
}
}
```

### Check if a port is open
```hcl
resource "process_run" "check_port" {
command {
platforms = ["darwin", "linux"]
command = "nc -z 127.0.0.1 8080"
}
tries = 10
timeout = 100
}
```

### Write file
```hcl
resource "process_run" "write_text" {
command {
platforms = ["linux", "darwin"]
command = "cat > info.txt"
stdin = "Hello World!"
}
}
resource "process_run" "write_image" {
command {
platforms = ["linux", "darwin"]
command = "cat > image.jpg"
stdin_base64 = var.image_base64
}
}
```

### Read file
```hcl
resource "process_run" "read_file" {
command {
platforms = ["linux", "darwin"]
command = "cat info.txt"
}
}
locals {
file_content = process_run.read_file.stdout
}
```

## Argument Reference

The following arguments are supported:

* `triggers` - (Optional) When anything in this object changed, the process will
be executed again.
* `command` - (Required) A configuration of a possible command (documented below)
* `tries` - (Optional) The number of tries, it will run the process again when failed.
* `retry_interval` - (Optional, Default: `500`) The number of milliseconds to wait between the tries
* `timeout` - (Optional, Default: `500`) The maximum number of milliseconds after the process gets killed. The
timeout can be disabled by settings this argument to `0`.
* `inputs` - (Optional) Copied into `outputs` (documented on main page)

The `command` object supports the following:

* `platforms` - (Required) A set of platforms which are valid for this configuration.
Valid values are `darwin`, `freebsd`, `linux`, `openbsd`, `solaris`, and `windows`.
* `command` - (Required) The command which will be executed.
* `environment` - (Optional) A map of environment variables.
* `sensitive_environment` - (Optional) A map of environment variables which are sensitive.
* `interpreter` - (Optional) The command line which spawns the process. When not given, on unix-like systems
`["/bin/bash", "-c"]` and on Windows `["powershell.exe"]` will be assumed.
* `working_directory` - (Optional) The working directory to start the process in. By default, the root of the
project.
* `stdin` - (Optional) When given, this data will be piped into the stdin of the process. Conflicts with `stdin_base64`.
* `stdin_base64` - (Optional) When given, this data will be decoded as base64 and be piped into
the stdin of the process. Conflicts with `stdin`.

The first `command` block which has a matching platform will be used as configuration. All other blocks
are ignored. When there is no matching command configuration, this resource will fail to create.

## Attributes Reference

In addition to all arguments above, the following attributes are exported:

* `stdout` - The output in stdout of the last process
* `stderr` - The output in stderr of the last process
* `error` - True if the last process exited with an exit code not equal 0
* `timed_out` - True if the last process was killed because it took longer than the timeout
* `outputs` - Copied from `inputs` (documented on main page)
42 changes: 42 additions & 0 deletions website/docs/r/process_start.html.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
layout: "process"
page_title: "Process: process_start"
sidebar_current: "docs-process-process_start"
description: |-
Starts a process which runs in background.
---

# process_start

The ``process_start`` resource starts a process, which will keep running in background.

**Note:** check the ``process_end`` resources as well for best use of this resource.

## Usage

### Forwarding a TCP port
```hcl
resource "process_start" "forward_tcp" {
command {
platforms = ["linux", "darwin"]
command = "socat tcp-listen:443,reuseaddr,fork tcp:localhost:4000"
}
}
```

## Argument Reference

The following arguments are supported:

* `triggers` - (Optional) When anything in this object changed, the process will
be executed again.
* `command` - (Required) A configuration of a possible command (documented in `process_run`)
* `inputs` - (Optional) Copied into `outputs` (documented on main page)

## Attributes Reference

In addition to all arguments above, the following attributes are exported:

* `process_id` - A ID of the spawned process which can be passed to `process_end`.
* `pid` - The PID (Process Identifier) of the spawned process.
* `outputs` - Copied from `inputs` (documented on main page)
31 changes: 31 additions & 0 deletions website/process.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<% wrap_layout :inner do %>
<% content_for :sidebar do %>
<div class="docs-sidebar hidden-print affix-top" role="complementary">
<ul class="nav docs-sidenav">
<li<%= sidebar_current("docs-home") %>>
<a href="/docs/providers/index.html">All Providers</a>
</li>

<li<%= sidebar_current("docs-process-index") %>>
<a href="/docs/providers/process/index.html">Process Provider</a>
</li>

<li<%= sidebar_current("docs-process-resource") %>>
<a href="#">Resources</a>
<ul class="nav nav-visible">
<li<%= sidebar_current("docs-process-process_run") %>>
<a href="/docs/providers/process/r/process_run.html">process_run</a>
</li>
<li<%= sidebar_current("docs-process-process_start") %>>
<a href="/docs/providers/process/r/process_start.html">process_start</a>
</li>
<li<%= sidebar_current("docs-process-process_end") %>>
<a href="/docs/providers/process/r/process_end.html">process_end</a>
</li>
</ul>
</li>
</ul>
</div>
<% end %>
<%= yield %>
<% end %>

0 comments on commit 13af87d

Please sign in to comment.