Merge pull request #8561 from ata18/ata18-end-of-life
Set expiry for image versions in SIG
This commit is contained in:
commit
af2c4346f8
|
@ -395,6 +395,9 @@ func (b *Builder) configureStateBag(stateBag multistep.StateBag) {
|
|||
stateBag.Put(constants.ArmManagedImageSharedGalleryImageName, b.config.SharedGalleryDestination.SigDestinationImageName)
|
||||
stateBag.Put(constants.ArmManagedImageSharedGalleryImageVersion, b.config.SharedGalleryDestination.SigDestinationImageVersion)
|
||||
stateBag.Put(constants.ArmManagedImageSubscription, b.config.ClientConfig.SubscriptionID)
|
||||
stateBag.Put(constants.ArmManagedImageSharedGalleryImageVersionEndOfLifeDate, b.config.SharedGalleryImageVersionEndOfLifeDate)
|
||||
stateBag.Put(constants.ArmManagedImageSharedGalleryImageVersionReplicaCount, b.config.SharedGalleryImageVersionReplicaCount)
|
||||
stateBag.Put(constants.ArmManagedImageSharedGalleryImageVersionExcludeFromLatest, b.config.SharedGalleryImageVersionExcludeFromLatest)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -137,6 +137,16 @@ type Config struct {
|
|||
// its default of "60m" (valid time units include `s` for seconds, `m` for
|
||||
// minutes, and `h` for hours.)
|
||||
SharedGalleryTimeout time.Duration `mapstructure:"shared_image_gallery_timeout"`
|
||||
// The end of life date (2006-01-02T15:04:05.99Z) of the gallery Image Version. This property
|
||||
// can be used for decommissioning purposes.
|
||||
SharedGalleryImageVersionEndOfLifeDate string `mapstructure:"shared_gallery_image_version_end_of_life_date" required:"false"`
|
||||
// The number of replicas of the Image Version to be created per region. This
|
||||
// property would take effect for a region when regionalReplicaCount is not specified.
|
||||
// Replica count must be between 1 and 10.
|
||||
SharedGalleryImageVersionReplicaCount int32 `mapstructure:"shared_image_gallery_replica_count" required:"false"`
|
||||
// If set to true, Virtual Machines deployed from the latest version of the
|
||||
// Image Definition won't use this Image Version.
|
||||
SharedGalleryImageVersionExcludeFromLatest bool `mapstructure:"shared_gallery_image_version_exclude_from_latest" required:"false"`
|
||||
// PublisherName for your base image. See
|
||||
// [documentation](https://azure.microsoft.com/en-us/documentation/articles/resource-groups-vm-searching/)
|
||||
// for details.
|
||||
|
|
|
@ -29,6 +29,9 @@ type FlatConfig struct {
|
|||
SharedGallery *FlatSharedImageGallery `mapstructure:"shared_image_gallery" required:"false" cty:"shared_image_gallery"`
|
||||
SharedGalleryDestination *FlatSharedImageGalleryDestination `mapstructure:"shared_image_gallery_destination" cty:"shared_image_gallery_destination"`
|
||||
SharedGalleryTimeout *string `mapstructure:"shared_image_gallery_timeout" cty:"shared_image_gallery_timeout"`
|
||||
SharedGalleryImageVersionEndOfLifeDate *string `mapstructure:"shared_gallery_image_version_end_of_life_date" required:"false" cty:"shared_gallery_image_version_end_of_life_date"`
|
||||
SharedGalleryImageVersionReplicaCount *int32 `mapstructure:"shared_image_gallery_replica_count" required:"false" cty:"shared_image_gallery_replica_count"`
|
||||
SharedGalleryImageVersionExcludeFromLatest *bool `mapstructure:"shared_gallery_image_version_exclude_from_latest" required:"false" cty:"shared_gallery_image_version_exclude_from_latest"`
|
||||
ImagePublisher *string `mapstructure:"image_publisher" required:"true" cty:"image_publisher"`
|
||||
ImageOffer *string `mapstructure:"image_offer" required:"true" cty:"image_offer"`
|
||||
ImageSku *string `mapstructure:"image_sku" required:"true" cty:"image_sku"`
|
||||
|
@ -139,6 +142,9 @@ func (*FlatConfig) HCL2Spec() map[string]hcldec.Spec {
|
|||
"shared_image_gallery": &hcldec.BlockSpec{TypeName: "shared_image_gallery", Nested: hcldec.ObjectSpec((*FlatSharedImageGallery)(nil).HCL2Spec())},
|
||||
"shared_image_gallery_destination": &hcldec.BlockSpec{TypeName: "shared_image_gallery_destination", Nested: hcldec.ObjectSpec((*FlatSharedImageGalleryDestination)(nil).HCL2Spec())},
|
||||
"shared_image_gallery_timeout": &hcldec.AttrSpec{Name: "shared_image_gallery_timeout", Type: cty.String, Required: false},
|
||||
"shared_gallery_image_version_end_of_life_date": &hcldec.AttrSpec{Name: "shared_gallery_image_version_end_of_life_date", Type: cty.String, Required: false},
|
||||
"shared_image_gallery_replica_count": &hcldec.AttrSpec{Name: "shared_image_gallery_replica_count", Type: cty.Number, Required: false},
|
||||
"shared_gallery_image_version_exclude_from_latest": &hcldec.AttrSpec{Name: "shared_gallery_image_version_exclude_from_latest", Type: cty.Bool, Required: false},
|
||||
"image_publisher": &hcldec.AttrSpec{Name: "image_publisher", Type: cty.String, Required: false},
|
||||
"image_offer": &hcldec.AttrSpec{Name: "image_offer", Type: cty.String, Required: false},
|
||||
"image_sku": &hcldec.AttrSpec{Name: "image_sku", Type: cty.String, Required: false},
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
"fmt"
|
||||
|
||||
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-03-01/compute"
|
||||
"github.com/Azure/go-autorest/autorest/date"
|
||||
"github.com/hashicorp/packer/builder/azure/common/constants"
|
||||
"github.com/hashicorp/packer/helper/multistep"
|
||||
"github.com/hashicorp/packer/packer"
|
||||
|
@ -12,7 +13,7 @@ import (
|
|||
|
||||
type StepPublishToSharedImageGallery struct {
|
||||
client *AzureClient
|
||||
publish func(ctx context.Context, mdiID, miSigPubRg, miSIGalleryName, miSGImageName, miSGImageVersion string, miSigReplicationRegions []string, location string, tags map[string]*string) (string, error)
|
||||
publish func(ctx context.Context, mdiID, miSigPubRg, miSIGalleryName, miSGImageName, miSGImageVersion string, miSigReplicationRegions []string, miSGImageVersionEndOfLifeDate string, miSGImageVersionExcludeFromLatest bool, miSigReplicaCount int32, location string, tags map[string]*string) (string, error)
|
||||
say func(message string)
|
||||
error func(e error)
|
||||
toSIG func() bool
|
||||
|
@ -36,7 +37,7 @@ func NewStepPublishToSharedImageGallery(client *AzureClient, ui packer.Ui, confi
|
|||
return step
|
||||
}
|
||||
|
||||
func (s *StepPublishToSharedImageGallery) publishToSig(ctx context.Context, mdiID string, miSigPubRg string, miSIGalleryName string, miSGImageName string, miSGImageVersion string, miSigReplicationRegions []string, location string, tags map[string]*string) (string, error) {
|
||||
func (s *StepPublishToSharedImageGallery) publishToSig(ctx context.Context, mdiID string, miSigPubRg string, miSIGalleryName string, miSGImageName string, miSGImageVersion string, miSigReplicationRegions []string, miSGImageVersionEndOfLifeDate string, miSGImageVersionExcludeFromLatest bool, miSigReplicaCount int32, location string, tags map[string]*string) (string, error) {
|
||||
|
||||
replicationRegions := make([]compute.TargetRegion, len(miSigReplicationRegions))
|
||||
for i, v := range miSigReplicationRegions {
|
||||
|
@ -44,6 +45,17 @@ func (s *StepPublishToSharedImageGallery) publishToSig(ctx context.Context, mdiI
|
|||
replicationRegions[i] = compute.TargetRegion{Name: ®ionName}
|
||||
}
|
||||
|
||||
var endOfLifeDate *date.Time
|
||||
if miSGImageVersionEndOfLifeDate != "" {
|
||||
parseDate, err := date.ParseTime("2006-01-02T15:04:05.99Z", miSGImageVersionEndOfLifeDate)
|
||||
if err != nil {
|
||||
s.say(fmt.Sprintf("Error parsing date from shared_gallery_image_version_end_of_life_date: %s", err))
|
||||
return "", err
|
||||
}
|
||||
endOfLifeDate = &date.Time{Time: parseDate}
|
||||
} else {
|
||||
endOfLifeDate = (*date.Time)(nil)
|
||||
}
|
||||
galleryImageVersion := compute.GalleryImageVersion{
|
||||
Location: &location,
|
||||
Tags: tags,
|
||||
|
@ -55,6 +67,9 @@ func (s *StepPublishToSharedImageGallery) publishToSig(ctx context.Context, mdiI
|
|||
},
|
||||
},
|
||||
TargetRegions: &replicationRegions,
|
||||
EndOfLifeDate: endOfLifeDate,
|
||||
ExcludeFromLatest: &miSGImageVersionExcludeFromLatest,
|
||||
ReplicaCount: &miSigReplicaCount,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
@ -102,6 +117,15 @@ func (s *StepPublishToSharedImageGallery) Run(ctx context.Context, stateBag mult
|
|||
var targetManagedImageName = stateBag.Get(constants.ArmManagedImageName).(string)
|
||||
var managedImageSubscription = stateBag.Get(constants.ArmManagedImageSubscription).(string)
|
||||
var mdiID = fmt.Sprintf("/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Compute/images/%s", managedImageSubscription, targetManagedImageResourceGroupName, targetManagedImageName)
|
||||
miSGImageVersionEndOfLifeDate, _ := stateBag.Get(constants.ArmManagedImageSharedGalleryImageVersionEndOfLifeDate).(string)
|
||||
miSGImageVersionExcludeFromLatest, _ := stateBag.Get(constants.ArmManagedImageSharedGalleryImageVersionExcludeFromLatest).(bool)
|
||||
miSigReplicaCount, _ := stateBag.Get(constants.ArmManagedImageSharedGalleryImageVersionReplicaCount).(int32)
|
||||
// Replica count must be between 1 and 10 inclusive.
|
||||
if miSigReplicaCount <= 0 {
|
||||
miSigReplicaCount = constants.SharedImageGalleryImageVersionDefaultMinReplicaCount
|
||||
} else if miSigReplicaCount > 10 {
|
||||
miSigReplicaCount = constants.SharedImageGalleryImageVersionDefaultMaxReplicaCount
|
||||
}
|
||||
|
||||
s.say(fmt.Sprintf(" -> MDI ID used for SIG publish : '%s'", mdiID))
|
||||
s.say(fmt.Sprintf(" -> SIG publish resource group : '%s'", miSigPubRg))
|
||||
|
@ -109,7 +133,11 @@ func (s *StepPublishToSharedImageGallery) Run(ctx context.Context, stateBag mult
|
|||
s.say(fmt.Sprintf(" -> SIG image name : '%s'", miSGImageName))
|
||||
s.say(fmt.Sprintf(" -> SIG image version : '%s'", miSGImageVersion))
|
||||
s.say(fmt.Sprintf(" -> SIG replication regions : '%v'", miSigReplicationRegions))
|
||||
createdGalleryImageVersionID, err := s.publish(ctx, mdiID, miSigPubRg, miSIGalleryName, miSGImageName, miSGImageVersion, miSigReplicationRegions, location, tags)
|
||||
s.say(fmt.Sprintf(" -> SIG image version endoflife date : '%s'", miSGImageVersionEndOfLifeDate))
|
||||
s.say(fmt.Sprintf(" -> SIG image version exclude from latest : '%t'", miSGImageVersionExcludeFromLatest))
|
||||
s.say(fmt.Sprintf(" -> SIG replica count [1, 10] : '%d'", miSigReplicaCount))
|
||||
|
||||
createdGalleryImageVersionID, err := s.publish(ctx, mdiID, miSigPubRg, miSIGalleryName, miSGImageName, miSGImageVersion, miSigReplicationRegions, miSGImageVersionEndOfLifeDate, miSGImageVersionExcludeFromLatest, miSigReplicaCount, location, tags)
|
||||
|
||||
if err != nil {
|
||||
stateBag.Put(constants.Error, err)
|
||||
|
|
|
@ -10,7 +10,7 @@ import (
|
|||
|
||||
func TestStepPublishToSharedImageGalleryShouldNotPublishForVhd(t *testing.T) {
|
||||
var testSubject = &StepPublishToSharedImageGallery{
|
||||
publish: func(context.Context, string, string, string, string, string, []string, string, map[string]*string) (string, error) {
|
||||
publish: func(context.Context, string, string, string, string, string, []string, string, bool, int32, string, map[string]*string) (string, error) {
|
||||
return "test", nil
|
||||
},
|
||||
say: func(message string) {},
|
||||
|
@ -31,7 +31,7 @@ func TestStepPublishToSharedImageGalleryShouldNotPublishForVhd(t *testing.T) {
|
|||
|
||||
func TestStepPublishToSharedImageGalleryShouldPublishForManagedImageWithSig(t *testing.T) {
|
||||
var testSubject = &StepPublishToSharedImageGallery{
|
||||
publish: func(context.Context, string, string, string, string, string, []string, string, map[string]*string) (string, error) {
|
||||
publish: func(context.Context, string, string, string, string, string, []string, string, bool, int32, string, map[string]*string) (string, error) {
|
||||
return "", nil
|
||||
},
|
||||
say: func(message string) {},
|
||||
|
|
|
@ -9,6 +9,13 @@ const (
|
|||
Thumbprint string = "thumbprint"
|
||||
Ui string = "ui"
|
||||
)
|
||||
|
||||
// Default replica count for image versions in shared image gallery
|
||||
const (
|
||||
SharedImageGalleryImageVersionDefaultMinReplicaCount int32 = 1
|
||||
SharedImageGalleryImageVersionDefaultMaxReplicaCount int32 = 10
|
||||
)
|
||||
|
||||
const (
|
||||
ArmCaptureTemplate string = "arm.CaptureTemplate"
|
||||
ArmComputeName string = "arm.ComputeName"
|
||||
|
@ -40,6 +47,9 @@ const (
|
|||
ArmManagedImageSharedGalleryImageVersion string = "arm.ManagedImageSharedGalleryImageVersion"
|
||||
ArmManagedImageSharedGalleryReplicationRegions string = "arm.ManagedImageSharedGalleryReplicationRegions"
|
||||
ArmManagedImageSharedGalleryId string = "arm.ArmManagedImageSharedGalleryId"
|
||||
ArmManagedImageSharedGalleryImageVersionEndOfLifeDate string = "arm.ArmManagedImageSharedGalleryImageVersionEndOfLifeDate"
|
||||
ArmManagedImageSharedGalleryImageVersionReplicaCount string = "arm.ArmManagedImageSharedGalleryImageVersionReplicaCount"
|
||||
ArmManagedImageSharedGalleryImageVersionExcludeFromLatest string = "arm.ArmManagedImageSharedGalleryImageVersionExcludeFromLatest"
|
||||
ArmManagedImageSubscription string = "arm.ArmManagedImageSubscription"
|
||||
ArmAsyncResourceGroupDelete string = "arm.AsyncResourceGroupDelete"
|
||||
ArmManagedImageOSDiskSnapshotName string = "arm.ManagedImageOSDiskSnapshotName"
|
||||
|
|
2
go.mod
2
go.mod
|
@ -81,7 +81,7 @@ require (
|
|||
github.com/hashicorp/golang-lru v0.5.3 // indirect
|
||||
github.com/hashicorp/hcl v1.0.0 // indirect
|
||||
github.com/hashicorp/hcl/v2 v2.0.0
|
||||
github.com/hashicorp/hcl2 v0.0.0-20191002203319-fb75b3253c80
|
||||
github.com/hashicorp/hcl2 v0.0.0-20191002203319-fb75b3253c80 // indirect
|
||||
github.com/hashicorp/serf v0.8.2 // indirect
|
||||
github.com/hashicorp/vault v1.1.0
|
||||
github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d
|
||||
|
|
|
@ -40,6 +40,16 @@
|
|||
its default of "60m" (valid time units include `s` for seconds, `m` for
|
||||
minutes, and `h` for hours.)
|
||||
|
||||
- `shared_gallery_image_version_end_of_life_date` (string) - The end of life date (2006-01-02T15:04:05.99Z) of the gallery Image Version. This property
|
||||
can be used for decommissioning purposes.
|
||||
|
||||
- `shared_image_gallery_replica_count` (int32) - The number of replicas of the Image Version to be created per region. This
|
||||
property would take effect for a region when regionalReplicaCount is not specified.
|
||||
Replica count must be between 1 and 10.
|
||||
|
||||
- `shared_gallery_image_version_exclude_from_latest` (bool) - If set to true, Virtual Machines deployed from the latest version of the
|
||||
Image Definition won't use this Image Version.
|
||||
|
||||
- `image_version` (string) - Specify a specific version of an OS to boot from.
|
||||
Defaults to `latest`. There may be a difference in versions available
|
||||
across regions due to image synchronization latency. To ensure a consistent
|
||||
|
|
Loading…
Reference in New Issue