|
| 1 | +# External provisioners |
| 2 | + |
| 3 | +By default, the Coder server runs [built-in provisioner daemons](../cli/coder_server.md#provisioner-daemons), which execute `terraform` during workspace and template builds. You can learn more about `provisionerd` in our [architecture documentation](../about/architecture.md#provisionerd). |
| 4 | + |
| 5 | +> While external provisioners are stable, the feature is in an [alpha state](../contributing/feature-stages.md#alpha-features) and the behavior is subject to change in feature releases. Use [GitHub issues](https://github.com/coder/coder) to leave feedback. |
| 6 | +
|
| 7 | +## Benefits of external provisioners |
| 8 | + |
| 9 | +There are benefits in running external provisioner servers. |
| 10 | + |
| 11 | +### Security |
| 12 | + |
| 13 | +As you add more (template) admins in Coder, there is an increased risk of malicious code being added into templates. Isolated provisioners can prevent template admins from running code directly against the Coder server, database, or host machine. |
| 14 | + |
| 15 | +Additionally, you can configure provisioner environments to access cloud secrets that the Coder server does not necessarily have access to. |
| 16 | + |
| 17 | +### Extensibility |
| 18 | + |
| 19 | +Instead of exposing a full API and secrets to the Coder server (e.g. Kubernetes, Docker, VMware), provisioners can run in each environment. See [Provider authentication](../templates/authentication.md) for more details. |
| 20 | + |
| 21 | +### Scalability |
| 22 | + |
| 23 | +Reduce load from the Coder server and reduce queue times and build times for users. See [Scaling Coder](./scale.md#concurrent-workspace-builds) for more details. |
| 24 | + |
| 25 | +## Run an external provisioner |
| 26 | + |
| 27 | +The [Coder CLI](../cli.md) can launch external provisioners once authenticated as a user with the Template Admin or Owner role. There are 3 types of provisioners: |
| 28 | + |
| 29 | +- **Generic provisioners** can pick up any build job from templates without provisioner tags. |
| 30 | + |
| 31 | + ```sh |
| 32 | + coder provisionerd start |
| 33 | + ``` |
| 34 | + |
| 35 | + > Ensure all provisioners (including [built-in provisioners](#disable-built-in-provisioners)) have similar configuration/cloud access or you may run into intermittent build errors, depending on which provisioner picks up a job. |
| 36 | +
|
| 37 | +- **Tagged provisioners** can be used to pick up build jobs from workspaces and templates with matching tags. |
| 38 | + |
| 39 | + ```sh |
| 40 | + coder provisionerd start \ |
| 41 | + --tag environment=on_prem \ |
| 42 | + --tag data_center=chicago |
| 43 | + |
| 44 | + # In another terminal, create/push |
| 45 | + # a template that requires this provisioner |
| 46 | + coder templates create on-prem \ |
| 47 | + --provisioner-tag environment=on_prem |
| 48 | + |
| 49 | + # Or, match the provisioner exactly |
| 50 | + coder templates create on-prem-chicago \ |
| 51 | + --provisioner-tag environment=on_prem \ |
| 52 | + --provisioner-tag data_center=chicago |
| 53 | + ``` |
| 54 | + |
| 55 | + > At this time, tagged provisioners can also pick jobs from untagged templates. This behavior is [subject to change](https://github.com/coder/coder/issues/6442). |
| 56 | +
|
| 57 | +- **User provisioners** can only pick up jobs from user-tagged templates. Unlike the other provisioner types, any Coder can run user provisioners, but they have no impact unless there is at least one template with the `scope=user` provisioner tag. |
| 58 | + |
| 59 | + ```sh |
| 60 | + coder provisionerd start \ |
| 61 | + --tag scope=user |
| 62 | + |
| 63 | + # In another terminal, create/push |
| 64 | + # a template that requires user provisioners |
| 65 | + coder templates create on-prem \ |
| 66 | + --provisioner-tag scope=user |
| 67 | + ``` |
| 68 | + |
| 69 | +## Running external provisioners via Docker |
| 70 | + |
| 71 | +The following command can run a Coder provisioner isolated in a Docker container. |
| 72 | + |
| 73 | +```sh |
| 74 | +docker run --rm -it \ |
| 75 | + -e CODER_URL=https://coder.example.com/ \ |
| 76 | + -e CODER_SESSION_TOKEN=your_token \ |
| 77 | + --entrypoint /opt/coder \ |
| 78 | + ghcr.io/coder/coder:latest \ |
| 79 | + provisionerd start |
| 80 | +``` |
| 81 | + |
| 82 | +Be sure to replace `https://coder.example.com` with your [access URL](./configure.md#access-url) and `your_token` with an [API token](../api.md). |
| 83 | + |
| 84 | +To include [provider secrets](../templates/authentication.md), you can modify the command to mount environment variables or external volumes. Alternatively, you can create a custom provisioner image that includes the Coder CLI. |
| 85 | + |
| 86 | +## Disable built-in provisioners |
| 87 | + |
| 88 | +As mentioned above, the Coder server will run built-in provisioners by default. This can be disabled with a server-wide [flag or environment variable](../cli/coder_server.md#provisioner-daemons). |
| 89 | + |
| 90 | +```sh |
| 91 | +coder server --provisioner-daemons=0 |
| 92 | +``` |
0 commit comments