2020-01-23 17:28:54 -05:00
|
|
|
package arm
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
|
2020-02-06 19:35:39 -05:00
|
|
|
"github.com/hashicorp/packer/builder/azure/common"
|
2020-01-23 17:28:54 -05:00
|
|
|
"github.com/hashicorp/packer/builder/azure/common/constants"
|
|
|
|
"github.com/hashicorp/packer/helper/multistep"
|
|
|
|
"github.com/hashicorp/packer/packer"
|
|
|
|
)
|
|
|
|
|
|
|
|
type StepCertificateInKeyVault struct {
|
|
|
|
config *Config
|
2020-02-06 19:35:39 -05:00
|
|
|
client common.AZVaultClientIface
|
2020-01-23 17:28:54 -05:00
|
|
|
say func(message string)
|
|
|
|
error func(e error)
|
|
|
|
}
|
|
|
|
|
2020-02-06 19:35:39 -05:00
|
|
|
func NewStepCertificateInKeyVault(cli common.AZVaultClientIface, ui packer.Ui, config *Config) *StepCertificateInKeyVault {
|
2020-01-23 17:28:54 -05:00
|
|
|
var step = &StepCertificateInKeyVault{
|
|
|
|
client: cli,
|
|
|
|
config: config,
|
|
|
|
say: func(message string) { ui.Say(message) },
|
|
|
|
error: func(e error) { ui.Error(e.Error()) },
|
|
|
|
}
|
|
|
|
|
|
|
|
return step
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *StepCertificateInKeyVault) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
|
|
|
|
s.say("Setting the certificate in the KeyVault...")
|
|
|
|
var keyVaultName = state.Get(constants.ArmKeyVaultName).(string)
|
|
|
|
|
|
|
|
err := s.client.SetSecret(keyVaultName, DefaultSecretName, s.config.winrmCertificate)
|
|
|
|
if err != nil {
|
|
|
|
s.error(fmt.Errorf("Error setting winrm cert in custom keyvault: %s", err))
|
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
|
|
|
|
|
|
|
return multistep.ActionContinue
|
|
|
|
}
|
|
|
|
|
|
|
|
func (*StepCertificateInKeyVault) Cleanup(multistep.StateBag) {
|
|
|
|
}
|