packer-cn/builder/osc/common/interpolate_build_info.go

36 lines
828 B
Go
Raw Normal View History

package common
import (
2020-11-17 19:31:03 -05:00
"github.com/hashicorp/packer/packer-plugin-sdk/multistep"
"github.com/outscale/osc-sdk-go/osc"
)
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,
}
}
sourceOMI := rawSourceOMI.(osc.Image)
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,
}
}