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

Loading credentials from env_file parameter #107

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ func main() {
EnvVar: "PLUGIN_CA_CERT",
},
cli.StringFlag{
Name: "env-file",
Usage: "source env file",
Name: "env_file",
ndajr marked this conversation as resolved.
Show resolved Hide resolved
Usage: "pass filename to source it and load variables into current shell",
EnvVar: "PLUGIN_ENV_FILE",
},
cli.StringFlag{
Name: "init_options",
Expand Down Expand Up @@ -125,8 +126,8 @@ func run(c *cli.Context) error {
"Revision": revision,
}).Info("Drone Terraform Plugin Version")

if c.String("env-file") != "" {
_ = godotenv.Load(c.String("env-file"))
if c.String("env_file") != "" {
_ = godotenv.Load(c.String("env_file"))
}

var vars map[string]string
Expand Down
12 changes: 11 additions & 1 deletion plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (p Plugin) Exec() error {
}
}

if p.Config.RoleARN != "" {
if p.Config.RoleARN != "" && !credsSet() {
assumeRole(p.Config.RoleARN)
}

Expand Down Expand Up @@ -169,6 +169,16 @@ func CopyTfEnv() {
}
}

func credsSet() bool {
ndajr marked this conversation as resolved.
Show resolved Hide resolved
awsTokens := []string{"AWS_ACCESS_KEY_ID", "AWS_SECRET_ACCESS_KEY", "AWS_SESSION_TOKEN"}
ndajr marked this conversation as resolved.
Show resolved Hide resolved
for _, token := range awsTokens {
if os.Getenv(token) != "" {
return true
}
}
return false
}

func assumeRole(roleArn string) {
ndajr marked this conversation as resolved.
Show resolved Hide resolved
client := sts.New(session.New())
duration := time.Hour * 1
Expand Down