docs: add conditional example to optional vs required parameters (#9115)

This commit is contained in:
Ben Potter 2023-08-15 13:24:05 -05:00 committed by GitHub
parent 65d84827cd
commit ee9deb0a6e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 0 deletions

View File

@ -133,6 +133,21 @@ data "coder_parameter" "dotfiles_url" {
}
```
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:
```hcl
resource "coder_agent" "main" {
# ...
startup_script_timeout = 180
startup_script = <<-EOT
set -e
echo "The optional parameter value is: ${data.coder_parameter.optional.value == "" ? "[empty]" : data.coder_parameter.optional.value}"
EOT
}
```
## Mutability
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.: