Skip to content

Commit

Permalink
Merge pull request #189 from HarrisonWAffel/enhance-ec2-logging
Browse files Browse the repository at this point in the history
ensure proper logging of instance creation failures
  • Loading branch information
HarrisonWAffel authored Jul 27, 2022
2 parents add42df + ed79a04 commit a468db1
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions drivers/amazonec2/amazonec2.go
Original file line number Diff line number Diff line change
Expand Up @@ -647,9 +647,10 @@ func (d *Driver) Create() error {
// PreCreateCheck has already been called

if err := d.innerCreate(); err != nil {
log.Warnf("error encountered during instance creation: %s", err.Error())
// cleanup partially created resources
if err := d.Remove(); err != nil {
return err
if removalErr := d.Remove(); removalErr != nil {
return removalErr
}
return err
}
Expand Down Expand Up @@ -690,7 +691,7 @@ func (d *Driver) innerCreate() error {
var instance *ec2.Instance
if d.RequestSpotInstance {
req := ec2.RunInstancesInput{
ImageId: &d.AMI,
ImageId: &d.AMI,
MinCount: aws.Int64(1),
MaxCount: aws.Int64(1),
Placement: &ec2.Placement{
Expand All @@ -706,11 +707,11 @@ func (d *Driver) innerCreate() error {
EbsOptimized: &d.UseEbsOptimizedInstance,
BlockDeviceMappings: bdmList,
UserData: &userdata,
MetadataOptions: &ec2.InstanceMetadataOptionsRequest{},
MetadataOptions: &ec2.InstanceMetadataOptionsRequest{},
InstanceMarketOptions: &ec2.InstanceMarketOptionsRequest{
MarketType: aws.String(ec2.MarketTypeSpot),
SpotOptions: &ec2.SpotMarketOptions{
MaxPrice: &d.SpotPrice,
MaxPrice: &d.SpotPrice,
SpotInstanceType: aws.String(ec2.SpotInstanceTypeOneTime),
},
},
Expand Down Expand Up @@ -808,7 +809,7 @@ func (d *Driver) innerCreate() error {
EbsOptimized: &d.UseEbsOptimizedInstance,
BlockDeviceMappings: bdmList,
UserData: &userdata,
MetadataOptions: &ec2.InstanceMetadataOptionsRequest{},
MetadataOptions: &ec2.InstanceMetadataOptionsRequest{},
TagSpecifications: resourceTags,
}

Expand Down

0 comments on commit a468db1

Please sign in to comment.