-
Notifications
You must be signed in to change notification settings - Fork 22
Replace login_before_ready
with startup_script_behavior
#125
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
Merged
mafredri
merged 5 commits into
main
from
mafredri/replace-login_before_ready-with-startup_script_behavior
Jun 5, 2023
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
609d6e0
Replace `login_before_ready` with `startup_script_behavior`
mafredri 386efce
Add note for future deprecation removal
mafredri b9521bf
Remove `updateStartupScriptBehaviorIfLoginBeforeReady`
mafredri b6f0451
Fix PR comment
mafredri f763469
Add test cases for startup script behavior
mafredri File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,7 @@ import ( | |
func agentResource() *schema.Resource { | ||
return &schema.Resource{ | ||
Description: "Use this resource to associate an agent.", | ||
CreateContext: func(c context.Context, resourceData *schema.ResourceData, i interface{}) diag.Diagnostics { | ||
CreateContext: func(ctx context.Context, resourceData *schema.ResourceData, i interface{}) diag.Diagnostics { | ||
mafredri marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// This should be a real authentication token! | ||
resourceData.SetId(uuid.NewString()) | ||
err := resourceData.Set("token", uuid.NewString()) | ||
|
@@ -25,14 +25,14 @@ func agentResource() *schema.Resource { | |
} | ||
return updateInitScript(resourceData, i) | ||
}, | ||
ReadWithoutTimeout: func(c context.Context, resourceData *schema.ResourceData, i interface{}) diag.Diagnostics { | ||
ReadWithoutTimeout: func(ctx context.Context, resourceData *schema.ResourceData, i interface{}) diag.Diagnostics { | ||
err := resourceData.Set("token", uuid.NewString()) | ||
if err != nil { | ||
return diag.FromErr(err) | ||
} | ||
return updateInitScript(resourceData, i) | ||
}, | ||
DeleteContext: func(c context.Context, rd *schema.ResourceData, i interface{}) diag.Diagnostics { | ||
DeleteContext: func(ctx context.Context, resourceData *schema.ResourceData, i interface{}) diag.Diagnostics { | ||
return nil | ||
}, | ||
Schema: map[string]*schema.Schema{ | ||
|
@@ -131,11 +131,29 @@ func agentResource() *schema.Resource { | |
Description: "The path to a file within the workspace containing a message to display to users when they login via SSH. A typical value would be /etc/motd.", | ||
}, | ||
"login_before_ready": { | ||
Type: schema.TypeBool, | ||
Default: true, // Change default value to false in a future release. | ||
ForceNew: true, | ||
Optional: true, | ||
Description: "This option defines whether or not the user can (by default) login to the workspace before it is ready. Ready means that e.g. the startup_script is done and has exited. When enabled, users may see an incomplete workspace when logging in.", | ||
// Note: When this is removed, "startup_script_behavior" should | ||
// be set to "non-blocking" by default (instead of empty string). | ||
Type: schema.TypeBool, | ||
Default: true, | ||
ForceNew: true, | ||
Optional: true, | ||
Description: "This option defines whether or not the user can (by default) login to the workspace before it is ready. Ready means that e.g. the startup_script is done and has exited. When enabled, users may see an incomplete workspace when logging in.", | ||
Deprecated: "Configure startup_script_behavior instead. This attribute will be removed in a future version of the provider.", | ||
ConflictsWith: []string{"startup_script_behavior"}, | ||
}, | ||
"startup_script_behavior": { | ||
// Note: Our default value is "non-blocking" but we do not set | ||
// it here because we want to be able to differentiate between | ||
// the user setting this or "login_before_ready". For all | ||
// intents and purposes, until deprecation, setting | ||
// "login_before_ready = false" is equivalent to setting | ||
// "startup_script_behavior = blocking". | ||
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. We will handle this case in coder/coder, if |
||
Type: schema.TypeString, | ||
ForceNew: true, | ||
Optional: true, | ||
Description: "This option sets the behavior of the `startup_script`. When set to \"blocking\", the startup_script must exit before the workspace is ready. When set to \"non-blocking\", the startup_script may run in the background and the workspace will be ready immediately. Default is \"non-blocking\", although \"blocking\" is recommended.", | ||
ValidateFunc: validation.StringInSlice([]string{"blocking", "non-blocking"}, false), | ||
ConflictsWith: []string{"login_before_ready"}, | ||
}, | ||
"metadata": { | ||
Type: schema.TypeList, | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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'm curious if there is a way to check if
CheckContext
calledupdateStartupScriptBehaviorIfLoginBeforeReady
or if it wasReadWithoutTimeout
.BTW It would be nice to write a comment on why we need to call it in both contexts. I think that we usually stick with
ReadContext
.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.
Both are called, but I never got this method working because the value reverts at the end resulting in
Step 1/1 error: After applying this test step, the plan was not empty.
.This function was actually supposed to be removed in favor of empty default for
startup_script_behavior
, so it's good you asked.