feat: import value from legacy variable to build parameter (#6556)

This commit is contained in:
Marcin Tojek
2023-03-14 12:02:44 +00:00
committed by GitHub
parent bc26c4a27f
commit 7587850a1c
24 changed files with 576 additions and 296 deletions
+2
View File
@@ -3734,6 +3734,7 @@ Parameter represents a set value for the scope.
"description": "string",
"description_plaintext": "string",
"icon": "string",
"legacy_variable_name": "string",
"mutable": true,
"name": "string",
"options": [
@@ -3762,6 +3763,7 @@ Parameter represents a set value for the scope.
| `description` | string | false | | |
| `description_plaintext` | string | false | | |
| `icon` | string | false | | |
| `legacy_variable_name` | string | false | | |
| `mutable` | boolean | false | | |
| `name` | string | false | | |
| `options` | array of [codersdk.TemplateVersionParameterOption](#codersdktemplateversionparameteroption) | false | | |
+2
View File
@@ -2209,6 +2209,7 @@ curl -X GET http://coder-server:8080/api/v2/templateversions/{templateversion}/r
"description": "string",
"description_plaintext": "string",
"icon": "string",
"legacy_variable_name": "string",
"mutable": true,
"name": "string",
"options": [
@@ -2247,6 +2248,7 @@ Status Code **200**
| `» description` | string | false | | |
| `» description_plaintext` | string | false | | |
| `» icon` | string | false | | |
| `» legacy_variable_name` | string | false | | |
| `» mutable` | boolean | false | | |
| `» name` | string | false | | |
| `» options` | array | false | | |
+47
View File
@@ -196,6 +196,53 @@ variable "cpu" {
> ⚠️ Legacy (`variable`) parameters and rich parameters can't be used in the same template.
### Migration
Terraform variables shouldn't be used for workspace scoped parameters anymore, and it's recommended to convert variables to `coder_parameter` resources. To make the migration smoother, there is a special property introduced -
`legacy_variable` and `legacy_variable_name` , which can link `coder_parameter` with a legacy variable.
```hcl
variable "legacy_cpu" {
sensitive = false
description = "CPU cores"
default = 2
}
data "coder_parameter" "cpu" {
name = "CPU cores"
type = "number"
description = "Number of CPU cores"
mutable = true
legacy_variable_name = "legacy_cpu"
legacy_variable = var.legacy_cpu
}
```
#### Steps
1. Prepare and update a new template version:
- Add `coder_parameter` resource matching the legacy variable to migrate.
- Use `legacy_variable_name` and `legacy_variable` to link the `coder_parameter` to the legacy variable.
- Mark the new parameter as `mutable`, so that Coder will not block updating existing workspaces.
2. Update all workspaces to the updated template version. Coder will populate the added `coder_parameter`s with values from legacy variables.
3. Prepare another template version:
- Remove the migrated variables.
- Remove properties `legacy_variable` and `legacy_variable_name` from `coder_parameter`s.
4. Update all workspaces to the updated template version (2nd).
5. Prepare a third template version:
- Enable the `feature_use_managed_variables` provider flag to use managed Terraform variables for template customization. Once the flag is enabled, legacy variables won't be used.
6. Update all workspaces to the updated template version (3rd).
7. Delete legacy parameters.
As a template improvement, the template author can consider making some of the new `coder_parameter` resources `mutable`.
## Managed Terraform variables
As parameters are intended to be used only for workspace customization purposes, Terraform variables can be freely managed by the template author to build templates. Workspace users are not able to modify