I am unable to call a simple provisioner which is connecting to Azure.
Here is the error
"
Failed to initialize build 'hyperv-iso': error initializing provisioner 'install-certificate': plugin exited before we could connect
hyperv-iso output will be in this color.
"
Here is my Provisioner Code. If I comment the keyvault client line the packer is able to initialize the provisioner. Can it be due to different SDK version? Any pointers?
package certificate
import (
"context"
"errors"
"fmt"
)
type Config struct {
common.PackerConfig `mapstructure:",squash"`
SubscriptionID string `mapstructure:"subscription_id"`
VaultName string `mapstructure:"vault_name"`
CertificateName string `mapstructure:"certificate_name"`
Script string `mapstructure:"script"`
ctx interpolate.Context
}
type Provisioner struct {
config Config
}
func (p *Provisioner) Prepare(raws ...interface{}) error {
err := config.Decode(&p.config, &config.DecodeOpts{
Interpolate: true,
InterpolateContext: &p.config.ctx,
InterpolateFilter: &interpolate.RenderFilter{},
}, raws...)
if err != nil {
return err
}
var errs *packer.MultiError
if len(p.config.SubscriptionID) < 1 {
errs = packer.MultiErrorAppend(errs, errors.New("subscription_id must be specified."))
}
if len(p.config.VaultName) < 1 {
errs = packer.MultiErrorAppend(errs, errors.New("vault_name must be specified."))
}
if len(p.config.CertificateName) < 1 {
errs = packer.MultiErrorAppend(errs, errors.New("certificate_name must be specified."))
}
if len(p.config.Script) < 1 {
errs = packer.MultiErrorAppend(errs, errors.New("script must be specified."))
}
if errs != nil && len(errs.Errors) > 0 {
return errs
}
return nil
}
func (p *Provisioner) Provision(ctx context.Context, ui packer.Ui, comm packer.Communicator) error {
basicClient := keyvault.New()
fmt.Println(basicClient.RetryAttempts)
var cmd = &packer.RemoteCmd{
Command: fmt.Sprintf("powershell.exe -file %s -CertificateBase64 %s", p.config.Script, "YoHooay!!"),
}
return cmd.RunWithUi(ctx, comm, ui)
}
Packer Config
{
"builders": [
{
"boot_wait": "0s",
"boot_command": [],
"communicator": "winrm",
"cpus": "{{ user `cpus` }}",
"disk_size": "{{user `disk_size` }}",
"enable_secure_boot": true,
"floppy_files": [],
"generation": 2,
"headless": false,
"iso_checksum": "",
"iso_checksum_type": "none",
"iso_url": "{{ user `image_path` }}",
"iso_target_extension": "vhdx",
"memory": "{{ user `memory` }}",
"secondary_iso_images": [],
"shutdown_command": "{{ user `shutdown_command` }}",
"shutdown_timeout": "10m",
"switch_name": "External VM Switch",
"type": "hyperv-iso",
"vm_name": "AutomatedPackerImage",
"winrm_password": "{{ user `winrm_password` }}",
"winrm_timeout": "10000s",
"winrm_username": "{{ user `winrm_username` }}",
"winrm_use_ssl": true,
"winrm_insecure": true
}
],
"provisioners": [{
"type": "file",
"source": "Certificates\\Install-Cert.ps1",
"destination": "C:\\Users\\Public\\Documents\\Install-Cert.ps1"
},{
"type" : "install-certificate",
"script": "C:\\Users\\Public\\Documents\\Install-Cert.ps1",
"vault_name": "sdfgsdfasfgsdf",
"certificate_name": "blahblah"
}],
"variables": {
"cpus": "2",
"memory": "4096",
"disk_size": "250960",
"image_path": "",
"shutdown_command": "C:\\Users\\Public\\Documents\\Sysprep.bat",
"winrm_username": "",
"winrm_password": ""
}
}