File tree Expand file tree Collapse file tree 2 files changed +18
-3
lines changed
Expand file tree Collapse file tree 2 files changed +18
-3
lines changed Original file line number Diff line number Diff line change @@ -6,7 +6,13 @@ import (
66)
77
88// RequireEnv requires environment variable to be present.
9+ // The constraint can be verified only during execution of the workspace build
10+ // (determined with env `CODER_WORKSPACE_BUILD_ID`).
911func RequireEnv (name string ) (string , error ) {
12+ if os .Getenv ("CODER_WORKSPACE_BUILD_ID" ) == "" {
13+ return os .Getenv (name ), nil
14+ }
15+
1016 val := os .Getenv (name )
1117 if val == "" {
1218 return "" , fmt .Errorf ("%s is required" , name )
Original file line number Diff line number Diff line change @@ -62,13 +62,22 @@ func workspaceDataSource() *schema.Resource {
6262 id := helpers .OptionalEnvOrDefault ("CODER_WORKSPACE_ID" , uuid .NewString ())
6363 rd .SetId (id )
6464
65- templateID := helpers .OptionalEnv ("CODER_WORKSPACE_TEMPLATE_ID" ) // FIXME switch to `helpers.RequireEnv(...)`
65+ templateID , err := helpers .RequireEnv ("CODER_WORKSPACE_TEMPLATE_ID" )
66+ if err != nil {
67+ return diag .Errorf ("template ID is missing: %w" , err )
68+ }
6669 _ = rd .Set ("template_id" , templateID )
6770
68- templateName := helpers .OptionalEnv ("CODER_WORKSPACE_TEMPLATE_NAME" ) // FIXME switch to `helpers.RequireEnv(...)`
71+ templateName , err := helpers .RequireEnv ("CODER_WORKSPACE_TEMPLATE_NAME" )
72+ if err != nil {
73+ return diag .Errorf ("template name is missing: %w" , err )
74+ }
6975 _ = rd .Set ("template_name" , templateName )
7076
71- templateVersion := helpers .OptionalEnv ("CODER_WORKSPACE_TEMPLATE_VERSION" ) // FIXME switch to `helpers.RequireEnv(...)`
77+ templateVersion , err := helpers .RequireEnv ("CODER_WORKSPACE_TEMPLATE_VERSION" )
78+ if err != nil {
79+ return diag .Errorf ("template version is missing: %w" , err )
80+ }
7281 _ = rd .Set ("template_version" , templateVersion )
7382
7483 config , valid := i .(config )
You can’t perform that action at this time.
0 commit comments