make inner image accessible from other packages

This commit is contained in:
Gennady Lipenkov 2020-07-08 19:32:20 +03:00
parent 371be8775d
commit 420beb333b
3 changed files with 9 additions and 9 deletions

View File

@ -9,7 +9,7 @@ import (
type Artifact struct {
config *Config
driver Driver
image *compute.Image
Image *compute.Image
// StateData should store data such as GeneratedData
// to be shared with post-processors
@ -22,7 +22,7 @@ func (*Artifact) BuilderId() string {
}
func (a *Artifact) Id() string {
return a.image.Id
return a.Image.Id
}
func (*Artifact) Files() []string {
@ -31,7 +31,7 @@ func (*Artifact) Files() []string {
//revive:enable:var-naming
func (a *Artifact) String() string {
return fmt.Sprintf("A disk image was created: %v (id: %v) with family name %v", a.image.Name, a.image.Id, a.image.Family)
return fmt.Sprintf("A disk image was created: %v (id: %v) with family name %v", a.Image.Name, a.Image.Id, a.Image.Family)
}
func (a *Artifact) State(name string) interface{} {
@ -41,14 +41,14 @@ func (a *Artifact) State(name string) interface{} {
switch name {
case "ImageID":
return a.image.Id
return a.Image.Id
case "FolderID":
return a.image.FolderId
return a.Image.FolderId
}
return nil
}
func (a *Artifact) Destroy() error {
return a.driver.DeleteImage(a.image.Id)
return a.driver.DeleteImage(a.Image.Id)
}

View File

@ -18,7 +18,7 @@ func TestArtifact_Id(t *testing.T) {
FolderId: "test-folder-id",
}
a := &Artifact{
image: i}
Image: i}
expected := "test-id-value"
if a.Id() != expected {
@ -34,7 +34,7 @@ func TestArtifact_String(t *testing.T) {
Family: "test-family",
}
a := &Artifact{
image: i}
Image: i}
expected := "A disk image was created: test-name (id: test-id-value) with family name test-family"
if a.String() != expected {

View File

@ -91,7 +91,7 @@ func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (pack
}
artifact := &Artifact{
image: image.(*compute.Image),
Image: image.(*compute.Image),
config: &b.config,
driver: driver,
StateData: map[string]interface{}{"generated_data": state.Get("generated_data")},