From 336cac29d42a8091584e1803a9453e9f4d650df7 Mon Sep 17 00:00:00 2001 From: Adrien Delorme Date: Fri, 24 Aug 2018 09:17:47 +0200 Subject: [PATCH] also use config.SSHPrivateKey for azure-arm builds --- builder/azure/arm/builder.go | 5 ++--- builder/azure/arm/builder_test.go | 1 - builder/azure/arm/config.go | 5 ++--- builder/azure/arm/openssh_key_pair.go | 6 +++--- 4 files changed, 7 insertions(+), 10 deletions(-) diff --git a/builder/azure/arm/builder.go b/builder/azure/arm/builder.go index 432d863ea..061595ba0 100644 --- a/builder/azure/arm/builder.go +++ b/builder/azure/arm/builder.go @@ -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) diff --git a/builder/azure/arm/builder_test.go b/builder/azure/arm/builder_test.go index 99855333d..a71f92874 100644 --- a/builder/azure/arm/builder_test.go +++ b/builder/azure/arm/builder_test.go @@ -15,7 +15,6 @@ func TestStateBagShouldBePopulatedExpectedValues(t *testing.T) { var expectedStateBagKeys = []string{ constants.AuthorizedKey, - constants.PrivateKey, constants.ArmTags, constants.ArmComputeName, diff --git a/builder/azure/arm/config.go b/builder/azure/arm/config.go index 8e2f3c5a6..eb8142065 100644 --- a/builder/azure/arm/config.go +++ b/builder/azure/arm/config.go @@ -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 diff --git a/builder/azure/arm/openssh_key_pair.go b/builder/azure/arm/openssh_key_pair.go index 7b5e771ef..5ab97c00e 100644 --- a/builder/azure/arm/openssh_key_pair.go +++ b/builder/azure/arm/openssh_key_pair.go @@ -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 }