-
Notifications
You must be signed in to change notification settings - Fork 1.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
feat: Return early during linking if no destination resources are found #5220
Changes from 3 commits
127defa
962f777
9ed3e5c
1ddaff0
f801862
9913d78
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -231,9 +231,12 @@ def _link_using_terraform_config(self, source_tf_resource: TFResource, cfn_resou | |
) | ||
if not dest_resources: | ||
LOG.debug( | ||
"There are destination resources defined for for the source resource %s", | ||
"There are destination resources defined for for the source resource %s, skipping linking.", | ||
source_tf_resource.full_address, | ||
) | ||
|
||
return | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. LGTM in general. I am just wondering why having 2 destinations is throwing an error (at line 229 above) but defining none is skipping this step. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comment explains it in a little more detail, but essentially we don't want to block the execution of some testing cases where the customer may have a partially defined API (eg. defined gateway, but missing some parts of method or integration). If they were looking to only test their Lambda function using In the case of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If this method linking layers to functions and also APIGW methods/paths to functions, should we have distinct ways? Like different part of our logic can call this function (either linking layers to functions or apigw methods/paths to functions), then this method can do whatever it supposed to do. The caller function then can decide whether the case is valid for that purpose or not. I feel like this method is been overloaded with different purposes, and this might lead to a bug in the future. (Of course there is a chance that I mis-understood everything wrong, in that case please ignore my comment :D ) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function is a generic function that we used to link different resources. The logic of what to be linked is maintained here https://github.com/aws/aws-sam-cli/blob/develop/samcli/hook_packages/terraform/hooks/prepare/resources/resource_links.py#L29-L81 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for your comment regarding the exception we raise in line 229, this is related to the Terraform limitations we have, at this point we could not differentiate if the customer is really linking to 2 different resources, or using some conditional expression to choose one of them. As, we do not know what to be done in this case, shall we use the 2 destination resources, or choose one of them, so, we decided to raise an exception to the customer that we do not support this case, and they can resolve this issue by running But, for no destination resources found at all, this means that there is no destinations at all to be linked, and should not be an issue (this like if the customer does not have any layers defined for a lambda function), so we do not raise exception here. Sometimes, it can be an issue in the customer terraform project, but we decided not to raise the exception here, and leave this decision to each SAM CLI command to decide if it is an issue or not (Like the customer define a Rest API method, but does not link it to a Lambda function) |
||
|
||
for cfn_resource in cfn_resources: | ||
self._resource_pair.cfn_resource_update_call_back_function(cfn_resource, dest_resources) # type: ignore | ||
|
||
|
@@ -284,7 +287,12 @@ def _link_using_linking_fields(self, cfn_resource: Dict) -> None: | |
else ExistingResourceReference(value) | ||
for value in values | ||
] | ||
LOG.debug("The value of the source resource linking field after mapping $s", dest_resources) | ||
|
||
if not dest_resources: | ||
LOG.debug("Skipping linking call back, no destination resources discovered.") | ||
return | ||
|
||
LOG.debug("The value of the source resource linking field after mapping %s", dest_resources) | ||
self._resource_pair.cfn_resource_update_call_back_function(cfn_resource, dest_resources) # type: ignore | ||
|
||
def _process_resolved_resources( | ||
|
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.
can you update the log message to be There are no destination resources
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.
Oh whoops, will update this