Handle empty Lambda environment. (#10306)
The Lambda environment will be nil if the function has never had an environment applied. Fixes #10302
This commit is contained in:
parent
3fd6c253ea
commit
3be29ab5d0
|
@ -333,7 +333,7 @@ func resourceAwsLambdaFunctionRead(d *schema.ResourceData, meta interface{}) err
|
|||
|
||||
d.Set("source_code_hash", function.CodeSha256)
|
||||
|
||||
if err := d.Set("environment", flattenLambdaEnvironment(function.Environment.Variables)); err != nil {
|
||||
if err := d.Set("environment", flattenLambdaEnvironment(function.Environment)); err != nil {
|
||||
log.Printf("[ERR] Error setting environment for Lambda Function (%s): %s", d.Id(), err)
|
||||
}
|
||||
|
||||
|
|
|
@ -49,6 +49,15 @@ func TestAccAWSLambdaFunction_envVariables(t *testing.T) {
|
|||
Providers: testAccProviders,
|
||||
CheckDestroy: testAccCheckLambdaFunctionDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
{
|
||||
Config: testAccAWSLambdaConfigBasic(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"),
|
||||
),
|
||||
},
|
||||
{
|
||||
Config: testAccAWSLambdaConfigEnvVariables(rName),
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
|
|
|
@ -950,10 +950,15 @@ func flattenDSVpcSettings(
|
|||
return []map[string]interface{}{settings}
|
||||
}
|
||||
|
||||
func flattenLambdaEnvironment(variables map[string]*string) []interface{} {
|
||||
func flattenLambdaEnvironment(lambdaEnv *lambda.EnvironmentResponse) []interface{} {
|
||||
envs := make(map[string]interface{})
|
||||
en := make(map[string]string)
|
||||
for k, v := range variables {
|
||||
|
||||
if lambdaEnv == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
for k, v := range lambdaEnv.Variables {
|
||||
en[k] = *v
|
||||
}
|
||||
if len(en) > 0 {
|
||||
|
|
Loading…
Reference in New Issue