Commit 57f18545 authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

builder/amazon: drop private key if debug mode [GH-373]

parent 404ae53a
## 0.3.6 (unreleased) ## 0.3.6 (unreleased)
IMPROVEMENTS:
* builder/amazon: In `-debug` mode, the keypair used will be saved to
the current directory so you can access the machine. [GH-373]
BUG FIXES: BUG FIXES:
* core: Fix possible panic when ctrl-C during provisioner run. * core: Fix possible panic when ctrl-C during provisioner run.
......
...@@ -8,9 +8,13 @@ import ( ...@@ -8,9 +8,13 @@ import (
"github.com/mitchellh/multistep" "github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer" "github.com/mitchellh/packer/packer"
"log" "log"
"os"
) )
type StepKeyPair struct { type StepKeyPair struct {
Debug bool
DebugKeyPath string
keyName string keyName string
} }
...@@ -34,6 +38,23 @@ func (s *StepKeyPair) Run(state map[string]interface{}) multistep.StepAction { ...@@ -34,6 +38,23 @@ func (s *StepKeyPair) Run(state map[string]interface{}) multistep.StepAction {
state["keyPair"] = keyName state["keyPair"] = keyName
state["privateKey"] = keyResp.KeyMaterial state["privateKey"] = keyResp.KeyMaterial
// If we're in debug mode, output the private key to the working
// directory.
if s.Debug {
ui.Message(fmt.Sprintf("Saving key for debug purposes: %s", s.DebugKeyPath))
f, err := os.Create(s.DebugKeyPath)
if err != nil {
state["error"] = fmt.Errorf("Error saving debug key: %s", err)
return multistep.ActionHalt
}
defer f.Close()
if _, err := f.Write([]byte(keyResp.KeyMaterial)); err != nil {
state["error"] = fmt.Errorf("Error saving debug key: %s", err)
return multistep.ActionHalt
}
}
return multistep.ActionContinue return multistep.ActionContinue
} }
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
package ebs package ebs
import ( import (
"fmt"
"github.com/mitchellh/goamz/ec2" "github.com/mitchellh/goamz/ec2"
"github.com/mitchellh/multistep" "github.com/mitchellh/multistep"
awscommon "github.com/mitchellh/packer/builder/amazon/common" awscommon "github.com/mitchellh/packer/builder/amazon/common"
...@@ -80,7 +81,10 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe ...@@ -80,7 +81,10 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
// Build the steps // Build the steps
steps := []multistep.Step{ steps := []multistep.Step{
&awscommon.StepKeyPair{}, &awscommon.StepKeyPair{
Debug: b.config.PackerDebug,
DebugKeyPath: fmt.Sprintf("ec2_%s.pem", b.config.PackerBuildName),
},
&awscommon.StepSecurityGroup{ &awscommon.StepSecurityGroup{
SecurityGroupId: b.config.SecurityGroupId, SecurityGroupId: b.config.SecurityGroupId,
SSHPort: b.config.SSHPort, SSHPort: b.config.SSHPort,
......
...@@ -184,7 +184,10 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe ...@@ -184,7 +184,10 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
// Build the steps // Build the steps
steps := []multistep.Step{ steps := []multistep.Step{
&awscommon.StepKeyPair{}, &awscommon.StepKeyPair{
Debug: b.config.PackerDebug,
DebugKeyPath: fmt.Sprintf("ec2_%s.pem", b.config.PackerBuildName),
},
&awscommon.StepSecurityGroup{ &awscommon.StepSecurityGroup{
SecurityGroupId: b.config.SecurityGroupId, SecurityGroupId: b.config.SecurityGroupId,
SSHPort: b.config.SSHPort, SSHPort: b.config.SSHPort,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment