also use config.SSHPrivateKey for azure-arm builds
This commit is contained in:
parent
d49ad12895
commit
336cac29d4
@ -229,7 +229,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
|
||||
ui.Message(fmt.Sprintf("temp admin user: '%s'", b.config.UserName))
|
||||
ui.Message(fmt.Sprintf("temp admin password: '%s'", b.config.Password))
|
||||
|
||||
if b.config.sshPrivateKey != "" {
|
||||
if len(b.config.Comm.SSHPrivateKey) != 0 {
|
||||
debugKeyPath := fmt.Sprintf("%s-%s.pem", b.config.PackerBuildName, b.config.tmpComputeName)
|
||||
ui.Message(fmt.Sprintf("temp ssh key: %s", debugKeyPath))
|
||||
|
||||
@ -282,7 +282,7 @@ func (b *Builder) writeSSHPrivateKey(ui packer.Ui, debugKeyPath string) {
|
||||
defer f.Close()
|
||||
|
||||
// Write the key out
|
||||
if _, err := f.Write([]byte(b.config.sshPrivateKey)); err != nil {
|
||||
if _, err := f.Write(b.config.Comm.SSHPrivateKey); err != nil {
|
||||
ui.Say(fmt.Sprintf("Error saving debug key: %s", err))
|
||||
return
|
||||
}
|
||||
@ -333,7 +333,6 @@ func (b *Builder) getBlobAccount(ctx context.Context, client *AzureClient, resou
|
||||
|
||||
func (b *Builder) configureStateBag(stateBag multistep.StateBag) {
|
||||
stateBag.Put(constants.AuthorizedKey, b.config.sshAuthorizedKey)
|
||||
stateBag.Put(constants.PrivateKey, b.config.sshPrivateKey)
|
||||
|
||||
stateBag.Put(constants.ArmTags, b.config.AzureTags)
|
||||
stateBag.Put(constants.ArmComputeName, b.config.tmpComputeName)
|
||||
|
@ -15,7 +15,6 @@ func TestStateBagShouldBePopulatedExpectedValues(t *testing.T) {
|
||||
|
||||
var expectedStateBagKeys = []string{
|
||||
constants.AuthorizedKey,
|
||||
constants.PrivateKey,
|
||||
|
||||
constants.ArmTags,
|
||||
constants.ArmComputeName,
|
||||
|
@ -143,7 +143,6 @@ type Config struct {
|
||||
|
||||
// Authentication with the VM via SSH
|
||||
sshAuthorizedKey string
|
||||
sshPrivateKey string
|
||||
|
||||
// Authentication with the VM via WinRM
|
||||
winrmCertificate string
|
||||
@ -329,7 +328,7 @@ func setSshValues(c *Config) error {
|
||||
publicKey.Type(),
|
||||
base64.StdEncoding.EncodeToString(publicKey.Marshal()),
|
||||
time.Now().Format(time.RFC3339))
|
||||
c.sshPrivateKey = string(privateKeyBytes)
|
||||
c.Comm.SSHPrivateKey = privateKeyBytes
|
||||
|
||||
} else {
|
||||
sshKeyPair, err := NewOpenSshKeyPair()
|
||||
@ -338,7 +337,7 @@ func setSshValues(c *Config) error {
|
||||
}
|
||||
|
||||
c.sshAuthorizedKey = sshKeyPair.AuthorizedKey()
|
||||
c.sshPrivateKey = sshKeyPair.PrivateKey()
|
||||
c.Comm.SSHPrivateKey = sshKeyPair.PrivateKey()
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -49,11 +49,11 @@ func (s *OpenSshKeyPair) AuthorizedKey() string {
|
||||
time.Now().Format(time.RFC3339))
|
||||
}
|
||||
|
||||
func (s *OpenSshKeyPair) PrivateKey() string {
|
||||
privateKey := string(pem.EncodeToMemory(&pem.Block{
|
||||
func (s *OpenSshKeyPair) PrivateKey() []byte {
|
||||
privateKey := pem.EncodeToMemory(&pem.Block{
|
||||
Type: "RSA PRIVATE KEY",
|
||||
Bytes: x509.MarshalPKCS1PrivateKey(s.privateKey),
|
||||
}))
|
||||
})
|
||||
|
||||
return privateKey
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user