2019-01-29 13:18:02 -05:00
|
|
|
package common
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/hashicorp/packer/helper/multistep"
|
2020-08-17 17:04:19 -04:00
|
|
|
"github.com/outscale/osc-sdk-go/osc"
|
2019-01-29 13:18:02 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
type BuildInfoTemplate struct {
|
|
|
|
BuildRegion string
|
|
|
|
SourceOMI string
|
|
|
|
SourceOMIName string
|
|
|
|
SourceOMITags map[string]string
|
|
|
|
}
|
|
|
|
|
|
|
|
func extractBuildInfo(region string, state multistep.StateBag) *BuildInfoTemplate {
|
|
|
|
rawSourceOMI, hasSourceOMI := state.GetOk("source_image")
|
|
|
|
if !hasSourceOMI {
|
|
|
|
return &BuildInfoTemplate{
|
|
|
|
BuildRegion: region,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-17 17:04:19 -04:00
|
|
|
sourceOMI := rawSourceOMI.(osc.Image)
|
2019-01-29 13:18:02 -05:00
|
|
|
sourceOMITags := make(map[string]string, len(sourceOMI.Tags))
|
|
|
|
for _, tag := range sourceOMI.Tags {
|
|
|
|
sourceOMITags[tag.Key] = tag.Value
|
|
|
|
}
|
|
|
|
|
|
|
|
return &BuildInfoTemplate{
|
|
|
|
BuildRegion: region,
|
|
|
|
SourceOMI: sourceOMI.ImageId,
|
|
|
|
SourceOMIName: sourceOMI.ImageName,
|
|
|
|
SourceOMITags: sourceOMITags,
|
|
|
|
}
|
|
|
|
}
|