@@ -317,14 +317,38 @@ func TestAccBuilder_EbsForceDeleteSnapshot(t *testing.T) {
317317func checkSnapshotsDeleted (snapshotIds []string ) error {
318318 ctx := context .TODO ()
319319 // Verify the snapshots are gone
320- ec2conn , _ := testEC2Conn ("us-east-1" )
321- snapshotResp , _ := ec2conn .DescribeSnapshots (ctx ,
320+ ec2conn , err := testEC2Conn ("us-east-1" )
321+ if err != nil {
322+ return fmt .Errorf ("failed to create EC2 connection: %w" , err )
323+ }
324+
325+ snapshotResp , err := ec2conn .DescribeSnapshots (ctx ,
322326 & ec2.DescribeSnapshotsInput {SnapshotIds : snapshotIds },
323327 )
324328
329+ // In AWS SDK v2, when snapshots are deleted, DescribeSnapshots returns an error
330+ // with code "InvalidSnapshot.NotFound". This is the expected behavior.
331+ if err != nil {
332+ // Check if the error is InvalidSnapshot.NotFound, which means snapshots are deleted
333+ errMsg := err .Error ()
334+ if strings .Contains (errMsg , "InvalidSnapshot.NotFound" ) {
335+ // Snapshots are successfully deleted
336+ return nil
337+ }
338+ // Some other error occurred
339+ return fmt .Errorf ("error describing snapshots: %w" , err )
340+ }
341+
342+ // If no error and response is not nil, check if snapshots still exist
343+ if snapshotResp == nil {
344+ return fmt .Errorf ("received nil response from DescribeSnapshots" )
345+ }
346+
325347 if len (snapshotResp .Snapshots ) > 0 {
326- return fmt .Errorf ("Snapshots weren't successfully deleted by `force_delete_snapshot`" )
348+ return fmt .Errorf ("Snapshots weren't successfully deleted by `force_delete_snapshot`: found %d snapshot(s)" , len ( snapshotResp . Snapshots ) )
327349 }
350+
351+ // No error, no snapshots found - they are deleted
328352 return nil
329353}
330354
@@ -372,7 +396,11 @@ func checkAMISharing(ami amazon_acc.AMIHelper, count int, uid, group string) err
372396 return fmt .Errorf ("failed to find ami %s at region %s" , ami .Name , ami .Region )
373397 }
374398
375- ec2Client , _ := testEC2Conn ("us-east-1" )
399+ ec2Client , err := testEC2Conn ("us-east-1" )
400+ if err != nil {
401+ return fmt .Errorf ("failed to create EC2 connection: %w" , err )
402+ }
403+
376404 imageResp , err := ec2Client .DescribeImageAttribute (ctx , & ec2.DescribeImageAttributeInput {
377405 Attribute : "launchPermission" ,
378406 ImageId : images [0 ].ImageId ,
@@ -550,14 +578,21 @@ func checkBootEncrypted(ami amazon_acc.AMIHelper) error {
550578 }
551579 ctx := context .TODO ()
552580 // describe the image, get block devices with a snapshot
553- ec2Client , _ := testEC2Conn (ami .Region )
581+ ec2Client , err := testEC2Conn (ami .Region )
582+ if err != nil {
583+ return fmt .Errorf ("failed to create EC2 connection: %w" , err )
584+ }
585+
554586 imageResp , err := ec2Client .DescribeImages (ctx , & ec2.DescribeImagesInput {
555587 ImageIds : []string {* images [0 ].ImageId },
556588 })
557589
558590 if err != nil {
559591 return fmt .Errorf ("Error retrieving Image Attributes for AMI (%s) in AMI Encrypted Boot Test: %s" , ami .Name , err )
560592 }
593+ if imageResp == nil || len (imageResp .Images ) == 0 {
594+ return fmt .Errorf ("received nil or empty response from DescribeImages" )
595+ }
561596
562597 image := imageResp .Images [0 ] // Only requested a single AMI ID
563598
@@ -687,6 +722,9 @@ func checkDeprecationEnabled(ami amazon_acc.AMIHelper, deprecationTime time.Time
687722 if err != nil {
688723 return fmt .Errorf ("Error Describe Image for AMI (%s): %s" , ami .Name , err )
689724 }
725+ if imageResp == nil || len (imageResp .Images ) == 0 {
726+ return fmt .Errorf ("received nil or empty response from DescribeImages" )
727+ }
690728
691729 expectTime := deprecationTime .Round (time .Minute )
692730 expectTimeStr := expectTime .Format (time .RFC3339 )
@@ -1459,13 +1497,20 @@ func checkAMITags(ami amazon_acc.AMIHelper, tagList map[string]string) error {
14591497 amiNameRegion := fmt .Sprintf ("%s/%s" , ami .Region , ami .Name )
14601498
14611499 // describe the image, get block devices with a snapshot
1462- ec2Client , _ := testEC2Conn (ami .Region )
1500+ ec2Client , err := testEC2Conn (ami .Region )
1501+ if err != nil {
1502+ return fmt .Errorf ("failed to create EC2 connection: %w" , err )
1503+ }
1504+
14631505 imageResp , err := ec2Client .DescribeImages (ctx , & ec2.DescribeImagesInput {
14641506 ImageIds : []string {* images [0 ].ImageId },
14651507 })
14661508 if err != nil {
14671509 return fmt .Errorf ("failed to describe AMI %q: %s" , amiNameRegion , err )
14681510 }
1511+ if imageResp == nil || len (imageResp .Images ) == 0 {
1512+ return fmt .Errorf ("received nil or empty response from DescribeImages for AMI %q" , amiNameRegion )
1513+ }
14691514
14701515 var errs error
14711516 image := imageResp .Images [0 ] // Only requested a single AMI ID
@@ -1816,6 +1861,9 @@ func checkDeregistrationProtectionEnabled(ami amazon_acc.AMIHelper) error {
18161861 if err != nil {
18171862 return fmt .Errorf ("Error Describe Image for AMI (%s): %s" , ami .Name , err )
18181863 }
1864+ if imageResp == nil || len (imageResp .Images ) == 0 {
1865+ return fmt .Errorf ("received nil or empty response from DescribeImages" )
1866+ }
18191867
18201868 image := imageResp .Images [0 ]
18211869 if image .DeregistrationProtection == nil {
@@ -1987,7 +2035,7 @@ const testBuilderAccSessionManagerInterface = `
19872035const testBuilderAccSSMWithReboot = `
19882036source "amazon-ebs" "test" {
19892037 ami_name = "%s"
1990- source_ami = "ami-00874d747dde814fa " # Ubuntu Server 22.04 LTS
2038+ source_ami = "ami-0b4a8cd67f04e48b7 " # hc-base-ubuntu-2204-20260330144317
19912039 instance_type = "m3.medium"
19922040 region = "us-east-1"
19932041 ssh_username = "ubuntu"
@@ -2045,10 +2093,10 @@ build {
20452093const testPrivateKeyFileWithReboot = `
20462094source "amazon-ebs" "test" {
20472095 ami_name = "%s"
2048- source_ami = "ami-00874d747dde814fa " # Ubuntu Server 22.04 LTS
2096+ source_ami = "ami-0b5eea76982371e91 " # Amazon Linux 2 AMI - kernel 5.10
20492097 instance_type = "m3.medium"
20502098 region = "us-east-1"
2051- ssh_username = "ubuntu "
2099+ ssh_username = "ec2-user "
20522100 ssh_interface = "session_manager"
20532101 iam_instance_profile = "SSMInstanceProfile"
20542102 communicator = "ssh"
@@ -2072,7 +2120,7 @@ build {
20722120const testIMDSv2Support = `
20732121source "amazon-ebs" "test" {
20742122 ami_name = "%s"
2075- source_ami = "ami-00874d747dde814fa " # Ubuntu Server 22.04 LTS
2123+ source_ami = "ami-0b4a8cd67f04e48b7 " # hc-base-ubuntu-2204-20260330144317
20762124 instance_type = "m3.medium"
20772125 region = "us-east-1"
20782126 ssh_username = "ubuntu"
@@ -2090,7 +2138,7 @@ build {
20902138const testAMIRunTagsCopyKeepRunTags = `
20912139source "amazon-ebs" "test" {
20922140 region = "us-east-1"
2093- source_ami = "ami-00874d747dde814fa " # Ubuntu Server 22.04 LTS
2141+ source_ami = "ami-0b4a8cd67f04e48b7 " # hc-base-ubuntu-2204-20260330144317
20942142 instance_type = "m3.medium"
20952143 ami_name = "%s"
20962144 communicator = "ssh"
@@ -2115,7 +2163,7 @@ build {
21152163const testAMIRunTagsCopyKeepTags = `
21162164source "amazon-ebs" "test" {
21172165 region = "us-east-1"
2118- source_ami = "ami-00874d747dde814fa " # Ubuntu Server 22.04 LTS
2166+ source_ami = "ami-0b4a8cd67f04e48b7 " # hc-base-ubuntu-2204-20260330144317
21192167 instance_type = "m3.medium"
21202168 ami_name = "%s"
21212169 communicator = "ssh"
@@ -2157,7 +2205,7 @@ build {
21572205const sshPasswordEnabledAMI = `
21582206source "amazon-ebs" "test" {
21592207 region = "us-east-1"
2160- source_ami = "ami-00874d747dde814fa " # Ubuntu Server 22.04 LTS
2208+ source_ami = "ami-0b4a8cd67f04e48b7 " # hc-base-ubuntu-2204-20260330144317
21612209 instance_type = "m3.medium"
21622210 ami_name = "%s"
21632211 communicator = "ssh"
@@ -2176,7 +2224,7 @@ build {
21762224 "set -e",
21772225 "sudo su",
21782226 "echo 'Enabling SSH password authentication...'",
2179- "sudo sed -i 's/^PasswordAuthentication no /PasswordAuthentication yes/' /etc/ssh/sshd_config",
2227+ "sudo sed -i 's/^# PasswordAuthentication yes /PasswordAuthentication yes/' /etc/ssh/sshd_config",
21802228 "sudo useradd -m -s /bin/bash user",
21812229 "echo 'Setting up password for user'",
21822230 "echo 'user:password' | sudo chpasswd ubuntu",
0 commit comments