Browse Source

generate a profile file if necessary

pull/78/head
Chris Mague 6 years ago
parent
commit
1084a40895
  1. 9
      plugin.go
  2. 8
      terraform.go

9
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 {

8
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 {

Loading…
Cancel
Save