Merge pull request #14964 from hashicorp/b-fix-panic-nil-dead-letter-config
provider/aws: Fix panic on nil dead_letter_config
This commit is contained in:
commit
0845ab8d0f
|
@ -263,6 +263,10 @@ func resourceAwsLambdaFunctionCreate(d *schema.ResourceData, meta interface{}) e
|
||||||
if v, ok := d.GetOk("dead_letter_config"); ok {
|
if v, ok := d.GetOk("dead_letter_config"); ok {
|
||||||
dlcMaps := v.([]interface{})
|
dlcMaps := v.([]interface{})
|
||||||
if len(dlcMaps) == 1 { // Schema guarantees either 0 or 1
|
if len(dlcMaps) == 1 { // Schema guarantees either 0 or 1
|
||||||
|
// Prevent panic on nil dead_letter_config. See GH-14961
|
||||||
|
if dlcMaps[0] == nil {
|
||||||
|
return fmt.Errorf("Nil dead_letter_config supplied for function: %s", functionName)
|
||||||
|
}
|
||||||
dlcMap := dlcMaps[0].(map[string]interface{})
|
dlcMap := dlcMaps[0].(map[string]interface{})
|
||||||
params.DeadLetterConfig = &lambda.DeadLetterConfig{
|
params.DeadLetterConfig = &lambda.DeadLetterConfig{
|
||||||
TargetArn: aws.String(dlcMap["target_arn"].(string)),
|
TargetArn: aws.String(dlcMap["target_arn"].(string)),
|
||||||
|
|
|
@ -232,6 +232,24 @@ func TestAccAWSLambdaFunction_DeadLetterConfig(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAccAWSLambdaFunction_nilDeadLetterConfig(t *testing.T) {
|
||||||
|
rSt := acctest.RandString(5)
|
||||||
|
rName := fmt.Sprintf("tf_test_%s", rSt)
|
||||||
|
|
||||||
|
resource.Test(t, resource.TestCase{
|
||||||
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
|
Providers: testAccProviders,
|
||||||
|
CheckDestroy: testAccCheckLambdaFunctionDestroy,
|
||||||
|
Steps: []resource.TestStep{
|
||||||
|
{
|
||||||
|
Config: testAccAWSLambdaConfigWithNilDeadLetterConfig(rName, rSt),
|
||||||
|
ExpectError: regexp.MustCompile(
|
||||||
|
fmt.Sprintf("Nil dead_letter_config supplied for function: %s", rName)),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func TestAccAWSLambdaFunction_tracingConfig(t *testing.T) {
|
func TestAccAWSLambdaFunction_tracingConfig(t *testing.T) {
|
||||||
var conf lambda.GetFunctionOutput
|
var conf lambda.GetFunctionOutput
|
||||||
|
|
||||||
|
@ -1135,6 +1153,22 @@ resource "aws_sns_topic" "lambda_function_test" {
|
||||||
`, rName, rName)
|
`, rName, rName)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testAccAWSLambdaConfigWithNilDeadLetterConfig(rName, rSt string) string {
|
||||||
|
return fmt.Sprintf(baseAccAWSLambdaConfig(rSt)+`
|
||||||
|
resource "aws_lambda_function" "lambda_function_test" {
|
||||||
|
filename = "test-fixtures/lambdatest.zip"
|
||||||
|
function_name = "%s"
|
||||||
|
role = "${aws_iam_role.iam_for_lambda.arn}"
|
||||||
|
handler = "exports.example"
|
||||||
|
runtime = "nodejs4.3"
|
||||||
|
|
||||||
|
dead_letter_config {
|
||||||
|
target_arn = ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`, rName)
|
||||||
|
}
|
||||||
|
|
||||||
func testAccAWSLambdaConfigWithVPC(rName, rSt string) string {
|
func testAccAWSLambdaConfigWithVPC(rName, rSt string) string {
|
||||||
return fmt.Sprintf(baseAccAWSLambdaConfig(rSt)+`
|
return fmt.Sprintf(baseAccAWSLambdaConfig(rSt)+`
|
||||||
resource "aws_lambda_function" "lambda_function_test" {
|
resource "aws_lambda_function" "lambda_function_test" {
|
||||||
|
|
Loading…
Reference in New Issue