File tree 2 files changed +18
-3
lines changed
2 files changed +18
-3
lines changed Original file line number Diff line number Diff line change @@ -6,7 +6,13 @@ import (
6
6
)
7
7
8
8
// 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`).
9
11
func RequireEnv (name string ) (string , error ) {
12
+ if os .Getenv ("CODER_WORKSPACE_BUILD_ID" ) == "" {
13
+ return os .Getenv (name ), nil
14
+ }
15
+
10
16
val := os .Getenv (name )
11
17
if val == "" {
12
18
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 {
62
62
id := helpers .OptionalEnvOrDefault ("CODER_WORKSPACE_ID" , uuid .NewString ())
63
63
rd .SetId (id )
64
64
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
+ }
66
69
_ = rd .Set ("template_id" , templateID )
67
70
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
+ }
69
75
_ = rd .Set ("template_name" , templateName )
70
76
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
+ }
72
81
_ = rd .Set ("template_version" , templateVersion )
73
82
74
83
config , valid := i .(config )
You can’t perform that action at this time.
0 commit comments