diff --git a/internal/postprocessor/execv/gocmd/gocmd.go b/internal/postprocessor/execv/gocmd/gocmd.go index 0224622e6a00..cbda042eab96 100644 --- a/internal/postprocessor/execv/gocmd/gocmd.go +++ b/internal/postprocessor/execv/gocmd/gocmd.go @@ -138,3 +138,10 @@ func EditReplace(dir, mod, modPath string) error { } return c.Run() } + +// WorkUse updates the go.work file for added modules. +func WorkUse(dir string) error { + c := execv.Command("go", "work", "use", "-r", ".") + c.Dir = dir + return c.Run() +} diff --git a/internal/postprocessor/main.go b/internal/postprocessor/main.go index 38707c6cba68..319353f93f5a 100644 --- a/internal/postprocessor/main.go +++ b/internal/postprocessor/main.go @@ -250,7 +250,11 @@ func (p *postProcessor) generateModule(modPath, importPath string) error { return err } log.Printf("Creating %s/go.mod", modPath) - return gocmd.ModInit(modPath, importPath) + if err := gocmd.ModInit(modPath, importPath); err != nil { + return err + } + log.Print("Updating workspace") + return gocmd.WorkUse(p.googleCloudDir) } func (p *postProcessor) generateVersionFile(moduleName, path string) error {