diff --git a/builder/oracle/classic/artifact.go b/builder/oracle/classic/artifact.go index ff01b186f..bf1fed0ba 100644 --- a/builder/oracle/classic/artifact.go +++ b/builder/oracle/classic/artifact.go @@ -1,7 +1,15 @@ package classic -// Artifact is an artifact implementation that contains a built Custom Image. +import ( + "fmt" + + "github.com/hashicorp/go-oracle-terraform/compute" +) + +// Artifact is an artifact implementation that contains a Snapshot. type Artifact struct { + Snapshot *compute.Snapshot + driver *compute.ComputeClient } // BuilderId uniquely identifies the builder. @@ -15,13 +23,17 @@ func (a *Artifact) Files() []string { return nil } -// Id returns the OCID of the associated Image. func (a *Artifact) Id() string { - return "" + return a.Snapshot.Name } func (a *Artifact) String() string { - return "" + return fmt.Sprintf("A Snapshot was created: \n"+ + "Name: %s\n"+ + "Instance: %s\n"+ + "MachineImage: %s\n"+ + "URI: %s", + a.Snapshot.Name, a.Snapshot.Instance, a.Snapshot.MachineImage, a.Snapshot.URI) } func (a *Artifact) State(name string) interface{} { @@ -30,5 +42,11 @@ func (a *Artifact) State(name string) interface{} { // Destroy deletes the custom image associated with the artifact. func (a *Artifact) Destroy() error { - return nil + client := a.driver.Snapshots() + mic := a.driver.MachineImages() + input := &compute.DeleteSnapshotInput{ + Snapshot: a.Snapshot.Name, + MachineImage: a.Snapshot.MachineImage, + } + return client.DeleteSnapshot(mic, input) } diff --git a/builder/oracle/classic/builder.go b/builder/oracle/classic/builder.go index 7e8c07f53..7847ef179 100644 --- a/builder/oracle/classic/builder.go +++ b/builder/oracle/classic/builder.go @@ -89,17 +89,13 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe return nil, rawErr.(error) } - /* - // Build the artifact and return it - artifact := &Artifact{ - Image: state.Get("image").(client.Image), - Region: b.config.AccessCfg.Region, - driver: driver, - } + // Build the artifact and return it + artifact := &Artifact{ + Snapshot: state.Get("snapshot").(*compute.Snapshot), + driver: client, + } - return artifact, nil - */ - return nil, nil + return artifact, nil } // Cancel terminates a running build. diff --git a/builder/oracle/classic/step_snapshot.go b/builder/oracle/classic/step_snapshot.go index 52c2557c6..2e4e9d7a3 100644 --- a/builder/oracle/classic/step_snapshot.go +++ b/builder/oracle/classic/step_snapshot.go @@ -35,6 +35,7 @@ func (s *stepSnapshot) Run(state multistep.StateBag) multistep.StepAction { return multistep.ActionHalt } + state.Put("snapshot", snap) ui.Say(fmt.Sprintf("Created snapshot (%s).", snap.Name)) return multistep.ActionContinue }