Add logic to handle volumes of spot instances
This commit is contained in:
parent
cfd6b6fed5
commit
939b44b4fd
|
@ -152,6 +152,7 @@ func (s *StepRunSourceInstance) Run(state multistep.StateBag) multistep.StepActi
|
||||||
}
|
}
|
||||||
ReportTags(ui, ec2Tags)
|
ReportTags(ui, ec2Tags)
|
||||||
|
|
||||||
|
createVolTagsAfterInstanceStarts := true
|
||||||
volTags, err := ConvertToEC2Tags(s.VolumeTags, *ec2conn.Config.Region, s.SourceAMI, s.Ctx)
|
volTags, err := ConvertToEC2Tags(s.VolumeTags, *ec2conn.Config.Region, s.SourceAMI, s.Ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err := fmt.Errorf("Error tagging volumes: %s", err)
|
err := fmt.Errorf("Error tagging volumes: %s", err)
|
||||||
|
@ -193,6 +194,7 @@ func (s *StepRunSourceInstance) Run(state multistep.StateBag) multistep.StepActi
|
||||||
}
|
}
|
||||||
|
|
||||||
tagSpecs = append(tagSpecs, runVolTags)
|
tagSpecs = append(tagSpecs, runVolTags)
|
||||||
|
createVolTagsAfterInstanceStarts = false
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(tagSpecs) > 0 {
|
if len(tagSpecs) > 0 {
|
||||||
|
@ -355,6 +357,44 @@ func (s *StepRunSourceInstance) Run(state multistep.StateBag) multistep.StepActi
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if createVolTagsAfterInstanceStarts {
|
||||||
|
volumeIds := make([]*string, 0)
|
||||||
|
for _, v := range instance.BlockDeviceMappings {
|
||||||
|
if ebs := v.Ebs; ebs != nil {
|
||||||
|
volumeIds = append(volumeIds, ebs.VolumeId)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(volumeIds) > 0 {
|
||||||
|
ui.Say("Adding tags to source EBS Volumes")
|
||||||
|
tags, err := ConvertToEC2Tags(s.VolumeTags, *ec2conn.Config.Region, s.SourceAMI, s.Ctx)
|
||||||
|
if err != nil {
|
||||||
|
err := fmt.Errorf("Error tagging source EBS Volumes on %s: %s", *instance.InstanceId, err)
|
||||||
|
state.Put("error", err)
|
||||||
|
ui.Error(err.Error())
|
||||||
|
return multistep.ActionHalt
|
||||||
|
}
|
||||||
|
|
||||||
|
ReportTags(ui, tags)
|
||||||
|
|
||||||
|
_, err = ec2conn.CreateTags(&ec2.CreateTagsInput{
|
||||||
|
Resources: volumeIds,
|
||||||
|
Tags: tags,
|
||||||
|
})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
err := fmt.Errorf("Error tagging source EBS Volumes on %s: %s", *instance.InstanceId, err)
|
||||||
|
state.Put("error", err)
|
||||||
|
ui.Error(err.Error())
|
||||||
|
return multistep.ActionHalt
|
||||||
|
}
|
||||||
|
|
||||||
|
return multistep.ActionContinue
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
if s.Debug {
|
if s.Debug {
|
||||||
if instance.PublicDnsName != nil && *instance.PublicDnsName != "" {
|
if instance.PublicDnsName != nil && *instance.PublicDnsName != "" {
|
||||||
ui.Message(fmt.Sprintf("Public DNS: %s", *instance.PublicDnsName))
|
ui.Message(fmt.Sprintf("Public DNS: %s", *instance.PublicDnsName))
|
||||||
|
|
Loading…
Reference in New Issue