chore: implement persistent terraform directories (experimental) (#20563)

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 commit is contained in:
Steven Masley
2025-11-13 07:50:17 -06:00
committed by GitHub
parent 14f08444a9
commit 9ca5b44b56
11 changed files with 428 additions and 81 deletions
+6 -2
View File
@@ -41,7 +41,7 @@ type executor struct {
// cachePath and files must not be used by multiple processes at once.
cachePath string
cliConfigPath string
files tfpath.Layout
files tfpath.Layouter
// used to capture execution times at various stages
timings *timingAggregator
}
@@ -536,7 +536,11 @@ func (e *executor) graph(ctx, killCtx context.Context) (string, error) {
if err != nil {
return "", err
}
args := []string{"graph"}
args := []string{
"graph",
// TODO: When the plan is present, we should probably use it?
// "-plan=" + e.files.PlanFilePath(),
}
if ver.GreaterThanOrEqual(version170) {
args = append(args, "-type=plan")
}
+1 -1
View File
@@ -58,7 +58,7 @@ func parseModulesFile(filePath string) ([]*proto.Module, error) {
// getModules returns the modules from the modules file if it exists.
// It returns nil if the file does not exist.
// Modules become available after terraform init.
func getModules(files tfpath.Layout) ([]*proto.Module, error) {
func getModules(files tfpath.Layouter) ([]*proto.Module, error) {
filePath := files.ModulesFilePath()
if _, err := os.Stat(filePath); os.IsNotExist(err) {
return nil, nil
+1 -1
View File
@@ -161,7 +161,7 @@ func (s *server) startTrace(ctx context.Context, name string, opts ...trace.Span
))...)
}
func (s *server) executor(files tfpath.Layout, stage database.ProvisionerJobTimingStage) *executor {
func (s *server) executor(files tfpath.Layouter, stage database.ProvisionerJobTimingStage) *executor {
return &executor{
server: s,
mut: s.execMut,