Skip to content

Commit fe3b825

Browse files
authored
chore: per template opt into cached terraform directories (#20609)
For experimental and dogfood purposes, this adds the ability to opt in a single template. Leaving the rest of the templates as is. For GA, this setting might be removed or changed.
1 parent edf056b commit fe3b825

File tree

22 files changed

+221
-53
lines changed

22 files changed

+221
-53
lines changed

coderd/apidoc/docs.go

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

coderd/apidoc/swagger.json

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

coderd/database/dump.sql

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
DROP VIEW template_with_names;
2+
-- Drop the column
3+
ALTER TABLE templates DROP COLUMN use_terraform_workspace_cache;
4+
5+
-- Update the template_with_names view by recreating it.
6+
CREATE VIEW template_with_names AS
7+
SELECT
8+
templates.*,
9+
COALESCE(visible_users.avatar_url, ''::text) AS created_by_avatar_url,
10+
COALESCE(visible_users.username, ''::text) AS created_by_username,
11+
COALESCE(visible_users.name, ''::text) AS created_by_name,
12+
COALESCE(organizations.name, ''::text) AS organization_name,
13+
COALESCE(organizations.display_name, ''::text) AS organization_display_name,
14+
COALESCE(organizations.icon, ''::text) AS organization_icon
15+
FROM
16+
templates
17+
LEFT JOIN
18+
visible_users
19+
ON
20+
templates.created_by = visible_users.id
21+
LEFT JOIN
22+
organizations
23+
ON templates.organization_id = organizations.id
24+
;
25+
26+
COMMENT ON VIEW template_with_names IS 'Joins in the display name information such as username, avatar, and organization name.';
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
-- Default to `false`. Users will have to manually opt into the terraform workspace cache feature.
2+
ALTER TABLE templates ADD COLUMN use_terraform_workspace_cache BOOL NOT NULL DEFAULT false;
3+
4+
COMMENT ON COLUMN templates.use_terraform_workspace_cache IS
5+
'Determines whether to keep terraform directories cached between runs for workspaces created from this template. '
6+
'When enabled, this can significantly speed up the `terraform init` step at the cost of increased disk usage. '
7+
'This is an opt-in experience, as it prevents modules from being updated, and therefore is a behavioral difference '
8+
'from the default.';
9+
;
10+
11+
-- Update the template_with_names view by recreating it.
12+
DROP VIEW template_with_names;
13+
CREATE VIEW template_with_names AS
14+
SELECT
15+
templates.*,
16+
COALESCE(visible_users.avatar_url, ''::text) AS created_by_avatar_url,
17+
COALESCE(visible_users.username, ''::text) AS created_by_username,
18+
COALESCE(visible_users.name, ''::text) AS created_by_name,
19+
COALESCE(organizations.name, ''::text) AS organization_name,
20+
COALESCE(organizations.display_name, ''::text) AS organization_display_name,
21+
COALESCE(organizations.icon, ''::text) AS organization_icon
22+
FROM
23+
templates
24+
LEFT JOIN
25+
visible_users
26+
ON
27+
templates.created_by = visible_users.id
28+
LEFT JOIN
29+
organizations
30+
ON templates.organization_id = organizations.id
31+
;
32+
33+
COMMENT ON VIEW template_with_names IS 'Joins in the display name information such as username, avatar, and organization name.';

coderd/database/modelqueries.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ func (q *sqlQuerier) GetAuthorizedTemplates(ctx context.Context, arg GetTemplate
127127
&i.MaxPortSharingLevel,
128128
&i.UseClassicParameterFlow,
129129
&i.CorsBehavior,
130+
&i.UseTerraformWorkspaceCache,
130131
&i.CreatedByAvatarURL,
131132
&i.CreatedByUsername,
132133
&i.CreatedByName,

coderd/database/models.go

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

coderd/database/queries.sql.go

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

coderd/database/queries/templates.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,8 @@ SET
173173
group_acl = $8,
174174
max_port_sharing_level = $9,
175175
use_classic_parameter_flow = $10,
176-
cors_behavior = $11
176+
cors_behavior = $11,
177+
use_terraform_workspace_cache = $12
177178
WHERE
178179
id = $1
179180
;

coderd/provisionerdserver/provisionerdserver.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,10 @@ func (s *server) acquireProtoJob(ctx context.Context, job database.ProvisionerJo
711711
ExternalAuthProviders: externalAuthProviders,
712712
// If active and experiment is enabled, allow workspace reuse existing TF
713713
// workspaces (directories) for a faster startup.
714-
ExpReuseTerraformWorkspace: ptr.Ref(activeVersion && s.Experiments.Enabled(codersdk.ExperimentTerraformWorkspace)),
714+
ExpReuseTerraformWorkspace: ptr.Ref(s.Experiments.Enabled(codersdk.ExperimentTerraformWorkspace) && // Experiment required
715+
template.UseTerraformWorkspaceCache && // Template setting
716+
activeVersion, // Only for active versions
717+
),
715718
Metadata: &sdkproto.Metadata{
716719
CoderUrl: s.AccessURL.String(),
717720
WorkspaceTransition: transition,

0 commit comments

Comments
 (0)