From d236f26439f22df68c4aecb46c260c88387e6018 Mon Sep 17 00:00:00 2001 From: Megan Marsh Date: Thu, 5 Apr 2018 15:24:54 -0700 Subject: [PATCH] allow users to access winrm password in powershell and elevated powershell provisioners --- builder/azure/arm/builder.go | 3 +++ builder/azure/arm/config.go | 4 ++++ builder/azure/arm/step_save_winrm_password.go | 22 +++++++++++++++++++ 3 files changed, 29 insertions(+) create mode 100644 builder/azure/arm/step_save_winrm_password.go diff --git a/builder/azure/arm/builder.go b/builder/azure/arm/builder.go index b81ccf94f..8fb4389ad 100644 --- a/builder/azure/arm/builder.go +++ b/builder/azure/arm/builder.go @@ -176,6 +176,9 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe NewStepValidateTemplate(azureClient, ui, b.config, GetVirtualMachineDeployment), NewStepDeployTemplate(azureClient, ui, b.config, deploymentName, GetVirtualMachineDeployment), NewStepGetIPAddress(azureClient, ui, endpointConnectType), + &StepSaveWinRMPassword{ + Password: b.config.tmpAdminPassword, + }, &communicator.StepConnectWinRM{ Config: &b.config.Comm, Host: func(stateBag multistep.StateBag) (string, error) { diff --git a/builder/azure/arm/config.go b/builder/azure/arm/config.go index 8f795f353..5d789708d 100644 --- a/builder/azure/arm/config.go +++ b/builder/azure/arm/config.go @@ -22,6 +22,7 @@ import ( "github.com/hashicorp/packer/builder/azure/common/constants" "github.com/hashicorp/packer/builder/azure/pkcs12" "github.com/hashicorp/packer/common" + commonhelper "github.com/hashicorp/packer/helper/common" "github.com/hashicorp/packer/helper/communicator" "github.com/hashicorp/packer/helper/config" "github.com/hashicorp/packer/packer" @@ -357,6 +358,9 @@ func setRuntimeValues(c *Config) { var tempName = NewTempName() c.tmpAdminPassword = tempName.AdminPassword + // store so that we can access this later during provisioning + commonhelper.SetSharedState("winrm_password", c.tmpAdminPassword) + c.tmpCertificatePassword = tempName.CertificatePassword if c.TempComputeName == "" { c.tmpComputeName = tempName.ComputeName diff --git a/builder/azure/arm/step_save_winrm_password.go b/builder/azure/arm/step_save_winrm_password.go new file mode 100644 index 000000000..e28fcd771 --- /dev/null +++ b/builder/azure/arm/step_save_winrm_password.go @@ -0,0 +1,22 @@ +package arm + +import ( + "context" + + commonhelper "github.com/hashicorp/packer/helper/common" + "github.com/hashicorp/packer/helper/multistep" +) + +type StepSaveWinRMPassword struct { + Password string +} + +func (s *StepSaveWinRMPassword) Run(_ context.Context, state multistep.StateBag) multistep.StepAction { + // store so that we can access this later during provisioning + commonhelper.SetSharedState("winrm_password", s.Password) + return multistep.ActionContinue +} + +func (s *StepSaveWinRMPassword) Cleanup(multistep.StateBag) { + commonhelper.RemoveSharedStateFile("winrm_password") +}