diff --git a/plugin.go b/plugin.go index 7887143..1557d4e 100644 --- a/plugin.go +++ b/plugin.go @@ -58,8 +58,17 @@ type ( // Exec executes the plugin func (p Plugin) Exec() error { + + if len(os.Getenv("AWS_ACCESS_KEY_ID")) > 0 { + profileErr := installProfile(os.Getenv("AWS_PROFILE"), os.Getenv("AWS_ACCESS_KEY_ID"), os.Getenv("AWS_SECRET_ACCESS_KEY")) + + if profileErr != nil { + return profileErr + } + } // Install specified version of terraform if p.Terraform.Version != "" { + err := installTerraform(p.Terraform.Version) if err != nil { diff --git a/terraform.go b/terraform.go index 519fced..b3c3805 100644 --- a/terraform.go +++ b/terraform.go @@ -4,6 +4,7 @@ import ( "archive/zip" "fmt" "io" + "io/ioutil" "net/http" "os" "path/filepath" @@ -16,6 +17,13 @@ type ( } ) +func installProfile(profileName string, profileKey string, profileSecret string) error { + os.Mkdir(os.Getenv("HOME")+"/.aws", 0700) + myconf := []byte("[" + profileName + "]\naws_access_key_id = " + profileKey + "\naws_secret_access_key = " + profileSecret + "\n") + err := ioutil.WriteFile(os.Getenv("HOME")+"/.aws/credentials", myconf, 0644) + return err +} + func installTerraform(version string) error { err := downloadTerraform(version) if err != nil {