Fix ReregisterVM to default to true instead of false. (#9736)

This commit is contained in:
Megan Marsh 2020-08-10 04:13:14 -07:00 committed by GitHub
parent b72a75278a
commit daccfc42cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 53 additions and 13 deletions

View File

@ -42,7 +42,7 @@ type Config struct {
SnapshotEnable bool `mapstructure:"snapshot_enable"`
SnapshotName string `mapstructure:"snapshot_name"`
SnapshotDescription string `mapstructure:"snapshot_description"`
ReregisterVM bool `mapstructure:"reregister_vm" default:"true"`
ReregisterVM config.Trilean `mapstructure:"reregister_vm"`
ctx interpolate.Context
}

View File

@ -25,7 +25,7 @@ type FlatConfig struct {
SnapshotEnable *bool `mapstructure:"snapshot_enable" cty:"snapshot_enable" hcl:"snapshot_enable"`
SnapshotName *string `mapstructure:"snapshot_name" cty:"snapshot_name" hcl:"snapshot_name"`
SnapshotDescription *string `mapstructure:"snapshot_description" cty:"snapshot_description" hcl:"snapshot_description"`
ReregisterVM *bool `mapstructure:"reregister_vm" default:"true" cty:"reregister_vm" hcl:"reregister_vm"`
ReregisterVM *bool `mapstructure:"reregister_vm" cty:"reregister_vm" hcl:"reregister_vm"`
}
// FlatMapstructure returns a new FlatConfig.

View File

@ -0,0 +1,39 @@
package vsphere_template
import (
"testing"
)
func getTestConfig() Config {
return Config{
Username: "me",
Password: "notpassword",
Host: "myhost",
}
}
func TestConfigure_Good(t *testing.T) {
var p PostProcessor
config := getTestConfig()
err := p.Configure(config)
if err != nil {
t.Errorf("Error: %s", err)
}
}
func TestConfigure_ReRegisterVM(t *testing.T) {
var p PostProcessor
config := getTestConfig()
err := p.Configure(config)
if err != nil {
t.Errorf("Error: %s", err)
}
if p.config.ReregisterVM.False() {
t.Errorf("This should default to unset, not false.")
}
}

View File

@ -7,6 +7,7 @@ import (
"regexp"
"strings"
"github.com/hashicorp/packer/helper/config"
"github.com/hashicorp/packer/helper/multistep"
"github.com/hashicorp/packer/packer"
"github.com/hashicorp/packer/post-processor/vsphere"
@ -18,7 +19,7 @@ import (
type stepMarkAsTemplate struct {
VMName string
RemoteFolder string
ReregisterVM bool
ReregisterVM config.Trilean
}
func NewStepMarkAsTemplate(artifact packer.Artifact, p *PostProcessor) *stepMarkAsTemplate {
@ -52,7 +53,7 @@ func (s *stepMarkAsTemplate) Run(ctx context.Context, state multistep.StateBag)
}
// Use a simple "MarkAsTemplate" method unless `reregister_vm` is true
if !s.ReregisterVM {
if s.ReregisterVM.False() {
ui.Message("Marking as a template...")
if err := vm.MarkAsTemplate(context.Background()); err != nil {