- Notifications
You must be signed in to change notification settings - Fork907
chore: pass previous values into terraform apply#17696
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
d565cb5
b6d3d67
520fe49
690daac
692bab8
81ad901
c917ab0
28b2b9f
3fb8a22
2b642a6
fd6cdf5
2b41b8f
8a0dab1
d9fc4cc
fb2f081
97a99aa
9f3a8fd
bc38bfa
a7ab88c
52dcd80
3eb22f4
cb0f145
2774c07
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -549,6 +549,30 @@ func (s *server) acquireProtoJob(ctx context.Context, job database.ProvisionerJo | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return nil, failJob(fmt.Sprintf("convert workspace transition: %s", err)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// A previous workspace build exists | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
var lastWorkspaceBuildParameters []database.WorkspaceBuildParameter | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if workspaceBuild.BuildNumber > 1 { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// TODO: Should we fetch the last build that succeeded? This fetches the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// previous build regardless of the status of the build. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines +555 to +556 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. If we check for the last successful build, we could end up with no builds. What do we do then? Do we just settle for the last build? IMO just checking the previous build is simpler conceptually, and is more likely to be what users expect. 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. Yea, the wsbuilder just takes the last build regardless of status. Just feels a bit off since the tfstate is different if the previous failed. 🤷♂️ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
buildNum := workspaceBuild.BuildNumber - 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
previous, err := s.Database.GetWorkspaceBuildByWorkspaceIDAndBuildNumber(ctx, database.GetWorkspaceBuildByWorkspaceIDAndBuildNumberParams{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
WorkspaceID: workspaceBuild.WorkspaceID, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
BuildNumber: buildNum, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines +555 to +561 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. What problem are weactually trying to solve here?
coder/coderd/wsbuilder/wsbuilder.go Lines 650 to 669 inaf2941b
Given that this is the case, why do we need to do this extra work forall jobs? Isn't this just for template version import jobs? 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. That does it in The terraform provider now enforces monotonicity:coder/terraform-provider-coder#392 So this is duplicating that check in wsbuilder at 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. Maybe I could pass the values from wsbuilder to here via the job? Rather than refetch 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 like that approach -- 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. @johnstcn actually, as much as I'd like to have Current params, workspace data, external auth, etc. We store very little in the job payload: coder/coderd/provisionerdserver/provisionerdserver.go Lines 2498 to 2504 ina7ab88c
So I'm going to keep this as a refetching. Ideally I would use the same function to fetch the previous params in both cases, however at 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. Ahh... gotcha. That's unfortunate :( 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. It is, I think it would be a large refactor to move all the fields into wsbuilder | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// If the error is ErrNoRows, then assume previous values are empty. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if err != nil && !xerrors.Is(err, sql.ErrNoRows) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return nil, xerrors.Errorf("get last build with number=%d: %w", buildNum, err) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if err == nil { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
lastWorkspaceBuildParameters, err = s.Database.GetWorkspaceBuildParameters(ctx, previous.ID) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if err != nil { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return nil, xerrors.Errorf("get last build parameters %q: %w", previous.ID, err) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
workspaceBuildParameters, err := s.Database.GetWorkspaceBuildParameters(ctx, workspaceBuild.ID) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if err != nil { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return nil, failJob(fmt.Sprintf("get workspace build parameters: %s", err)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
@@ -625,12 +649,13 @@ func (s *server) acquireProtoJob(ctx context.Context, job database.ProvisionerJo | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
protoJob.Type = &proto.AcquiredJob_WorkspaceBuild_{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
WorkspaceBuild: &proto.AcquiredJob_WorkspaceBuild{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
WorkspaceBuildId: workspaceBuild.ID.String(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
WorkspaceName: workspace.Name, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
State: workspaceBuild.ProvisionerState, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
RichParameterValues: convertRichParameterValues(workspaceBuildParameters), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
PreviousParameterValues: convertRichParameterValues(lastWorkspaceBuildParameters), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
VariableValues: asVariableValues(templateVariables), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ExternalAuthProviders: externalAuthProviders, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Metadata: &sdkproto.Metadata{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
CoderUrl: s.AccessURL.String(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
WorkspaceTransition: transition, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Large diffs are not rendered by default.
Uh oh!
There was an error while loading.Please reload this page.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -16,6 +16,9 @@ import "github.com/coder/coder/v2/apiversion" | ||
// API v1.5: | ||
// - Add new field named `prebuilt_workspace_build_stage` enum in the Metadata message. | ||
// - Add `plan` and `module_files` fields to `CompletedJob.TemplateImport`. | ||
// - Add previous parameter values to 'WorkspaceBuild' jobs. Provisioner passes | ||
// the previous values for the `terraform apply` to enforce monotonicity | ||
// in the terraform provider. | ||
Comment on lines +19 to +21 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. 👍 | ||
const ( | ||
CurrentMajor = 1 | ||
CurrentMinor = 5 | ||
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.