From 3f9e48b427a51b3c7b0cc4ae5e10bc796c4d1de6 Mon Sep 17 00:00:00 2001 From: Brian Flad Date: Tue, 12 Nov 2019 15:38:58 -0500 Subject: [PATCH 1/2] resource/aws_lambda_function: Expand kms_key_arn documentation and testing when no environment variables are present Reference: https://github.com/terraform-providers/terraform-provider-aws/issues/6366 Output from acceptance testing: ``` --- PASS: TestAccAWSLambdaFunction_KmsKeyArn_NoEnvironmentVariables (56.91s) ``` --- aws/resource_aws_lambda_function_test.go | 66 ++++++++++++++++++++ website/docs/r/lambda_function.html.markdown | 2 +- 2 files changed, 67 insertions(+), 1 deletion(-) diff --git a/aws/resource_aws_lambda_function_test.go b/aws/resource_aws_lambda_function_test.go index 608e3b306edf..ce7db65661ac 100644 --- a/aws/resource_aws_lambda_function_test.go +++ b/aws/resource_aws_lambda_function_test.go @@ -616,6 +616,36 @@ func TestAccAWSLambdaFunction_tracingConfig(t *testing.T) { }) } +// Reference: https://github.com/terraform-providers/terraform-provider-aws/issues/6366 +func TestAccAWSLambdaFunction_KmsKeyArn_NoEnvironmentVariables(t *testing.T) { + var function1 lambda.GetFunctionOutput + + rName := acctest.RandomWithPrefix("tf-acc-test") + resourceName := "aws_lambda_function.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckLambdaFunctionDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAWSLambdaConfigKmsKeyArnNoEnvironmentVariables(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAwsLambdaFunctionExists(resourceName, rName, &function1), + resource.TestCheckResourceAttr(resourceName, "kms_key_arn", ""), + ), + ExpectNonEmptyPlan: true, + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"filename", "publish"}, + }, + }, + }) +} + func TestAccAWSLambdaFunction_Layers(t *testing.T) { var conf lambda.GetFunctionOutput @@ -2192,6 +2222,42 @@ resource "aws_lambda_function" "test" { `, funcName) } +func testAccAWSLambdaConfigKmsKeyArnNoEnvironmentVariables(rName string) string { + return fmt.Sprintf(baseAccAWSLambdaConfig(rName, rName, rName)+` +resource "aws_kms_key" "test" { + description = %[1]q + deletion_window_in_days = 7 + + policy = < Date: Tue, 12 Nov 2019 16:38:49 -0500 Subject: [PATCH 2/2] tests/resource/aws_lambda_function: Add more information to TestAccAWSLambdaFunction_KmsKeyArn_NoEnvironmentVariables test comment --- aws/resource_aws_lambda_function_test.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/aws/resource_aws_lambda_function_test.go b/aws/resource_aws_lambda_function_test.go index ce7db65661ac..189b8543afbf 100644 --- a/aws/resource_aws_lambda_function_test.go +++ b/aws/resource_aws_lambda_function_test.go @@ -616,6 +616,9 @@ func TestAccAWSLambdaFunction_tracingConfig(t *testing.T) { }) } +// This test is to verify the existing behavior in the Lambda API where the KMS Key ARN +// is not returned if environment variables are not in use. If the API begins saving this +// value and the kms_key_arn check begins failing, the documentation should be updated. // Reference: https://github.com/terraform-providers/terraform-provider-aws/issues/6366 func TestAccAWSLambdaFunction_KmsKeyArn_NoEnvironmentVariables(t *testing.T) { var function1 lambda.GetFunctionOutput