From 6a4fe8e637389a92fd58cc0bc52196d49055b66c Mon Sep 17 00:00:00 2001 From: Angie Pinilla Date: Wed, 2 Dec 2020 10:42:06 -0500 Subject: [PATCH] update lambda package type check to prevent panic --- aws/resource_aws_lambda_function.go | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/aws/resource_aws_lambda_function.go b/aws/resource_aws_lambda_function.go index ee298898dff..9c216d2508c 100644 --- a/aws/resource_aws_lambda_function.go +++ b/aws/resource_aws_lambda_function.go @@ -808,26 +808,25 @@ func resourceAwsLambdaFunctionRead(d *schema.ResourceData, meta interface{}) err return nil } - codeSigningConfigInput := &lambda.GetFunctionCodeSigningConfigInput{ - FunctionName: aws.String(d.Get("function_name").(string)), - } - // Code Signing is only supported on zip packaged lambda functions. - if *function.PackageType == lambda.PackageTypeZip { + var codeSigningConfigArn string + + if aws.StringValue(function.PackageType) == lambda.PackageTypeZip { + codeSigningConfigInput := &lambda.GetFunctionCodeSigningConfigInput{ + FunctionName: aws.String(d.Id()), + } getCodeSigningConfigOutput, err := conn.GetFunctionCodeSigningConfig(codeSigningConfigInput) if err != nil { return fmt.Errorf("error getting Lambda Function (%s) code signing config %w", d.Id(), err) } - if getCodeSigningConfigOutput == nil || getCodeSigningConfigOutput.CodeSigningConfigArn == nil { - d.Set("code_signing_config_arn", "") - } else { - d.Set("code_signing_config_arn", getCodeSigningConfigOutput.CodeSigningConfigArn) + if getCodeSigningConfigOutput != nil { + codeSigningConfigArn = aws.StringValue(getCodeSigningConfigOutput.CodeSigningConfigArn) } - } else { - d.Set("code_signing_config_arn", "") } + d.Set("code_signing_config_arn", codeSigningConfigArn) + return nil }