Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 48 additions & 6 deletions docs/resources/template.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,48 @@ resource "coderd_template" "ubuntu-main" {
groups = []
}
}

// Exactly one of `directory`, `files`, `archive_base64`, and `archive_file` may
// be set on a version.
resource "coderd_template" "ubuntu-rendered" {
name = "ubuntu-rendered"
description = "The main template, rendered for this deployment."
versions = [
{
name = "rendered-${var.COMMIT_SHA}"
active = true
files = {
"main.tf" = templatefile("${path.module}/tpl/main.tf.tftpl", { image = "ubuntu:24.04" })
"build/Dockerfile" = file("${path.module}/tpl/build/Dockerfile")
}
},
{
name = "prebuilt-${var.COMMIT_SHA}"
// A base64-encoded tar, tar.gz, or zip archive. Variable values aren't
// discovered from an archive, so they're set with `tf_vars`.
archive_base64 = filebase64("${path.module}/tpl/prebuilt.tar")
tf_vars = [{
name = "image"
value = "ubuntu:24.04"
}]
},
{
name = "packaged-${var.COMMIT_SHA}"
// The same archive, referenced by path. It has to exist at plan time.
archive_file = data.archive_file.template.output_path
tf_vars = [{
name = "image"
value = "ubuntu:24.04"
}]
}
]
}

data "archive_file" "template" {
type = "zip"
source_dir = "${path.module}/stable-template"
output_path = "${path.module}/build/template.zip"
}
```

<!-- schema generated by tfplugindocs -->
Expand Down Expand Up @@ -130,21 +172,21 @@ Optional:
<a id="nestedatt--versions"></a>
### Nested Schema for `versions`

Required:

- `directory` (String) A path to the directory to create the template version from. Changes in the directory contents will trigger the creation of a new template version.

Optional:

- `active` (Boolean) Whether this version is the active version of the template. Only one version can be active at a time.
- `archive_base64` (String) A base64-encoded archive of the template version contents, uploaded as-is. The archive must be an uncompressed tar, a gzipped tar, or a zip archive. Changes in the archive will trigger the creation of a new template version. Unlike `directory` and `files`, variable values are not discovered from the archive, so any `*.tfvars` files it contains are ignored - use `tf_vars` instead. Exactly one of `directory`, `files`, `archive_base64`, or `archive_file` must be set.
- `archive_file` (String) A path to an archive file containing the template version contents, uploaded as-is. The archive must be an uncompressed tar, a gzipped tar, or a zip archive, such as the one produced by the `archive_file` data source. The file is read while planning, so it must already exist at plan time, and changes to its contents will trigger the creation of a new template version. Unlike `directory` and `files`, variable values are not discovered from the archive, so any `*.tfvars` files it contains are ignored - use `tf_vars` instead. Exactly one of `directory`, `files`, `archive_base64`, or `archive_file` must be set.
- `directory` (String) A path to the directory to create the template version from. Changes in the directory contents will trigger the creation of a new template version. Exactly one of `directory`, `files`, `archive_base64`, or `archive_file` must be set.
- `files` (Map of String) The contents of the template version, as a map of file path (relative to the root of the template) to file content. Paths must be relative and must not escape the root of the template, and at least one `.tf` or `.tf.json` file must be present at the root. Changes in the contents will trigger the creation of a new template version. The files are archived exactly as if they were read from a `directory`, meaning hidden files are excluded, and `terraform.tfvars`/`*.auto.tfvars` entries are read as variable values instead of being uploaded. Exactly one of `directory`, `files`, `archive_base64`, or `archive_file` must be set.
- `message` (String) A message describing the changes in this version of the template. Messages longer than 72 characters will be truncated.
- `name` (String) The name of the template version. Automatically generated if not provided. If provided, the name *must* change each time the directory contents, or the `tf_vars` attribute are updated.
- `name` (String) The name of the template version. Automatically generated if not provided. If provided, the name *must* change each time the version contents, or the `tf_vars` attribute are updated.
- `provisioner_tags` (Attributes Set) Provisioner tags for the template version. (see [below for nested schema](#nestedatt--versions--provisioner_tags))
- `tf_vars` (Attributes Set) Terraform variables for the template version. (see [below for nested schema](#nestedatt--versions--tf_vars))

Read-Only:

- `directory_hash` (String)
- `directory_hash` (String) A hash of the template version contents, used to detect when a new version needs to be created.
- `id` (String)

<a id="nestedatt--versions--provisioner_tags"></a>
Expand Down
42 changes: 42 additions & 0 deletions examples/resources/coderd_template/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,45 @@ resource "coderd_template" "ubuntu-main" {
groups = []
}
}

// Exactly one of `directory`, `files`, `archive_base64`, and `archive_file` may
// be set on a version.
resource "coderd_template" "ubuntu-rendered" {
name = "ubuntu-rendered"
description = "The main template, rendered for this deployment."
versions = [
{
name = "rendered-${var.COMMIT_SHA}"
active = true
files = {
"main.tf" = templatefile("${path.module}/tpl/main.tf.tftpl", { image = "ubuntu:24.04" })
"build/Dockerfile" = file("${path.module}/tpl/build/Dockerfile")
}
},
{
name = "prebuilt-${var.COMMIT_SHA}"
// A base64-encoded tar, tar.gz, or zip archive. Variable values aren't
// discovered from an archive, so they're set with `tf_vars`.
archive_base64 = filebase64("${path.module}/tpl/prebuilt.tar")
tf_vars = [{
name = "image"
value = "ubuntu:24.04"
}]
},
{
name = "packaged-${var.COMMIT_SHA}"
// The same archive, referenced by path. It has to exist at plan time.
archive_file = data.archive_file.template.output_path
tf_vars = [{
name = "image"
value = "ubuntu:24.04"
}]
}
]
}

data "archive_file" "template" {
type = "zip"
source_dir = "${path.module}/stable-template"
output_path = "${path.module}/build/template.zip"
}
Loading