Skip to content

Conversation

@Emyrk
Copy link
Member

@Emyrk Emyrk commented Oct 29, 2025

Screencast.From.2025-10-30.14-28-48.webm

Behavior change

Prior to this, every workspace build ran terraform init in a fresh directory. This would mean the modules are downloaded fresh. If the module is not pinned, subsequent workspace builds would have different modules.

This change locks in a modules "version". If different provisioners warm their cache at different times, each provisioner could have a different truth for the module "version"

Implementation

tfpath.go is the implementation of where all terraform file management occurs. This PR makes the implementation an interface (unfortunate, will not use an interface when released).

type LayoutInterface interface {
	WorkDirectory() string
	StateFilePath() string
	// ...
	Cleanup(ctx context.Context, logger slog.Logger, fs afero.Fs)
	CleanStaleSessions(ctx context.Context, logger slog.Logger, fs afero.Fs, now time.Time) error
}

This moves almost the entire implementation into tfpath/x/tfpath.go. All provisioned workspaces use the new x package when the experiment is enabled.

Implementation details

  • All terraform.tfstate files are written to a subdirectory terraform.tfstate.d/<session>.
  • All terraform cli execs use the new terraform workspace context

TODO:

  • Make sure modules are pinned to allow this
  • Add more testing. Since it is almost all terraform interactions, it has only been manually tested so far. Hence the x package

@Emyrk Emyrk force-pushed the stevenmasley/cache_init_exp branch from cbc9d5d to e5c2b88 Compare October 30, 2025 14:59
@Emyrk Emyrk force-pushed the stevenmasley/cache_init_feature branch from 0c75392 to a92dd47 Compare October 30, 2025 14:59
@Emyrk Emyrk changed the title chore: pass through file locations more cleanly chore: implement experimental persistent terraform directories Oct 30, 2025
@Emyrk Emyrk changed the title chore: implement experimental persistent terraform directories chore: implement persistent terraform directories (experimental) Oct 30, 2025
@Emyrk Emyrk force-pushed the stevenmasley/cache_init_feature branch from 7e07051 to 39f81f0 Compare October 30, 2025 16:12
@Emyrk Emyrk force-pushed the stevenmasley/cache_init_exp branch from e5c2b88 to 87b5981 Compare October 30, 2025 16:12
@Emyrk Emyrk force-pushed the stevenmasley/cache_init_feature branch from 39f81f0 to b2d70af Compare October 30, 2025 16:25
@Emyrk Emyrk force-pushed the stevenmasley/cache_init_exp branch from 87b5981 to 27759a1 Compare October 30, 2025 16:25
@Emyrk Emyrk force-pushed the stevenmasley/cache_init_feature branch 2 times, most recently from b39cb1f to c21c9c9 Compare October 30, 2025 16:28
@Emyrk Emyrk force-pushed the stevenmasley/cache_init_exp branch 2 times, most recently from 4f4daa1 to fb8dd3a Compare October 30, 2025 16:49
@Emyrk Emyrk force-pushed the stevenmasley/cache_init_feature branch 2 times, most recently from f95e7dc to 95f149a Compare October 30, 2025 16:54
@Emyrk Emyrk force-pushed the stevenmasley/cache_init_exp branch 2 times, most recently from 5b3f9f8 to 5923703 Compare October 30, 2025 17:02
@Emyrk Emyrk force-pushed the stevenmasley/cache_init_feature branch 3 times, most recently from 27f40aa to cc32f8e Compare October 31, 2025 15:36
@github-actions github-actions bot added the stale This issue is like stale bread. label Nov 8, 2025
@Emyrk Emyrk force-pushed the stevenmasley/cache_init_feature branch from cc32f8e to 41a4de5 Compare November 10, 2025 15:30
@Emyrk Emyrk force-pushed the stevenmasley/cache_init_exp branch 2 times, most recently from 2f45b69 to 86c520b Compare November 10, 2025 15:32
@Emyrk Emyrk force-pushed the stevenmasley/cache_init_feature branch from 41a4de5 to 4b39bbb Compare November 10, 2025 15:32
@Emyrk Emyrk force-pushed the stevenmasley/cache_init_feature branch from 3d4b0f3 to 0d0a43d Compare November 12, 2025 16:48
@Emyrk Emyrk force-pushed the stevenmasley/cache_init_exp branch 2 times, most recently from 4005dbf to fa93b50 Compare November 12, 2025 16:53
@Emyrk Emyrk force-pushed the stevenmasley/cache_init_feature branch from 0d0a43d to 88e70bb Compare November 12, 2025 16:53
@Emyrk Emyrk force-pushed the stevenmasley/cache_init_exp branch from fa93b50 to 17ad382 Compare November 12, 2025 17:54
@Emyrk Emyrk force-pushed the stevenmasley/cache_init_feature branch 2 times, most recently from 63b00e6 to 5a5ee0a Compare November 12, 2025 18:17
@Emyrk Emyrk force-pushed the stevenmasley/cache_init_exp branch from 17ad382 to 388275e Compare November 12, 2025 18:17
@Emyrk Emyrk force-pushed the stevenmasley/cache_init_feature branch from 5a5ee0a to 0a6762b Compare November 12, 2025 18:25
@Emyrk Emyrk force-pushed the stevenmasley/cache_init_exp branch 2 times, most recently from 71a5ca9 to a51ae86 Compare November 12, 2025 19:20
@Emyrk Emyrk force-pushed the stevenmasley/cache_init_feature branch from 0a6762b to 705a746 Compare November 12, 2025 19:20
@Emyrk Emyrk force-pushed the stevenmasley/cache_init_exp branch from a51ae86 to a6914e7 Compare November 12, 2025 19:59
@Emyrk Emyrk force-pushed the stevenmasley/cache_init_feature branch 2 times, most recently from 1b05f76 to e469fd5 Compare November 12, 2025 20:01
@Emyrk Emyrk force-pushed the stevenmasley/cache_init_exp branch from a6914e7 to 93aca5b Compare November 12, 2025 20:01
@Emyrk Emyrk force-pushed the stevenmasley/cache_init_feature branch from e469fd5 to 4096ad8 Compare November 12, 2025 20:15
Base automatically changed from stevenmasley/cache_init_exp to main November 12, 2025 20:26
@Emyrk Emyrk force-pushed the stevenmasley/cache_init_feature branch 2 times, most recently from 49464f4 to 52e2fa1 Compare November 12, 2025 20:37
@Emyrk Emyrk force-pushed the stevenmasley/cache_init_feature branch from 52e2fa1 to b0b5edb Compare November 12, 2025 22:53
@Emyrk Emyrk merged commit 9ca5b44 into main Nov 13, 2025
31 checks passed
@Emyrk Emyrk deleted the stevenmasley/cache_init_feature branch November 13, 2025 13:50
@github-actions github-actions bot locked and limited conversation to collaborators Nov 13, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants