-
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
Native support for Terraform in SAM CLI (now in Beta) #3154
Comments
The "usual" way of doing Lambdas with Terraform is to use a module that abstracts the Lambda build and IaC boilerplate. A great module is serverless.tf's terraform-aws-lambda module. I'd love to see I am imagining a repo like this:
As a developer, I would clone the above repo, run In the CI/CD pipeline, |
@Vlaaaaaaad I like the idea of bringing an alternative approach to the (When we were making the terraform-aws-lambda module module, Terraform has its own resource lifecycle management which is carefully implemented as a part of the terraform-aws-lambda module. For example, rebuild the package and redeploy it only if something in dependencies changed. This does not sound like an easy task for me to even describe how Terraform & SAM should share the lifecycle management since resources can be cross-linked between SAM template and Terraform code. As a developer, I like to have a tool that does comprehensive infrastructure management and serverless application deployments. Yes, there is more to be done to improve the developer experience but it is not related to SAM CLI or this issue. |
Good point! |
@Vlaaaaaaad @antonbabenko Thank you for the feedback - this is helpful. To help us prioritize and make the integration decision, do you know how many Lambda users rely on the terraform-aws-lambda module? Could we get their +1s here if you are connected to the community? |
@praneetap Let me share some statistics for the terraform-aws-lambda module.
I will share this issue with the community if anyone wants to upvote it. |
The only issue is that my projects use GraphQL, so |
@debragail thanks for your input! We just published our open roadmap that proposes to address your issue in a couple ways - Cloud based development or building emulator plugins. Take a look and upvote the one that would work well for you. |
Hello All, I am trying to collect some data to know if the following pattern (defining multiple lambda functions and lambda layers using the count property, and t set the function.layers property to the corresponding layer using count.index) is commonly used pattern or not :
Also, if the following pattern (use conditional expression to set the Lambda function layers property) is commonly used
I appreciate if you can share with us form your experience with using terraform if you used any of these patterns in any of your terraform projects. |
@moelasmar Here are my 5 cents into this.
"commonly used pattern" is a rather tricky thing to ask because if it is valid syntax, there are users who write it like this, and any tool/solution should support it. |
Hello! How can you help? As you can see, this is a preview of just the Lambda function testing, and we want to build on this based on your feedback and feature requests. You can give us feedback by-
Thanks in advance! |
Is there an example somewhere of using this support with terraform-aws-modules project? I checked the docs there, and the examples directory, and also the aws-samples repo, but didn't see anything... |
Hello @lorengordon .. please check this example https://github.com/aws-samples/aws-sam-terraform-examples/tree/main/serverless_tf_sample/api-lambda-dynamodb-example |
@moelasmar Thanks! |
I'm seeing "Error: Import error - HookFunctionality module "samcli.hook_packages.terraform.main"" when attempting to build against both the example function in the blog post or my own functions. AWS CLI version: aws-cli/2.9.0 Python/3.9.11 Linux/5.15.74.2-microsoft-standard-WSL2 exe/x86_64.ubuntu.22 prompt/off SAM CLI output: 2022-11-18 14:37:52,786 | Running Prepare Hook to prepare the current application |
@tam116 .. could you please let us know how did you install SAM CLI, and what is your OS? |
I am having the same issue of:
I am running in a container from Ubuntu 22.04 and installed sam cli via
|
OS is Ubuntu 22.04 running under WSL2 SAM install was done using the Linux instructions here: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/install-sam-cli.html#install-sam-cli-instructions |
@tam116, @philipws .. This issue is fixed in this sam nightly release. As a workaround for now, please follow these instructions to install the sam nightly version. We will update this issue once we release this fix. |
@moelasmar The nightly build is working for me |
Thanks @tam116 for raising these requests. I replied to them and suggested some workarounds that you can try for now till we prioritized them and add a native SAM CLI support for them. |
Just an update to this thread, for people who are working on Linux, SAM CLI v1.66.0 should fix the problem of not able to run terraform support feature. Please give it a try and let us know your feedback about the feature. Thanks. |
Current support for |
I prefer to use terraform-aws-lambda module module to provision my lambda and related infra ressouces, and only use SAM to deploy the application. This seems impossible with the current way sam works because it needs to use my previously created lambda but instead wants to create a new one. |
Thanks for the feedback. I created a discussion thread to better capture the beta feedbacks at the mean time. Please feel free to discussion in the new discussion thread :) Happy testing! |
Closing as this was moved to Discussion (see above comment). |
|
We release the Terraform support in |
Terraform support in SAM CLI tool is GA now (announcement) in release 1.97.0. |
Terraform Support
Recently we added native support for CDK applications in the SAM CLI - you can see our launch announcement blog post and download the beta version of the CLI.
We would like to collect the community’s feedback on whether we should add native support for Terraform in the SAM CLI. Terraform users would be able to use the SAM CLI’s
build
,package
,local invoke
, andstart-api
commands. Thebuild
andpackage
commands make it easy to create deployment packages or OCI images that are ready to be used in AWS Lambda. Thelocal invoke
andstart-api
commands makes it easy to emulate AWS Lambda and API Gateway in local Docker container for testing purposes.With this change, the SAM CLI would parse HCL definitions to understand functions and APIs that can be locally tested and built. The SAM CLI would not write HCL, translate to, or force the use of CloudFormation. Deployments should still be performed using the Terraform toolkit.
What feedback are we looking for?
build
,package
, andlocal invoke
commands rely on theCodeUri
property of a function resource pointing to a local path where the source code for the Lambda function is stored. The SAM CLI automatically pulls dependencies, compiles if necessary, and prepares a deployment package for AWS Lambda. The package command today produces an output template that contains the S3 URL for the deployment package the SAM CLI prepared. How would you like this work with Terraform?The text was updated successfully, but these errors were encountered: