Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Workaround attempt for perpetual diff in lambda with vpc_config #16124

Closed
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion aws/resource_aws_lambda_function.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"io/ioutil"
"log"
"reflect"
"regexp"
"time"

Expand Down Expand Up @@ -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)
Copy link
Contributor

@gdavison gdavison Nov 11, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It took me a while to see this, but this is setting hasVpcConfigChange to true when they're DeepEqual. However, since vpc_config contains TypeSet elements, it will always return not equal, because TypeSets are never DeepEqual

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have tested this with a real Terraform project and this works: I don't have a plan with this change when a lambda_function has a vpc_config, and have a plan without that change. Additional debug logs show that hasChange("vpc_config") returns true, and reflect.DeepEqual(o, n) also returns true.

I have also tested it against a real change in vpc_config and made sure it shows up in plan.

However, since there can be only one vpc_config, if hasChange("vpc_config.0.subnet_ids") || hasChange("vpc_config.0.security_group_ids") does the trick, it seems to be a cleaner solution – it doesn't need reflection or conditionals. I'll test it.

}

return d.HasChange("description") ||
d.HasChange("handler") ||
d.HasChange("file_system_config") ||
Expand All @@ -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")
}
Expand Down Expand Up @@ -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 {
Expand Down