Skip to content

Commit fbe79b7

Browse files
committed
chore: add experiment toggle for terraform workspace caching
1 parent 41faf32 commit fbe79b7

File tree

6 files changed

+22
-0
lines changed

6 files changed

+22
-0
lines changed

cli/server.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1476,6 +1476,7 @@ func newProvisionerDaemon(
14761476
Listener: terraformServer,
14771477
Logger: provisionerLogger,
14781478
WorkDirectory: workDir,
1479+
Experiments: coderAPI.Experiments,
14791480
},
14801481
CachePath: tfDir,
14811482
Tracer: tracer,

codersdk/deployment.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3646,6 +3646,8 @@ const (
36463646
ExperimentOAuth2 Experiment = "oauth2" // Enables OAuth2 provider functionality.
36473647
ExperimentMCPServerHTTP Experiment = "mcp-server-http" // Enables the MCP HTTP server functionality.
36483648
ExperimentWorkspaceSharing Experiment = "workspace-sharing" // Enables updating workspace ACLs for sharing with users and groups.
3649+
// ExperimentTerraformWorkspace is named after the "Terraform Workspaces" feature, not to be confused with Coder Workspaces.
3650+
ExperimentTerraformWorkspace Experiment = "terraform-workspaces" // Enables reuse of existing terraform directory for builds
36493651
)
36503652

36513653
func (e Experiment) DisplayName() string {
@@ -3666,6 +3668,8 @@ func (e Experiment) DisplayName() string {
36663668
return "MCP HTTP Server Functionality"
36673669
case ExperimentWorkspaceSharing:
36683670
return "Workspace Sharing"
3671+
case ExperimentTerraformWorkspace:
3672+
return "Terraform Workspace Caching"
36693673
default:
36703674
// Split on hyphen and convert to title case
36713675
// e.g. "web-push" -> "Web Push", "mcp-server-http" -> "Mcp Server Http"

enterprise/cli/provisionerdaemonstart.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"github.com/coder/coder/v2/cli/clilog"
2424
"github.com/coder/coder/v2/cli/cliui"
2525
"github.com/coder/coder/v2/cli/cliutil"
26+
"github.com/coder/coder/v2/coderd"
2627
"github.com/coder/coder/v2/coderd/database"
2728
"github.com/coder/coder/v2/codersdk"
2829
"github.com/coder/coder/v2/codersdk/drpcsdk"
@@ -48,6 +49,7 @@ func (r *RootCmd) provisionerDaemonStart() *serpent.Command {
4849
preSharedKey string
4950
provisionerKey string
5051
verbose bool
52+
experiments []string
5153

5254
prometheusEnable bool
5355
prometheusAddress string
@@ -186,6 +188,7 @@ func (r *RootCmd) provisionerDaemonStart() *serpent.Command {
186188
Listener: terraformServer,
187189
Logger: logger.Named("terraform"),
188190
WorkDirectory: tempDir,
191+
Experiments: coderd.ReadExperiments(logger, experiments),
189192
},
190193
CachePath: cacheDir,
191194
})
@@ -378,6 +381,14 @@ func (r *RootCmd) provisionerDaemonStart() *serpent.Command {
378381
Value: serpent.StringOf(&prometheusAddress),
379382
Default: "127.0.0.1:2112",
380383
},
384+
{
385+
Name: "Experiments",
386+
Description: "Enable one or more experiments. These are not ready for production. Separate multiple experiments with commas, or enter '*' to opt-in to all available experiments.",
387+
Flag: "experiments",
388+
Env: "CODER_EXPERIMENTS",
389+
Value: serpent.StringArrayOf(&experiments),
390+
YAML: "experiments",
391+
},
381392
}
382393
orgContext.AttachOptions(cmd)
383394

enterprise/coderd/coderdenttest/coderdenttest.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,7 @@ func newExternalProvisionerDaemon(t testing.TB, client *codersdk.Client, org uui
414414
ServeOptions: &provisionersdk.ServeOptions{
415415
Listener: provisionerSrv,
416416
WorkDirectory: t.TempDir(),
417+
Experiments: codersdk.Experiments{},
417418
},
418419
}))
419420
}()

provisionersdk/serve.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"storj.io/drpc/drpcserver"
1616

1717
"cdr.dev/slog"
18+
"github.com/coder/coder/v2/codersdk"
1819
"github.com/coder/coder/v2/codersdk/drpcsdk"
1920

2021
"github.com/coder/coder/v2/coderd/tracing"
@@ -30,6 +31,7 @@ type ServeOptions struct {
3031
Logger slog.Logger
3132
WorkDirectory string
3233
ExternalProvisioner bool
34+
Experiments codersdk.Experiments
3335
}
3436

3537
type Server interface {

provisionersdk/session.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,13 @@ func (p *protoServer) Session(stream proto.DRPCProvisioner_SessionStream) error
6767
s.logLevel = proto.LogLevel_value[strings.ToUpper(s.Config.ProvisionerLogLevel)]
6868
}
6969

70+
// Extract the template source archive into the work directory.
7071
err = s.Files.ExtractArchive(s.Context(), s.Logger, afero.NewOsFs(), s.Config)
7172
if err != nil {
7273
return xerrors.Errorf("extract archive: %w", err)
7374
}
75+
76+
// Handle requests, which will amount to terraform cli execs.
7477
return s.handleRequests()
7578
}
7679

0 commit comments

Comments
 (0)