From 47a65e2319fceb056074aceda1bf3c5aa2eeda62 Mon Sep 17 00:00:00 2001 From: Maciej Pasternacki Date: Tue, 10 Nov 2020 19:22:08 +0100 Subject: [PATCH 1/2] Workaround attempt for perpetual diff in lambda with vpc_config --- aws/resource_aws_lambda_function.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/aws/resource_aws_lambda_function.go b/aws/resource_aws_lambda_function.go index 13070631ed3..7a4406feadb 100644 --- a/aws/resource_aws_lambda_function.go +++ b/aws/resource_aws_lambda_function.go @@ -6,6 +6,7 @@ import ( "fmt" "io/ioutil" "log" + "reflect" "regexp" "time" @@ -283,10 +284,18 @@ func updateComputedAttributesOnPublish(_ context.Context, d *schema.ResourceDiff d.SetNewComputed("version") d.SetNewComputed("qualified_arn") } + return nil } func hasConfigChanges(d resourceDiffer) bool { + hasVpcConfigChange := d.HasChange("vpc_config") + if hasVpcConfigChange { + // This returns true when vpc_config is set even when the values are the same + o, n := d.GetChange("vpc_config") + hasVpcConfigChange = reflect.DeepEqual(o, n) + } + return d.HasChange("description") || d.HasChange("handler") || d.HasChange("file_system_config") || @@ -297,7 +306,7 @@ func hasConfigChanges(d resourceDiffer) bool { d.HasChange("layers") || d.HasChange("dead_letter_config") || d.HasChange("tracing_config") || - d.HasChange("vpc_config") || + hasVpcConfigChange || d.HasChange("runtime") || d.HasChange("environment") } @@ -693,6 +702,7 @@ func resourceAwsLambdaFunctionDelete(d *schema.ResourceData, meta interface{}) e type resourceDiffer interface { HasChange(string) bool + GetChange(string) (interface{}, interface{}) } func needsFunctionCodeUpdate(d resourceDiffer) bool { From 654e8822b3f662a78a2536cc8a02deee44356d04 Mon Sep 17 00:00:00 2001 From: Maciej Pasternacki Date: Thu, 12 Nov 2020 15:12:38 +0100 Subject: [PATCH 2/2] aws_lambda_function: test for individual vpc_config properties in hasConfigChanges, avoid reflection --- aws/resource_aws_lambda_function.go | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/aws/resource_aws_lambda_function.go b/aws/resource_aws_lambda_function.go index 7a4406feadb..8ada277f0aa 100644 --- a/aws/resource_aws_lambda_function.go +++ b/aws/resource_aws_lambda_function.go @@ -6,7 +6,6 @@ import ( "fmt" "io/ioutil" "log" - "reflect" "regexp" "time" @@ -289,13 +288,6 @@ func updateComputedAttributesOnPublish(_ context.Context, d *schema.ResourceDiff } func hasConfigChanges(d resourceDiffer) bool { - hasVpcConfigChange := d.HasChange("vpc_config") - if hasVpcConfigChange { - // This returns true when vpc_config is set even when the values are the same - o, n := d.GetChange("vpc_config") - hasVpcConfigChange = reflect.DeepEqual(o, n) - } - return d.HasChange("description") || d.HasChange("handler") || d.HasChange("file_system_config") || @@ -306,7 +298,8 @@ func hasConfigChanges(d resourceDiffer) bool { d.HasChange("layers") || d.HasChange("dead_letter_config") || d.HasChange("tracing_config") || - hasVpcConfigChange || + d.HasChange("vpc_config.0.subnet_ids") || + d.HasChange("vpc_config.0.security_group_ids") || d.HasChange("runtime") || d.HasChange("environment") }