-
Notifications
You must be signed in to change notification settings - Fork 9.2k
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
Workaround attempt for perpetual diff in lambda with vpc_config #16124
Conversation
Hi @maciejp-ro, thanks for putting this together. It's helped me do some deeper investigation. It's related to hashicorp/terraform-plugin-sdk#617; a nested structure with a As a workaround, checking |
aws/resource_aws_lambda_function.go
Outdated
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) |
There was a problem hiding this comment.
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 TypeSet
s are never DeepEqual
There was a problem hiding this comment.
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.
For tests, you could make a copy of |
…ConfigChanges, avoid reflection
@maciejp-ro Thanks for the contribution 👏. |
I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. |
Community Note
Relates #15952
Release note for CHANGELOG:
WIP: Attempt at a workaround for perpetual plan on
aws_lambda_function
withvpc_config
. #15952 is labeled "good first issue", so I tried.I tracked the cause to
d.HasChange("vpc_config")
returningtrue
even ifvpc_config
did not actually change (two results fromGetChange
are identical as confirmed byreflect.DeepEqual
).I'm not very familiar with either this provider's internals or mechanics of Terraform plugins in general. This might be a bug in terraform-plugin-sdk (search for HasChange in the SDK repo returns some open issues, but they seem to refer to v1 of the SDK) or some subtle issue in the provider itself. Falling back on reflection to compare values seems to be code smell, but this fixes the issue for me and might provide some hints for a real fix.
I haven't figured out how to update tests yet, I'll try to add a test case later. Publishing a draft in the meantime to gather feedback (or help maintainers with finding a proper fix).
TODO: Output from acceptance testing: