-
Notifications
You must be signed in to change notification settings - Fork 943
feat: run a terraform plan before creating workspaces with the given template parameters #1732
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
Merged
Changes from 1 commit
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
3e9ecc3
feat: add new provisioner job type template_version_plan
deansheather cf033aa
feat: finish implementing workspace planning
deansheather bafe1c1
merge main
deansheather cfe34af
big tests
deansheather 0d03a39
fix: workspaces: relax error assertion
johnstcn 4078fd1
fix
deansheather 8d04749
fixup! fix
deansheather 4b06c72
gen
deansheather 2fee23a
fixup! gen
deansheather 6b95e54
remove heavy object nesting in tests
deansheather 0b6d083
Rename template version plan to template version dry run
deansheather 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
big tests
- Loading branch information
commit cfe34afcde3e257f497acf3d2a2aeba0459ae1ae
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
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 |
---|---|---|
|
@@ -167,6 +167,15 @@ func (api *API) templateVersionParameters(rw http.ResponseWriter, r *http.Reques | |
func (api *API) createTemplateVersionPlan(rw http.ResponseWriter, r *http.Request) { | ||
deansheather marked this conversation as resolved.
Show resolved
Hide resolved
|
||
apiKey := httpmw.APIKey(r) | ||
templateVersion := httpmw.TemplateVersionParam(r) | ||
if !api.Authorize(rw, r, rbac.ActionRead, templateVersion) { | ||
return | ||
} | ||
// We use the workspace RBAC check since we don't want to allow plans if the | ||
// user can't create workspaces. | ||
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. Technically correct - the best kind of correct. |
||
if !api.Authorize(rw, r, rbac.ActionCreate, | ||
rbac.ResourceWorkspace.InOrg(templateVersion.OrganizationID).WithOwner(apiKey.UserID.String())) { | ||
return | ||
} | ||
|
||
var req codersdk.CreateTemplateVersionPlanRequest | ||
if !httpapi.Read(rw, r, &req) { | ||
|
@@ -238,7 +247,7 @@ func (api *API) createTemplateVersionPlan(rw http.ResponseWriter, r *http.Reques | |
} | ||
|
||
func (api *API) templateVersionPlan(rw http.ResponseWriter, r *http.Request) { | ||
job, ok := getTemplateVersionPlanJob(api.Database, rw, r) | ||
job, ok := api.fetchTemplateVersionPlanJob(rw, r) | ||
if !ok { | ||
return | ||
} | ||
|
@@ -247,7 +256,7 @@ func (api *API) templateVersionPlan(rw http.ResponseWriter, r *http.Request) { | |
} | ||
|
||
func (api *API) templateVersionPlanResources(rw http.ResponseWriter, r *http.Request) { | ||
job, ok := getTemplateVersionPlanJob(api.Database, rw, r) | ||
job, ok := api.fetchTemplateVersionPlanJob(rw, r) | ||
if !ok { | ||
return | ||
} | ||
|
@@ -256,7 +265,7 @@ func (api *API) templateVersionPlanResources(rw http.ResponseWriter, r *http.Req | |
} | ||
|
||
func (api *API) templateVersionPlanLogs(rw http.ResponseWriter, r *http.Request) { | ||
job, ok := getTemplateVersionPlanJob(api.Database, rw, r) | ||
job, ok := api.fetchTemplateVersionPlanJob(rw, r) | ||
if !ok { | ||
return | ||
} | ||
|
@@ -265,10 +274,16 @@ func (api *API) templateVersionPlanLogs(rw http.ResponseWriter, r *http.Request) | |
} | ||
|
||
func (api *API) templateVersionPlanCancel(rw http.ResponseWriter, r *http.Request) { | ||
job, ok := getTemplateVersionPlanJob(api.Database, rw, r) | ||
templateVersion := httpmw.TemplateVersionParam(r) | ||
|
||
job, ok := api.fetchTemplateVersionPlanJob(rw, r) | ||
if !ok { | ||
return | ||
} | ||
if !api.Authorize(rw, r, rbac.ActionUpdate, | ||
rbac.ResourceWorkspace.InOrg(templateVersion.OrganizationID).WithOwner(job.InitiatorID.String())) { | ||
return | ||
} | ||
|
||
if job.CompletedAt.Valid { | ||
httpapi.Write(rw, http.StatusPreconditionFailed, httpapi.Response{ | ||
|
@@ -302,12 +317,14 @@ func (api *API) templateVersionPlanCancel(rw http.ResponseWriter, r *http.Reques | |
}) | ||
} | ||
|
||
func getTemplateVersionPlanJob(db database.Store, rw http.ResponseWriter, r *http.Request) (database.ProvisionerJob, bool) { | ||
func (api *API) fetchTemplateVersionPlanJob(rw http.ResponseWriter, r *http.Request) (database.ProvisionerJob, bool) { | ||
var ( | ||
apiKey = httpmw.APIKey(r) | ||
templateVersion = httpmw.TemplateVersionParam(r) | ||
jobID = chi.URLParam(r, "jobID") | ||
) | ||
if !api.Authorize(rw, r, rbac.ActionRead, templateVersion) { | ||
return database.ProvisionerJob{}, false | ||
} | ||
|
||
jobUUID, err := uuid.Parse(jobID) | ||
if err != nil { | ||
|
@@ -317,7 +334,7 @@ func getTemplateVersionPlanJob(db database.Store, rw http.ResponseWriter, r *htt | |
return database.ProvisionerJob{}, false | ||
} | ||
|
||
job, err := db.GetProvisionerJobByID(r.Context(), jobUUID) | ||
job, err := api.Database.GetProvisionerJobByID(r.Context(), jobUUID) | ||
if xerrors.Is(err, sql.ErrNoRows) { | ||
httpapi.Forbidden(rw) | ||
return database.ProvisionerJob{}, false | ||
|
@@ -332,9 +349,9 @@ func getTemplateVersionPlanJob(db database.Store, rw http.ResponseWriter, r *htt | |
httpapi.Forbidden(rw) | ||
return database.ProvisionerJob{}, false | ||
} | ||
// TODO: real RBAC | ||
if job.InitiatorID != apiKey.UserID { | ||
httpapi.Forbidden(rw) | ||
// Do a workspace resource check since it's basically a workspace plan. | ||
if !api.Authorize(rw, r, rbac.ActionRead, | ||
rbac.ResourceWorkspace.InOrg(templateVersion.OrganizationID).WithOwner(job.InitiatorID.String())) { | ||
return database.ProvisionerJob{}, false | ||
} | ||
|
||
|
@@ -645,12 +662,13 @@ func (api *API) templateVersionLogs(rw http.ResponseWriter, r *http.Request) { | |
|
||
func convertTemplateVersion(version database.TemplateVersion, job codersdk.ProvisionerJob) codersdk.TemplateVersion { | ||
return codersdk.TemplateVersion{ | ||
ID: version.ID, | ||
TemplateID: &version.TemplateID.UUID, | ||
CreatedAt: version.CreatedAt, | ||
UpdatedAt: version.UpdatedAt, | ||
Name: version.Name, | ||
Job: job, | ||
Readme: version.Readme, | ||
ID: version.ID, | ||
TemplateID: &version.TemplateID.UUID, | ||
OrganizationID: version.OrganizationID, | ||
CreatedAt: version.CreatedAt, | ||
UpdatedAt: version.UpdatedAt, | ||
Name: version.Name, | ||
Job: job, | ||
Readme: version.Readme, | ||
} | ||
} |
Oops, something went wrong.
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.
TODO: open an issue
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.
Opened two issues:
#1872 - for integrating with frontend
#1873 - for reprompting for values in CLI