Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set AWS credentials in the environment so go-getter can use them #775

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
7 changes: 7 additions & 0 deletions cli/cli_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
"io"
"os"
"regexp"
"strings"
"time"
Expand Down Expand Up @@ -367,6 +368,12 @@ func assumeRoleIfNecessary(terragruntOptions *options.TerragruntOptions) error {
terragruntOptions.Env["AWS_SECRET_ACCESS_KEY"] = aws.StringValue(creds.SecretAccessKey)
terragruntOptions.Env["AWS_SESSION_TOKEN"] = aws.StringValue(creds.SessionToken)

// Workaround for https://github.com/hashicorp/go-getter/issues/191
// Set these directly as environment variables so that go-getter can download artifacts from S3
os.Setenv("AWS_ACCESS_KEY_ID", aws.StringValue(creds.AccessKeyId))
os.Setenv("AWS_SECRET_ACCESS_KEY", aws.StringValue(creds.SecretAccessKey))
os.Setenv("AWS_SESSION_TOKEN", aws.StringValue(creds.SessionToken))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR!

I'm grateful for the attempt at a simple fix, but I'm 95% sure this approach is going to cause other problems:

  1. We run Terragrunt's tests in parallel, some of which use different auth strategies. If we set global env vars here, that will affect all tests, and cause strange, intermittent behavior depending on which tests happen to run in parallel.
  2. Terragrunt itself runs things in parallel when you run xxx-all commands (e.g., apply-all). If you have different modules that use different auth settings, this again will cause strange race conditions based on timing.

So, I suspect that either we need a way to explicitly set auth values when executing an instance of go-getter, if it's API exposes that ability... And if not, fix the bug in go-getter itself.


return nil
}

Expand Down