From 615da28b6e4075a85651305262fc8099127ea68a Mon Sep 17 00:00:00 2001 From: Ninir Date: Fri, 2 Dec 2016 14:36:55 +0100 Subject: [PATCH] provider/aws: Fixed Lambda environment removal --- .../aws/resource_aws_lambda_function.go | 5 +++++ .../aws/resource_aws_lambda_function_test.go | 21 +++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/builtin/providers/aws/resource_aws_lambda_function.go b/builtin/providers/aws/resource_aws_lambda_function.go index f123298e6bd2..5f8a8168464d 100644 --- a/builtin/providers/aws/resource_aws_lambda_function.go +++ b/builtin/providers/aws/resource_aws_lambda_function.go @@ -495,6 +495,11 @@ func resourceAwsLambdaFunctionUpdate(d *schema.ResourceData, meta interface{}) e } configUpdate = true } + } else { + configReq.Environment = &lambda.Environment{ + Variables: aws.StringMap(map[string]string{}), + } + configUpdate = true } } diff --git a/builtin/providers/aws/resource_aws_lambda_function_test.go b/builtin/providers/aws/resource_aws_lambda_function_test.go index 349270d84725..06c7a64dba97 100644 --- a/builtin/providers/aws/resource_aws_lambda_function_test.go +++ b/builtin/providers/aws/resource_aws_lambda_function_test.go @@ -77,6 +77,16 @@ func TestAccAWSLambdaFunction_envVariables(t *testing.T) { resource.TestCheckResourceAttr("aws_lambda_function.lambda_function_test", "environment.0.variables.foo1", "bar1"), ), }, + { + Config: testAccAWSLambdaConfigEnvVariablesModifiedWithoutEnvironment(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAwsLambdaFunctionExists("aws_lambda_function.lambda_function_test", rName, &conf), + testAccCheckAwsLambdaFunctionName(&conf, rName), + testAccCheckAwsLambdaFunctionArnHasSuffix(&conf, ":"+rName), + resource.TestCheckResourceAttr("aws_lambda_function.lambda_function_test", "environment.0.variables.foo", ""), + resource.TestCheckResourceAttr("aws_lambda_function.lambda_function_test", "environment.0.variables.foo1", ""), + ), + }, }, }) } @@ -648,6 +658,17 @@ resource "aws_lambda_function" "lambda_function_test" { `, rName) } +func testAccAWSLambdaConfigEnvVariablesModifiedWithoutEnvironment(rName string) string { + return fmt.Sprintf(baseAccAWSLambdaConfig+` +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" +} +`, rName) +} + func testAccAWSLambdaConfigEncryptedEnvVariables(rName string) string { return fmt.Sprintf(baseAccAWSLambdaConfig+` resource "aws_kms_key" "foo" {