Skip to content

Commit ee9deb0

Browse files
authored
docs: add conditional example to optional vs required parameters (#9115)
1 parent 65d8482 commit ee9deb0

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

docs/templates/parameters.md

+15
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,21 @@ data "coder_parameter" "dotfiles_url" {
133133
}
134134
```
135135

136+
Terraform [conditional expressions](https://developer.hashicorp.com/terraform/language/expressions/conditionals) can be used to determine whether the user specified a value for an optional parameter:
137+
138+
```hcl
139+
resource "coder_agent" "main" {
140+
# ...
141+
startup_script_timeout = 180
142+
startup_script = <<-EOT
143+
set -e
144+
145+
echo "The optional parameter value is: ${data.coder_parameter.optional.value == "" ? "[empty]" : data.coder_parameter.optional.value}"
146+
147+
EOT
148+
}
149+
```
150+
136151
## Mutability
137152

138153
Immutable parameters can be only set before workspace creation, or during update on the first usage to set the initial value for required parameters. The idea is to prevent users from modifying fragile or persistent workspace resources like volumes, regions, etc.:

0 commit comments

Comments
 (0)