From b9807b4647b8ef62f51c97901ea9f9b3f616af96 Mon Sep 17 00:00:00 2001 From: Chris Mague Date: Fri, 24 Aug 2018 12:30:25 -0700 Subject: [PATCH] add the github private key option --- plugin.go | 10 ++++++++++ terraform.go | 15 +++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/plugin.go b/plugin.go index 1557d4e..ae23059 100644 --- a/plugin.go +++ b/plugin.go @@ -59,6 +59,16 @@ type ( // Exec executes the plugin func (p Plugin) Exec() error { + // Install a Github SSH key + if len(os.Getenv("GITHUB_PRIVATE_SSH_KEY")) > 0 { + sshconfErr := installGithubSsh(os.Getenv("GITHUB_PRIVATE_SSH_KEY")) + + if sshconfErr != nil { + return sshconfErr + } + } + + // Install an AWS profile if env var is set 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")) diff --git a/terraform.go b/terraform.go index b3c3805..1eaae79 100644 --- a/terraform.go +++ b/terraform.go @@ -17,6 +17,21 @@ type ( } ) +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") + err := ioutil.WriteFile(os.Getenv("HOME")+"/.ssh/conf", myconf, 0644) + if err != nil { + return err + } + mykey := []byte(githubSshPrivate) + err2 := ioutil.WriteFile(os.Getenv("HOME")+"/.ssh/id_rsa", mykey, 0600) + if err2 != nil { + return err2 + } + return nil +} + 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")