Hey guys, I'm struggling with a bug in a set of Dagger tasks that I'm writing in Go.
Basically, I'm fetching a private Git repository with a certain Terragrunt-based root-modules; this part works well. When I'm running a command to generate the output of the plan (here's the scenario, file generation), let's say WithExec([]string{"sh", "-c", "terragrunt plan -out=output.tfplan"}). it doesn't fail, but it does not generate the expected output.tfplan in the container. I'm even inspecting the Entries and printing the standard output, and nope! no file at all.
What I'm doing wrong?
// Generate the terraform plan file.
_, _ = tg.
WithUnixSocket(sshSocketPath, client.Host().UnixSocket(sshSocketPath)).
WithEnvVariable("SSH_AUTH_SOCK", sshSocketPath).
WithEnvVariable("GIT_SSH_COMMAND", "ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=accept-new").
WithExec([]string{"sh", "-c", "terragrunt plan -out=output.tfplan"}).
Stdout(ctx)
// Export the plan output.
planOutput, planErr := tg.
WithUnixSocket(sshSocketPath, client.Host().UnixSocket(sshSocketPath)).
WithEnvVariable("SSH_AUTH_SOCK", sshSocketPath).
WithEnvVariable("GIT_SSH_COMMAND", "ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=accept-new").
WithExec([]string{"sh", "-c", "terragrunt show -json output.tfplan > output.json"}).
Stdout(ctx)
if planErr != nil {
return fmt.Errorf("failed to export plan output: %w", planErr)
}
// Inspect the generated plan output.
output, catErr := tg.
WithEntrypoint(nil).
WithEnvVariable("CACHEBUSTER", time.Now().String()).
WithExec([]string{"sh", "-c", "cat output.json"}).
Stdout(ctx)
if catErr != nil {
return fmt.Errorf("failed to read plan output: %w", catErr)
}
I have to say that the commands executed on themselves aren't failing. It's just the file that somehow isn't there.