From a0fb6be03344ed2d4887468efa64abe3fcce4634 Mon Sep 17 00:00:00 2001 From: Domas Monkus Date: Fri, 2 Jun 2023 16:39:20 +0300 Subject: [PATCH] Check if DescribeKeyPairs returns a result. (#754) --- task/aws/resources/resource_key_pair.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/task/aws/resources/resource_key_pair.go b/task/aws/resources/resource_key_pair.go index 3dd05bf7..72e4eb2f 100644 --- a/task/aws/resources/resource_key_pair.go +++ b/task/aws/resources/resource_key_pair.go @@ -5,6 +5,7 @@ import ( "errors" "strings" + "github.com/0x2b3bfa0/logrusctx" "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/service/ec2" "github.com/aws/aws-sdk-go-v2/service/ec2/types" @@ -90,7 +91,12 @@ func (k *KeyPair) Read(ctx context.Context) error { return common.NotFoundError } } - + if pairs == nil { + // Unexpected, but it looks like DescribeKeyPairs may return no error and a nil + // result. + logrusctx.Error(ctx, "EC2 DescribeKeyPairs returned nil result.") + return nil + } k.Resource = &pairs.KeyPairs[0] return nil }