Skip to content

Commit 7e1dc17

Browse files
authored
Merge pull request #133 from wata727/fix_nil_pointer_dereference
Fix panic by nil pointer dereference
2 parents 020927f + a9728c5 commit 7e1dc17

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ source "amazon-ebs" "example" {
6767
instance_type = "t2.micro"
6868
ssh_username = "ec2-user"
6969
ssh_pty = true
70-
ami_name = "packer-example"
71-
tags {
70+
ami_name = "packer-example ${formatdate("YYYYMMDDhhmmss", timestamp())}"
71+
tags = {
7272
Amazon_AMI_Management_Identifier = "packer-example"
7373
}
7474
}

cleaner.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ func (c *Cleaner) DeleteImage(image *ec2.Image) error {
134134
log.Printf("Deleting snapshot related to AMI (%s)", *image.ImageId)
135135
for _, device := range image.BlockDeviceMappings {
136136
// skip delete if use ephemeral devise
137-
if device.Ebs == nil {
137+
if device.Ebs == nil || device.Ebs.SnapshotId == nil {
138138
continue
139139
}
140140
log.Printf("Deleting snapshot (%s) related to AMI (%s)", *device.Ebs.SnapshotId, *image.ImageId)
@@ -179,6 +179,10 @@ func (c *Cleaner) setInstanceUsed() error {
179179
}
180180
for _, reservation := range ret.Reservations {
181181
for _, instance := range reservation.Instances {
182+
if instance.ImageId == nil {
183+
continue
184+
}
185+
182186
c.used[*instance.ImageId] = &Used{
183187
ID: *instance.InstanceId,
184188
Type: "instance",
@@ -194,6 +198,10 @@ func (c *Cleaner) setLaunchConfigurationUsed() error {
194198
return err
195199
}
196200
for _, lc := range ret.LaunchConfigurations {
201+
if lc.ImageId == nil {
202+
continue
203+
}
204+
197205
c.used[*lc.ImageId] = &Used{
198206
ID: *lc.LaunchConfigurationName,
199207
Type: "launch configuration",
@@ -217,6 +225,10 @@ func (c *Cleaner) setLaunchTemplateUsed() error {
217225
}
218226

219227
for _, ltv := range versions.LaunchTemplateVersions {
228+
if ltv.LaunchTemplateData == nil || ltv.LaunchTemplateData.ImageId == nil {
229+
continue
230+
}
231+
220232
c.used[*ltv.LaunchTemplateData.ImageId] = &Used{
221233
ID: fmt.Sprintf("%s (%d)", *ltv.LaunchTemplateName, *ltv.VersionNumber),
222234
Type: "launch template",

0 commit comments

Comments
 (0)