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

sam build --hook-name terraform --beta-features command fails when creating nested resources in API Gateway #5639

Closed
arvindkurhe opened this issue Jul 28, 2023 · 11 comments
Labels
area/local/start-api sam local start-api command area/terraform terraform support issue stage/waiting-for-release Fix has been merged to develop and is waiting for a release type/bug

Comments

@arvindkurhe
Copy link

Hello Sir,

We are having existing terraform code with Lambda functions ready with API Gateway's parent and child resrouces at muli-level.

However when we are running following command getting errors

Command:sam build --hook-name terraform --beta-features

Error: Error: An error occurred when attempting to link two resources: Could not use the value aws_api_gateway_resource.parent._id
as a destination for the source resource module.module_dev.aws_api_gateway_resource.child. The source resource value should refer to valid destination ARN property.

We are attaching terrform code for you in this case.

SAM build command fails when creating/genrating
resource "aws_api_gateway_resource" "child_id_resource"

Awaiting resonse soon as this needs to resolve on priority.

API ID / Invoke URL: d
Region: us-east-1
Please select the type of API Gateway: REST API

@moelasmar
Copy link
Contributor

Thanks @arvindkurhe for raising this issue, could you please share with us your terraform project to be able to reproduce this issue.

@moelasmar moelasmar added blocked/more-info-needed More info is needed from the requester. If no response in 14 days, it will become stale. area/local/start-api sam local start-api command blocked/close-if-inactive Blocked for >14 days with no response, will be closed if still inactive after 7 days area/terraform terraform support issue labels Jul 28, 2023
@moelasmar
Copy link
Contributor

Also, as a workaround can you check if running terraform apply helps you to solve this probelm.

@arvindkurhe
Copy link
Author

This issue persist from the sam version 1.83.0 to latest version

@arvindkurhe
Copy link
Author

Here are the terraform files,

outputs.tf.txt
main.tf.txt

We are referring article "Better together: AWS SAM CLI and HashiCorp Terraform" from the following page,
https://aws.amazon.com/blogs/compute/better-together-aws-sam-cli-and-hashicorp-terraform/

And using the Github repo link provided in the above-mentioned link,
https://github.com/aws-samples/aws-sam-terraform-examples

We have updated API Gateway implementation with API Gateway REST API as per our needs.
As you are not able to reproduce the issue we have come up with the following,
1. Code provide in URL https://github.com/aws-samples/aws-sam-terraform-examples updated
2. We are using code from the following folder as per the documentation,
<>:\aws-ssm-terraform\zip_based_lambda_functions\api-lambda-dynamodb-example
3. Executed terraform command and deployed in this account and the endpoint is as below,
https://.execute-api.us-east-1.amazonaws.com/my_stage/event
https://.execute-api.us-east-1.amazonaws.com/my_stage/event/child
4. Then we have executed the following command,
sam build --hook-name terraform --beta-features
This command gives the following error,
Error: An error occurred when attempting to link two resources: Could not use the value aws_api_gateway_resource.parent as a destination for the source resource aws_api_gateway_resource.child_resource.

@github-actions
Copy link
Contributor

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

@arvindkurhe arvindkurhe reopened this Jul 29, 2023
@arvindkurhe
Copy link
Author

Closed issue by mistake

@moelasmar moelasmar added type/bug and removed blocked/more-info-needed More info is needed from the requester. If no response in 14 days, it will become stale. blocked/close-if-inactive Blocked for >14 days with no response, will be closed if still inactive after 7 days labels Jul 31, 2023
@moelasmar
Copy link
Contributor

I was able to reproduce this issue, we will work on fixing this issue.

@mudassir-ahmed
Copy link

Thanks for the SAM CLI. Do we know when this fix will be released and/or is it possible to build from source? We are blocked by this.

@github-actions
Copy link
Contributor

Patch is released in v1.95.0. Closing

@moelasmar
Copy link
Contributor

Hello @mudassir-ahmed, the fix for this problem got released in v1.95.0. Regarding your question to build from source, unfortunately we will not support that for Terraform projects. The reason is SAM CLI depends on running terraform apply for specific resources to build the lambda functions and layers resources exist in the customer's project, and since SAM CLI should not update customer state, we copied the project to a temp directory to do building to make sure we did not alter the customer's state.

Also, in case of remote backend states, SAM CLI overwrites that to use local states instead, and these types of changes we do not want to do it to the customer's project.

Could you please let us know why you are looking for build from source for Terraform project, if it is related to this problem, so the team is working now on a fix for it, that will be shipped soon.

@mudassir-ahmed
Copy link

Hello @mudassir-ahmed, the fix for this problem got released in v1.95.0. Regarding your question to build from source, unfortunately we will not support that for Terraform projects. The reason is SAM CLI depends on running terraform apply for specific resources to build the lambda functions and layers resources exist in the customer's project, and since SAM CLI should not update customer state, we copied the project to a temp directory to do building to make sure we did not alter the customer's state.

Also, in case of remote backend states, SAM CLI overwrites that to use local states instead, and these types of changes we do not want to do it to the customer's project.

Could you please let us know why you are looking for build from source for Terraform project, if it is related to this problem, so the team is working now on a fix for it, that will be shipped soon.

Thanks @moelasmar . We've just tried version 1.95 and everything is working for us.

Regarding the build from source: I meant is it possible to build the SAM CLI from source so we have the latest - however, we don't need to do this anymore since version 1.95 has the fix we're after. Thanks again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/local/start-api sam local start-api command area/terraform terraform support issue stage/waiting-for-release Fix has been merged to develop and is waiting for a release type/bug
Projects
None yet
Development

No branches or pull requests

3 participants