diff --git a/builtin/providers/aws/resource_aws_lambda_function.go b/builtin/providers/aws/resource_aws_lambda_function.go index f123298e6..5f8a81684 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 349270d84..06c7a64db 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" {