add insert_key option for toggling whether to add Vagrant's insecure key
This commit is contained in:
parent
6191b9c8c6
commit
3b3aa562ed
|
@ -67,6 +67,10 @@ type Config struct {
|
|||
// the name to give it. If left blank, will default to "packer_" plus your
|
||||
// buildname.
|
||||
BoxName string `mapstructure:"box_name" required:"false"`
|
||||
// If true, Vagrant will automatically insert a keypair to use for SSH,
|
||||
// replacing Vagrant's default insecure key inside the machine if detected.
|
||||
// By default, Packer sets this to false.
|
||||
InsertKey bool `mapstructure:"insert_key" required:"false"`
|
||||
// The vagrant provider.
|
||||
// This parameter is required when source_path have more than one provider,
|
||||
// or when using vagrant-cloud post-processor. Defaults to unset.
|
||||
|
@ -255,6 +259,7 @@ func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (pack
|
|||
BoxName: b.config.BoxName,
|
||||
OutputDir: b.config.OutputDir,
|
||||
GlobalID: b.config.GlobalID,
|
||||
InsertKey: b.config.InsertKey,
|
||||
},
|
||||
&StepAddBox{
|
||||
BoxVersion: b.config.BoxVersion,
|
||||
|
|
|
@ -79,6 +79,7 @@ type FlatConfig struct {
|
|||
Checksum *string `mapstructure:"checksum" required:"false" cty:"checksum"`
|
||||
ChecksumType *string `mapstructure:"checksum_type" required:"false" cty:"checksum_type"`
|
||||
BoxName *string `mapstructure:"box_name" required:"false" cty:"box_name"`
|
||||
InsertKey *bool `mapstructure:"insert_key" required:"false" cty:"insert_key"`
|
||||
Provider *string `mapstructure:"provider" required:"false" cty:"provider"`
|
||||
VagrantfileTpl *string `mapstructure:"vagrantfile_template" cty:"vagrantfile_template"`
|
||||
TeardownMethod *string `mapstructure:"teardown_method" required:"false" cty:"teardown_method"`
|
||||
|
@ -176,6 +177,7 @@ func (*FlatConfig) HCL2Spec() map[string]hcldec.Spec {
|
|||
"checksum": &hcldec.AttrSpec{Name: "checksum", Type: cty.String, Required: false},
|
||||
"checksum_type": &hcldec.AttrSpec{Name: "checksum_type", Type: cty.String, Required: false},
|
||||
"box_name": &hcldec.AttrSpec{Name: "box_name", Type: cty.String, Required: false},
|
||||
"insert_key": &hcldec.AttrSpec{Name: "insert_key", Type: cty.Bool, Required: false},
|
||||
"provider": &hcldec.AttrSpec{Name: "provider", Type: cty.String, Required: false},
|
||||
"vagrantfile_template": &hcldec.AttrSpec{Name: "vagrantfile_template", Type: cty.String, Required: false},
|
||||
"teardown_method": &hcldec.AttrSpec{Name: "teardown_method", Type: cty.String, Required: false},
|
||||
|
|
|
@ -19,15 +19,18 @@ type StepCreateVagrantfile struct {
|
|||
GlobalID string
|
||||
SourceBox string
|
||||
BoxName string
|
||||
InsertKey bool
|
||||
}
|
||||
|
||||
var DEFAULT_TEMPLATE = `Vagrant.configure("2") do |config|
|
||||
config.vm.define "source", autostart: false do |source|
|
||||
source.vm.box = "{{.SourceBox}}"
|
||||
config.ssh.insert_key = {{.InsertKey}}
|
||||
end
|
||||
config.vm.define "output" do |output|
|
||||
output.vm.box = "{{.BoxName}}"
|
||||
output.vm.box_url = "file://package.box"
|
||||
config.ssh.insert_key = {{.InsertKey}}
|
||||
end
|
||||
{{ if ne .SyncedFolder "" -}}
|
||||
config.vm.synced_folder "{{.SyncedFolder}}", "/vagrant"
|
||||
|
@ -40,6 +43,7 @@ type VagrantfileOptions struct {
|
|||
SyncedFolder string
|
||||
SourceBox string
|
||||
BoxName string
|
||||
InsertKey bool
|
||||
}
|
||||
|
||||
func (s *StepCreateVagrantfile) createVagrantfile() (string, error) {
|
||||
|
@ -66,6 +70,7 @@ func (s *StepCreateVagrantfile) createVagrantfile() (string, error) {
|
|||
SyncedFolder: s.SyncedFolder,
|
||||
BoxName: s.BoxName,
|
||||
SourceBox: s.SourceBox,
|
||||
InsertKey: s.InsertKey,
|
||||
}
|
||||
|
||||
err = tpl.Execute(templateFile, opts)
|
||||
|
|
|
@ -16,6 +16,10 @@
|
|||
the name to give it. If left blank, will default to "packer_" plus your
|
||||
buildname.
|
||||
|
||||
- `insert_key` (bool) - If true, Vagrant will automatically insert a keypair to use for SSH,
|
||||
replacing Vagrant's default insecure key inside the machine if detected.
|
||||
By default, Packer sets this to false.
|
||||
|
||||
- `provider` (string) - The vagrant provider.
|
||||
This parameter is required when source_path have more than one provider,
|
||||
or when using vagrant-cloud post-processor. Defaults to unset.
|
||||
|
|
Loading…
Reference in New Issue