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"

"github.com/Azure/azure-sdk-for-go/profiles/latest/keyvault/keyvault"

"github.com/hashicorp/packer/common"
"github.com/hashicorp/packer/helper/config"
"github.com/hashicorp/packer/packer"
"github.com/hashicorp/packer/template/interpolate"
)

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": ""
  }
}

-- 
This mailing list is governed under the HashiCorp Community Guidelines - 
https://www.hashicorp.com/community-guidelines.html. Behavior in violation of 
those guidelines may result in your removal from this mailing list.

GitHub Issues: https://github.com/mitchellh/packer/issues
IRC: #packer-tool on Freenode
--- 
You received this message because you are subscribed to the Google Groups 
"Packer" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/packer-tool/c584e318-ff09-4d97-9ccb-0e3846ae71f0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to