Skip to content

Commit 1e8385d

Browse files
committed
feat: pass flag to terraform provider when prebuilt workspace claimed
Signed-off-by: Danny Kopping <dannykopping@gmail.com>
1 parent bd65914 commit 1e8385d

File tree

9 files changed

+219
-190
lines changed

9 files changed

+219
-190
lines changed

cli/testdata/coder_provisioner_list_--output_json.golden

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"last_seen_at": "====[timestamp]=====",
88
"name": "test",
99
"version": "v0.0.0-devel",
10-
"api_version": "1.4",
10+
"api_version": "1.5",
1111
"provisioners": [
1212
"echo"
1313
],

coderd/provisionerdserver/provisionerdserver.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,7 @@ func (s *server) acquireProtoJob(ctx context.Context, job database.ProvisionerJo
646646
WorkspaceOwnerLoginType: string(owner.LoginType),
647647
WorkspaceOwnerRbacRoles: ownerRbacRoles,
648648
IsPrebuild: input.IsPrebuild,
649+
IsPrebuildClaim: input.IsPrebuildClaim,
649650
},
650651
LogLevel: input.LogLevel,
651652
},
@@ -2471,11 +2472,11 @@ type TemplateVersionImportJob struct {
24712472

24722473
// WorkspaceProvisionJob is the payload for the "workspace_provision" job type.
24732474
type WorkspaceProvisionJob struct {
2474-
WorkspaceBuildID uuid.UUID `json:"workspace_build_id"`
2475-
DryRun bool `json:"dry_run"`
2476-
IsPrebuild bool `json:"is_prebuild,omitempty"`
2477-
PrebuildClaimedByUser uuid.UUID `json:"prebuild_claimed_by,omitempty"`
2478-
LogLevel string `json:"log_level,omitempty"`
2475+
WorkspaceBuildID uuid.UUID `json:"workspace_build_id"`
2476+
DryRun bool `json:"dry_run"`
2477+
IsPrebuild bool `json:"is_prebuild,omitempty"`
2478+
IsPrebuildClaim bool `json:"is_prebuild_claim,omitempty"`
2479+
LogLevel string `json:"log_level,omitempty"`
24792480
}
24802481

24812482
// TemplateVersionDryRunJob is the payload for the "template_version_dry_run" job type.

coderd/workspaces.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,7 @@ func createWorkspace(
713713
builder = builder.TemplateVersionPresetID(req.TemplateVersionPresetID)
714714
}
715715
if claimedWorkspace != nil {
716-
builder = builder.MarkPrebuildClaimedBy(owner.ID)
716+
builder = builder.MarkPrebuildClaim()
717717
}
718718

719719
if req.EnableDynamicParameters && api.Experiments.Enabled(codersdk.ExperimentDynamicParameters) {

coderd/wsbuilder/wsbuilder.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,7 @@ type Builder struct {
7676
parameterValues *[]string
7777
templateVersionPresetParameterValues []database.TemplateVersionPresetParameter
7878

79-
prebuild bool
80-
prebuildClaimedBy uuid.UUID
79+
prebuild, prebuildClaim bool
8180

8281
verifyNoLegacyParametersOnce bool
8382
}
@@ -174,15 +173,17 @@ func (b Builder) RichParameterValues(p []codersdk.WorkspaceBuildParameter) Build
174173
return b
175174
}
176175

176+
// MarkPrebuild indicates that a prebuilt workspace is being built.
177177
func (b Builder) MarkPrebuild() Builder {
178178
// nolint: revive
179179
b.prebuild = true
180180
return b
181181
}
182182

183-
func (b Builder) MarkPrebuildClaimedBy(userID uuid.UUID) Builder {
183+
// MarkPrebuildClaim indicates that a prebuilt workspace is being claimed.
184+
func (b Builder) MarkPrebuildClaim() Builder {
184185
// nolint: revive
185-
b.prebuildClaimedBy = userID
186+
b.prebuildClaim = true
186187
return b
187188
}
188189

@@ -322,10 +323,10 @@ func (b *Builder) buildTx(authFunc func(action policy.Action, object rbac.Object
322323

323324
workspaceBuildID := uuid.New()
324325
input, err := json.Marshal(provisionerdserver.WorkspaceProvisionJob{
325-
WorkspaceBuildID: workspaceBuildID,
326-
LogLevel: b.logLevel,
327-
IsPrebuild: b.prebuild,
328-
PrebuildClaimedByUser: b.prebuildClaimedBy,
326+
WorkspaceBuildID: workspaceBuildID,
327+
LogLevel: b.logLevel,
328+
IsPrebuild: b.prebuild,
329+
IsPrebuildClaim: b.prebuildClaim,
329330
})
330331
if err != nil {
331332
return nil, nil, nil, BuildError{

provisioner/terraform/provision.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,9 @@ func provisionEnv(
273273
if metadata.GetIsPrebuild() {
274274
env = append(env, provider.IsPrebuildEnvironmentVariable()+"=true")
275275
}
276+
if metadata.GetIsPrebuildClaim() {
277+
env = append(env, provider.IsPrebuildClaimEnvironmentVariable()+"=true")
278+
}
276279

277280
for key, value := range provisionersdk.AgentScriptEnv() {
278281
env = append(env, key+"="+value)

provisionerd/proto/version.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,17 @@ import "github.com/coder/coder/v2/apiversion"
1212
//
1313
// API v1.4:
1414
// - Add new field named `devcontainers` in the Agent.
15+
//
16+
// API v1.5:
17+
// - Add new field named `is_prebuild_claim` in the Metadata message.
1518
const (
1619
CurrentMajor = 1
17-
CurrentMinor = 4
20+
CurrentMinor = 5
1821
)
1922

2023
// CurrentVersion is the current provisionerd API version.
2124
// Breaking changes to the provisionerd API **MUST** increment
2225
// CurrentMajor above.
26+
// Non-breaking changes to the provisionerd API **MUST** increment
27+
// CurrentMinor above.
2328
var CurrentVersion = apiversion.New(CurrentMajor, CurrentMinor)

provisionersdk/proto/provisioner.pb.go

Lines changed: 183 additions & 172 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

provisionersdk/proto/provisioner.proto

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,8 +293,9 @@ message Metadata {
293293
string workspace_build_id = 17;
294294
string workspace_owner_login_type = 18;
295295
repeated Role workspace_owner_rbac_roles = 19;
296-
bool is_prebuild = 20;
297-
string running_workspace_agent_token = 21;
296+
bool is_prebuild = 20; // Indicates that a prebuilt workspace is being built.
297+
string running_workspace_agent_token = 21; // Preserves the running agent token of a prebuilt workspace so it can reinitialize.
298+
bool is_prebuild_claim = 22; // Indicates that a prebuilt workspace is being claimed.
298299
}
299300

300301
// Config represents execution configuration shared by all subsequent requests in the Session

site/e2e/provisionerGenerated.ts

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)