Skip to content

Commit

Permalink
fix: use terraform for terragrunt tests
Browse files Browse the repository at this point in the history
  • Loading branch information
leg100 committed Jul 1, 2024
1 parent d1d9b4e commit e0cd4b3
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 7 deletions.
1 change: 1 addition & 0 deletions internal/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ func startApp(cfg config, stdout io.Writer) (*app, error) {
Logger: logger,
Workdir: workdir,
UserEnvs: cfg.Envs,
UserArgs: cfg.Args,
})
modules := module.NewService(module.ServiceOptions{
TaskService: tasks,
Expand Down
2 changes: 2 additions & 0 deletions internal/app/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type config struct {
WorkDir string
DataDir string
Envs []string
Args []string
Terragrunt bool

loggingOptions logging.Options
Expand All @@ -48,6 +49,7 @@ func parse(stderr io.Writer, args []string) (config, error) {
fs.IntVar(&cfg.MaxTasks, 't', "max-tasks", 2*runtime.NumCPU(), "The maximum number of parallel tasks.")
fs.StringVar(&cfg.DataDir, 0, "data-dir", defaultDataDir, "Directory in which to store plan files.")
fs.StringListVar(&cfg.Envs, 'e', "env", "Environment variable to pass to terraform process. Can set more than once.")
fs.StringListVar(&cfg.Args, 'a', "arg", "CLI arg to pass to terraform process. Can set more than once.")
fs.StringEnumVar(&cfg.FirstPage, 'f', "first-page", "The first page to open on startup.", "modules", "workspaces", "runs", "tasks", "logs")
fs.BoolVar(&cfg.Debug, 'd', "debug", "Log bubbletea messages to messages.log")
fs.BoolVar(&cfg.version, 'v', "version", "Print version.")
Expand Down
5 changes: 3 additions & 2 deletions internal/app/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ const mirrorConfigPath = "../../mirror/mirror.tfrc"

type configOption func(cfg *config)

func withProgram(prog string) configOption {
func withTerragrunt() configOption {
return func(cfg *config) {
cfg.Program = prog
cfg.Program = "terragrunt"
cfg.Args = []string{"--terragrunt-tfpath", "terraform"}
}
}

Expand Down
6 changes: 3 additions & 3 deletions internal/app/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ func TestMain(m *testing.M) {
os.Remove(file)
}
}
// Remove all .terraform-cache directories from testdata. These can sometimes be
// Remove all .terragrunt-cache directories from testdata. These can sometimes be
// created outside of tests, e.g. running pug within the repo, but none the
// of tests should start with a .terraform-cache directory, otherwise it
// of tests should start with a .terragrunt-cache directory, otherwise it
// can cause unintended consequences.
{
dirs, _ := filepath.Glob("./testdata/*/modules/*/.terraform-cache")
dirs, _ := filepath.Glob("./testdata/*/modules/*/.terragrunt-cache")
for _, dir := range dirs {
os.RemoveAll(dir)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/app/terragrunt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func skipIfTerragruntNotFound(t *testing.T) {
}

func setupAndInitTerragruntModule(t *testing.T) *testModel {
tm := setup(t, "./testdata/single_terragrunt_module", withProgram("terragrunt"))
tm := setup(t, "./testdata/single_terragrunt_module", withTerragrunt())

// Expect single module to be listed
waitFor(t, tm, func(s string) bool {
Expand Down
2 changes: 2 additions & 0 deletions internal/task/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type ServiceOptions struct {
Logger logging.Interface
Workdir internal.Workdir
UserEnvs []string
UserArgs []string
}

func NewService(opts ServiceOptions) *Service {
Expand All @@ -39,6 +40,7 @@ func NewService(opts ServiceOptions) *Service {
program: opts.Program,
workdir: opts.Workdir,
userEnvs: opts.UserEnvs,
userArgs: opts.UserArgs,
}

svc := &Service{
Expand Down
4 changes: 3 additions & 1 deletion internal/task/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ type factory struct {
workdir internal.Workdir
// Additional user-supplied environment variables.
userEnvs []string
// Additional user-supplied CLI args.
userArgs []string
}

type CreateOptions struct {
Expand Down Expand Up @@ -134,7 +136,7 @@ func (f *factory) newTask(opts CreateOptions) (*Task, error) {
program: f.program,
Command: opts.Command,
Path: filepath.Join(f.workdir.String(), opts.Path),
Args: opts.Args,
Args: append(f.userArgs, opts.Args...),
AdditionalEnv: append(f.userEnvs, opts.Env...),
JSON: opts.JSON,
Blocking: opts.Blocking,
Expand Down

0 comments on commit e0cd4b3

Please sign in to comment.