|
1 |
| -# Working with templates |
| 1 | +# Creating Templates |
2 | 2 |
|
3 |
| -You create and edit Coder templates as [Terraform](./tour.md) configuration |
4 |
| -files (`.tf`) and any supporting files, like a README or configuration files for |
5 |
| -other services. |
| 3 | +Users with the `Template Administrator` role or above can create templates |
| 4 | +within Coder. |
6 | 5 |
|
7 |
| -## Who creates templates? |
| 6 | +## From a starter template |
8 | 7 |
|
9 |
| -The [Template Admin](../admin/users.md) role (and above) can create templates. |
10 |
| -End users, like developers, create workspaces from them. Templates can also be |
11 |
| -[managed with git](./change-management.md), allowing any developer to propose |
12 |
| -changes to a template. |
| 8 | +In most cases, it is best to start with a starter template. |
13 | 9 |
|
14 |
| -You can give different users and groups access to templates with |
15 |
| -[role-based access control](../admin/rbac.md). |
| 10 | +<div class="tabs"> |
16 | 11 |
|
17 |
| -## Starter templates |
| 12 | +### Web UI |
18 | 13 |
|
19 |
| -We provide starter templates for common cloud providers, like AWS, and |
20 |
| -orchestrators, like Kubernetes. From there, you can modify them to use your own |
21 |
| -images, VPC, cloud credentials, and so on. Coder supports all Terraform |
22 |
| -resources and properties, so fear not if your favorite cloud provider isn't |
23 |
| -here! |
| 14 | +After navigating to the Templates page in the Coder dashboard, choose |
| 15 | +`Create Template > Choose a starter template`. |
24 | 16 |
|
25 |
| - |
| 17 | + |
26 | 18 |
|
27 |
| -If you prefer to use Coder on the [command line](../cli.md), use |
28 |
| -`coder templates init`. |
| 19 | +From there, select a starter template for desired underlying infrastructure for |
| 20 | +workspaces. |
29 | 21 |
|
30 |
| -> Coder starter templates are also available on our |
31 |
| -> [GitHub repo](https://github.com/coder/coder/tree/main/examples/templates). |
| 22 | + |
32 | 23 |
|
33 |
| -## Community Templates |
| 24 | +Give your template a name, description, and icon and press `Create template`. |
34 | 25 |
|
35 |
| -As well as Coder's starter templates, you can see a list of community templates |
36 |
| -by our users |
37 |
| -[here](https://github.com/coder/coder/blob/main/examples/templates/community-templates.md). |
| 26 | + |
38 | 27 |
|
39 |
| -## Editing templates |
| 28 | +> **⚠️ Note**: If template creation fails, Coder is likely not authorized to |
| 29 | +> deploy infrastructure in the given location. Learn how to configure |
| 30 | +> [provisioner authentication](#TODO). |
40 | 31 |
|
41 |
| -Our starter templates are meant to be modified for your use cases. You can edit |
42 |
| -any template's files directly in the Coder dashboard. |
| 32 | +### CLI |
43 | 33 |
|
44 |
| - |
| 34 | +You can the [Coder CLI](../../install/cli.md) to manage templates for Coder. |
| 35 | +After [logging in](#TODO) to your deployment, create a folder to store your |
| 36 | +templates: |
45 | 37 |
|
46 |
| -If you'd prefer to use the CLI, use `coder templates pull`, edit the template |
47 |
| -files, then `coder templates push`. |
48 |
| - |
49 |
| -> Even if you are a Terraform expert, we suggest reading our |
50 |
| -> [guided tour](./tour.md). |
| 38 | +```sh |
| 39 | +# This snippet applies to macOS and Linux only |
| 40 | +mkdir $HOME/coder-templates |
| 41 | +cd $HOME/coder-templates |
| 42 | +``` |
51 | 43 |
|
52 |
| -## Updating templates |
| 44 | +Use the [`templates init`](../../reference/cli/templates_init.md) command to |
| 45 | +pull a starter template: |
53 | 46 |
|
54 |
| -Coder tracks a template's versions, keeping all developer workspaces up-to-date. |
55 |
| -When you publish a new version, developers are notified to get the latest |
56 |
| -infrastructure, software, or security patches. Learn more about |
57 |
| -[change management](./change-management.md). |
| 47 | +```sh |
| 48 | +coder templates init |
| 49 | +``` |
58 | 50 |
|
59 |
| - |
| 51 | +After pulling the template to your local machine (e.g. `aws-linux`), you can |
| 52 | +rename it: |
60 | 53 |
|
61 |
| -## Delete templates |
| 54 | +```sh |
| 55 | +# This snippet applies to macOS and Linux only |
| 56 | +mv aws-linux universal-template |
| 57 | +cd universal-template |
| 58 | +``` |
62 | 59 |
|
63 |
| -You can delete a template using both the coder CLI and UI. Only |
64 |
| -[template admins and owners](../admin/users.md) can delete a template, and the |
65 |
| -template must not have any running workspaces associated to it. |
| 60 | +Next, push it to Coder with the |
| 61 | +[`templates push`](../../reference/cli/templates_push.md) command: |
66 | 62 |
|
67 |
| -In the UI, navigate to the template you want to delete, and select the dropdown |
68 |
| -in the right-hand corner of the page to delete the template. |
| 63 | +```sh |
| 64 | +coder templates push |
| 65 | +``` |
69 | 66 |
|
70 |
| - |
| 67 | +> ⚠️ Note: If `template push` fails, Coder is likely not authorized to deploy |
| 68 | +> infrastructure in the given location. Learn how to configure |
| 69 | +> [provisioner authentication](#TODO). |
71 | 70 |
|
72 |
| -Using the CLI, login to Coder and run the following command to delete a |
73 |
| -template: |
| 71 | +You can edit the metadata of the template such as the display name with the |
| 72 | +[`templates edit`](../../reference/cli/templates_edit.md) command: |
74 | 73 |
|
75 |
| -```shell |
76 |
| -coder templates delete <template-name> |
| 74 | +```sh |
| 75 | +coder templates edit universal-template \ |
| 76 | + --display-name "Universal Template" \ |
| 77 | + --description "Virtual machine configured with Java, Python, Typescript, IntelliJ IDEA, and Ruby. Use this for starter projects. " \ |
| 78 | + --icon "/emojis/2b50.png" |
77 | 79 | ```
|
78 | 80 |
|
79 |
| -### Delete workspaces |
| 81 | +### Git |
| 82 | + |
| 83 | +Follow our tutorial to [manage templates via GitOps](#TODO). |
| 84 | + |
| 85 | +</div> |
| 86 | + |
| 87 | +## From an existing template |
| 88 | + |
| 89 | +You can duplicate an existing template in your Coder deployment. This will copy |
| 90 | +the template code and metadata, allowing you to make changes without affecting |
| 91 | +the original template. |
| 92 | + |
| 93 | +<div class="tabs"> |
| 94 | + |
| 95 | +### Web UI |
| 96 | + |
| 97 | +After navigating to the page for a template, use the dropdown menu on the right |
| 98 | +to `Duplicate`. |
| 99 | + |
| 100 | + |
| 101 | + |
| 102 | +Give the new template a name, icon, and description. |
| 103 | + |
| 104 | + |
| 105 | + |
| 106 | +Press `Create template`. After the build, you will be taken to the new template |
| 107 | +page. |
| 108 | + |
| 109 | + |
| 110 | + |
| 111 | +### CLI |
| 112 | + |
| 113 | +</div> |
| 114 | + |
| 115 | +## From scratch (advanced) |
| 116 | + |
| 117 | +There may be cases where you want to create a template from scratch. You can use |
| 118 | +[any Terraform provider](https://registry.terraform.com) with Coder to create |
| 119 | +templates for additional clouds (e.g. Hetzner, Alibaba) or orchestrators |
| 120 | +(VMware, Proxmox) that we do not provide example templates for. |
80 | 121 |
|
81 |
| -When a workspace is deleted, the Coder server essentially runs a |
82 |
| -[terraform destroy](https://www.terraform.io/cli/commands/destroy) to remove all |
83 |
| -resources associated with the workspace. |
| 122 | +Refer to the following resources: |
84 | 123 |
|
85 |
| -> Terraform's |
86 |
| -> [prevent-destroy](https://www.terraform.io/language/meta-arguments/lifecycle#prevent_destroy) |
87 |
| -> and |
88 |
| -> [ignore-changes](https://www.terraform.io/language/meta-arguments/lifecycle#ignore_changes) |
89 |
| -> meta-arguments can be used to prevent accidental data loss. |
| 124 | +- [Tutorial: Create a template from scratch](../../tutorials/template-from-scratch.md) |
| 125 | +- [Extending templates](./editing-templates.md): Features and concepts around |
| 126 | + templates (agents, parameters, variables, etc) |
| 127 | +- [Coder Registry](https://registry.coder.com/templates): Official and community |
| 128 | + templates for Coder |
| 129 | +- [Coder Terraform Provider Reference](https://registry.terraform.io/providers/coder/coder) |
90 | 130 |
|
91 | 131 | ## Next steps
|
92 | 132 |
|
93 |
| -- [Your first template](../templates/tutorial.md) |
| 133 | +- [Extending templates](#TODO) |
| 134 | +- [TODO](#TODO) |
0 commit comments