diff --git a/plugin.go b/plugin.go index ae23059..319067f 100644 --- a/plugin.go +++ b/plugin.go @@ -59,6 +59,20 @@ type ( // Exec executes the plugin func (p Plugin) Exec() error { + // Install a extra PEM key if required + if len(os.Getenv("PEM_NAME")) > 0 { + value, exists := os.LookupEnv("PEM_CONTENTS") + if !exists { + value = "-----BEGIN RSA PRIVATE KEY-----\n\n-----END RSA PRIVATE KEY-----\n" + } + err := installExtraPem(os.Getenv("PEM_NAME"), value) + + if err != nil { + return err + } + } + + // Install a Github SSH key if len(os.Getenv("GITHUB_PRIVATE_SSH_KEY")) > 0 { sshconfErr := installGithubSsh(os.Getenv("GITHUB_PRIVATE_SSH_KEY")) diff --git a/terraform.go b/terraform.go index 1eaae79..e9e4fed 100644 --- a/terraform.go +++ b/terraform.go @@ -17,6 +17,14 @@ type ( } ) +func installExtraPem(pemName string, pemContents string) error { + err := ioutil.WriteFile(os.Getenv("HOME")+"/.ssh/"+pemName, []byte(pemContents), 0600) + if err != nil { + return err + } + return nil +} + func installGithubSsh(githubSshPrivate string) error { os.Mkdir(os.Getenv("HOME")+"/.aws", 0700) myconf := []byte("Host github.com\n StrictHostKeyChecking no\n UserKnownHostsFile=/dev/null\n")