Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Source image #120

Merged
merged 2 commits into from
Oct 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions builder/vsphere/clone/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,9 @@ func (b *Builder) Run(ctx context.Context, ui packersdk.Ui, hook packersdk.Hook)
ContentLibraryConfig: b.config.ContentLibraryDestinationConfig,
VM: vm,
StateData: map[string]interface{}{
"generated_data": state.Get("generated_data"),
"metadata": state.Get("metadata"),
"generated_data": state.Get("generated_data"),
"metadata": state.Get("metadata"),
"source_template": b.config.Template,
},
}
if b.config.Export != nil {
Expand Down
8 changes: 5 additions & 3 deletions builder/vsphere/clone/step_clone.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/hashicorp/packer-plugin-sdk/multistep"
packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
"github.com/hashicorp/packer-plugin-sdk/packerbuilderdata"
"github.com/hashicorp/packer-plugin-vsphere/builder/vsphere/common"
"github.com/hashicorp/packer-plugin-vsphere/builder/vsphere/driver"
)
Expand Down Expand Up @@ -68,9 +69,10 @@ func (c *CloneConfig) Prepare() []error {
}

type StepCloneVM struct {
Config *CloneConfig
Location *common.LocationConfig
Force bool
Config *CloneConfig
Location *common.LocationConfig
Force bool
GeneratedData *packerbuilderdata.GeneratedData
}

func (s *StepCloneVM) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
Expand Down
19 changes: 19 additions & 0 deletions builder/vsphere/common/artifact.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,32 @@ func (a *Artifact) stateHCPPackerRegistryMetadata() interface{} {
if a.ContentLibraryConfig != nil {
labels["content_library_destination"] = fmt.Sprintf("%s/%s", a.ContentLibraryConfig.Library, a.ContentLibraryConfig.Name)
}
// this is where the iso was downloaded from
sourceURL, ok := a.StateData["SourceImageURL"].(string)
if ok {
labels["source_image_url"] = sourceURL
}
// This is where the iso was uploaded to on the remote vsphere datastore
var sourceID string
isoPath, ok := a.StateData["iso_path"].(string)
if ok {
sourceID = isoPath
}

// If a clone, the source comes from a different place.
templatePath, ok := a.StateData["source_template"].(string)
if ok {
sourceID = templatePath
}

img, _ := registryimage.FromArtifact(a,
registryimage.WithID(a.Name),
registryimage.WithRegion(a.Datacenter.Name()),
registryimage.WithProvider("vsphere"),
registryimage.WithSourceID(sourceID),
registryimage.SetLabels(labels),
)

return img
}

Expand Down
1 change: 1 addition & 0 deletions builder/vsphere/common/step_download.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ func (s *StepDownload) Run(ctx context.Context, state multistep.StateBag) multis
if exists := ds.FileExists(remotePath); exists {
ui.Say(fmt.Sprintf("File %s already uploaded; continuing", targetPath))
state.Put(s.ResultKey, targetPath)
state.Put("SourceImageURL", source)
return multistep.ActionContinue
}
}
Expand Down
2 changes: 2 additions & 0 deletions builder/vsphere/iso/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ func (b *Builder) Run(ctx context.Context, ui packersdk.Ui, hook packersdk.Hook)
StateData: map[string]interface{}{
"generated_data": state.Get("generated_data"),
"metadata": state.Get("metadata"),
"SourceImageURL": state.Get("SourceImageURL"),
"iso_path": state.Get("iso_path"),
},
}

Expand Down
8 changes: 5 additions & 3 deletions builder/vsphere/iso/step_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/hashicorp/packer-plugin-sdk/multistep"
packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
"github.com/hashicorp/packer-plugin-sdk/packerbuilderdata"
"github.com/hashicorp/packer-plugin-vsphere/builder/vsphere/common"
"github.com/hashicorp/packer-plugin-vsphere/builder/vsphere/driver"
)
Expand Down Expand Up @@ -117,9 +118,10 @@ func (c *CreateConfig) Prepare() []error {
}

type StepCreateVM struct {
Config *CreateConfig
Location *common.LocationConfig
Force bool
Config *CreateConfig
Location *common.LocationConfig
Force bool
GeneratedData *packerbuilderdata.GeneratedData
}

func (s *StepCreateVM) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.17
require (
github.com/google/go-cmp v0.5.6
github.com/hashicorp/hcl/v2 v2.10.1
github.com/hashicorp/packer-plugin-sdk v0.2.5
github.com/hashicorp/packer-plugin-sdk v0.2.7
github.com/pkg/errors v0.9.1
github.com/vmware/govmomi v0.24.1
github.com/zclconf/go-cty v1.9.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,8 @@ github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO
github.com/hashicorp/mdns v1.0.1/go.mod h1:4gW7WsVCke5TE7EPeYliwHlRUyBtfCwuFwuMg2DmyNY=
github.com/hashicorp/memberlist v0.2.2 h1:5+RffWKwqJ71YPu9mWsF7ZOscZmwfasdA8kbdC7AO2g=
github.com/hashicorp/memberlist v0.2.2/go.mod h1:MS2lj3INKhZjWNqd3N0m3J+Jxf3DAOnAH9VT3Sh9MUE=
github.com/hashicorp/packer-plugin-sdk v0.2.5 h1:qydxm7rbyUuUvvh2rxTZjur8kG5JQNGtpOifS4Xv1BY=
github.com/hashicorp/packer-plugin-sdk v0.2.5/go.mod h1:ii9ub5UNAp30RGod3i3W8qj7wA+H7kpURnD+Jt7oDkQ=
github.com/hashicorp/packer-plugin-sdk v0.2.7 h1:L7mfLg+gGnqN3z8vEG4YojVsbhYJrNcimvOSIuCN6qA=
github.com/hashicorp/packer-plugin-sdk v0.2.7/go.mod h1:ii9ub5UNAp30RGod3i3W8qj7wA+H7kpURnD+Jt7oDkQ=
github.com/hashicorp/serf v0.9.5 h1:EBWvyu9tcRszt3Bxp3KNssBMP1KuHWyO51lz9+786iM=
github.com/hashicorp/serf v0.9.5/go.mod h1:UWDWwZeL5cuWDJdl0C6wrvrUwEqtQ4ZKBKKENpqIUyk=
github.com/hashicorp/vault/api v1.0.5-0.20200519221902-385fac77e20f/go.mod h1:euTFbi2YJgwcju3imEt919lhJKF68nN1cQPq3aA+kBE=
Expand Down