-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed using authentication provider credentials with `get_aws_account…
…_id` (#3243) * fix: using auth provider creads with get-aws-account-id * chore: file renaming
- Loading branch information
1 parent
fbda728
commit 187f912
Showing
28 changed files
with
119 additions
and
138 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package creds | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/gruntwork-io/terragrunt/cli/commands/terraform/creds/providers" | ||
"github.com/gruntwork-io/terragrunt/options" | ||
"golang.org/x/exp/maps" | ||
) | ||
|
||
type Getter struct { | ||
obtainedCreds map[string]*providers.Credentials | ||
} | ||
|
||
func NewGetter() *Getter { | ||
return &Getter{ | ||
obtainedCreds: make(map[string]*providers.Credentials), | ||
} | ||
} | ||
|
||
// ObtainAndUpdateEnvIfNecessary obtains credentials through different providers and sets them to `opts.Env`. | ||
func (getter *Getter) ObtainAndUpdateEnvIfNecessary(ctx context.Context, opts *options.TerragruntOptions, authProviders ...providers.Provider) error { | ||
for _, provider := range authProviders { | ||
creds, err := provider.GetCredentials(ctx) | ||
if err != nil { | ||
return err | ||
} | ||
if creds == nil { | ||
continue | ||
} | ||
|
||
for providerName, prevCreds := range getter.obtainedCreds { | ||
if prevCreds.Name == creds.Name { | ||
opts.Logger.Warnf("%s credentials obtained using %s are overwritten by credentials obtained using %s.", creds.Name, providerName, provider.Name()) | ||
} | ||
} | ||
getter.obtainedCreds[provider.Name()] = creds | ||
|
||
maps.Copy(opts.Env, creds.Envs) | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,14 @@ | ||
#!/bin/bash -e | ||
|
||
set -o pipefail | ||
|
||
. ${PWD}/creds.config | ||
|
||
json_string=$( jq -n \ | ||
--arg access_key_id "$fake_id" \ | ||
--arg secret_access_key "$fake_key" \ | ||
--arg session_token "$fake_tk" \ | ||
--arg tf_var_foo "$tf_var_foo" \ | ||
'{awsCredentials: {ACCESS_KEY_ID: $access_key_id, SECRET_ACCESS_KEY: $secret_access_key, SESSION_TOKEN: $session_token}, envs: {TF_VAR_foo: $tf_var_foo}}' ) | ||
json_string=$(jq -n \ | ||
--arg access_key_id "$access_key_id" \ | ||
--arg secret_access_key "$secret_access_key" \ | ||
--arg session_token "$session_token" \ | ||
--arg tf_var_foo "$tf_var_foo" \ | ||
'{awsCredentials: {ACCESS_KEY_ID: $access_key_id, SECRET_ACCESS_KEY: $secret_access_key, SESSION_TOKEN: $session_token}, envs: {TF_VAR_foo: $tf_var_foo}}') | ||
|
||
echo $json_string |
4 changes: 4 additions & 0 deletions
4
test/fixture-auth-provider-cmd/multiple-apps/app1/creds.config
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
access_key_id=app1_access_key_id | ||
secret_access_key=app1_secret_access_key | ||
session_token=app1_session_token | ||
tf_var_foo=app1-bar |
File renamed without changes.
7 changes: 2 additions & 5 deletions
7
...ure-auth-provider-cmd/app1/terragrunt.hcl → ...der-cmd/multiple-apps/app1/terragrunt.hcl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
test/fixture-auth-provider-cmd/multiple-apps/app2/creds.config
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
access_key_id=app2_access_key_id | ||
secret_access_key=app2_secret_access_key | ||
session_token=app2_session_token | ||
tf_var_foo=app2-bar |
File renamed without changes.
7 changes: 2 additions & 5 deletions
7
...ure-auth-provider-cmd/app2/terragrunt.hcl → ...der-cmd/multiple-apps/app2/terragrunt.hcl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
test/fixture-auth-provider-cmd/multiple-apps/app3/creds.config
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
access_key_id=app3_access_key_id | ||
secret_access_key=app3_secret_access_key | ||
session_token=app3_session_token | ||
tf_var_foo=app3-bar |
File renamed without changes.
3 changes: 3 additions & 0 deletions
3
test/fixture-auth-provider-cmd/multiple-apps/app3/terragrunt.hcl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
include { | ||
path = find_in_parent_folders() | ||
} |
2 changes: 1 addition & 1 deletion
2
...ure-auth-provider-cmd/app3/terragrunt.hcl → ...provider-cmd/multiple-apps/terragrunt.hcl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
terraform { | ||
before_hook "before_hook" { | ||
commands = ["init"] | ||
execute = ["./test-creds.sh"] | ||
execute = ["../test-creds.sh"] | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
test/fixture-auth-provider-cmd/multiple-apps/test-creds.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/bin/bash -e | ||
|
||
set -o pipefail | ||
|
||
. ${PWD}/creds.config | ||
|
||
if [ "$access_key_id" != "$AWS_ACCESS_KEY_ID" ]; then | ||
exit 1 | ||
fi | ||
|
||
if [ "$secret_access_key" != "$AWS_SECRET_ACCESS_KEY" ]; then | ||
exit 1 | ||
fi | ||
|
||
if [ "$session_token" != "$AWS_SESSION_TOKEN" ]; then | ||
exit 1 | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
access_key_id=__FILL_AWS_ACCESS_KEY_ID__ | ||
secret_access_key=__FILL_AWS_SECRET_ACCESS_KEY__ | ||
session_token= | ||
tf_var_foo= |
2 changes: 1 addition & 1 deletion
2
...-provider-cmd-remote-state/terragrunt.hcl → ...-provider-cmd/remote-state/terragrunt.hcl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters