-
Notifications
You must be signed in to change notification settings - Fork 22
feat: allow presets to define prebuilds #373
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
5418ed7
af25037
56d1ab7
c8c5101
4e37a00
06cf760
9f26791
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,14 @@ func workspaceDataSource() *schema.Resource { | |
} | ||
_ = rd.Set("start_count", count) | ||
|
||
prebuild := helpers.OptionalEnv(IsPrebuildEnvironmentVariable()) | ||
prebuildCount := 0 | ||
if prebuild == "true" { | ||
prebuildCount = 1 | ||
_ = rd.Set("is_prebuild", true) | ||
} | ||
_ = rd.Set("prebuild_count", prebuildCount) | ||
|
||
name := helpers.OptionalEnvOrDefault("CODER_WORKSPACE_NAME", "default") | ||
rd.Set("name", name) | ||
|
||
|
@@ -83,6 +91,11 @@ func workspaceDataSource() *schema.Resource { | |
Computed: true, | ||
Description: "The access port of the Coder deployment provisioning this workspace.", | ||
}, | ||
"prebuild_count": { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems to be duplication, yes. We could probably get rid of "is_prebuild" and just check the count. Looking at the rest of the code, we are following the pattern that was set by the "transition" and "start_count" parameters. They have the same relationship. I'm not sure whether to remove "is_prebuild" or keep it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't like neither
Also looks like there is some duplication here as well:
But I don't know why it's needed. We can ask original author of this approach with |
||
Type: schema.TypeInt, | ||
Computed: true, | ||
Description: "A computed count, equal to 1 if the workspace was prebuilt.", | ||
SasSwart marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}, | ||
"start_count": { | ||
Type: schema.TypeInt, | ||
Computed: true, | ||
|
@@ -98,6 +111,11 @@ func workspaceDataSource() *schema.Resource { | |
Computed: true, | ||
Description: "UUID of the workspace.", | ||
}, | ||
"is_prebuild": { | ||
Type: schema.TypeBool, | ||
Computed: true, | ||
Description: "Whether the workspace is a prebuild.", | ||
SasSwart marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}, | ||
"name": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
|
@@ -121,3 +139,7 @@ func workspaceDataSource() *schema.Resource { | |
}, | ||
} | ||
} | ||
|
||
func IsPrebuildEnvironmentVariable() string { | ||
return "CODER_WORKSPACE_IS_PREBUILD" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess it can be const instead of func, but up to you |
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I'd rather write it like this:
I think it's more logical, but it's not a big deal