Use Terraform to create lambda function and serverless to deploy code

Hi all

We are currently using Terraform to create aws resources together with the serverless framework to deploy our lambda functions that interact with these services.

We currently define our lambda functions inside the serverless.yml file but we want to find a way to be able to use these lambda functions inside Terraform to link them to certain resources/services.

During our deployment process we run a terraform plan, terraform apply and a serverless deploy. This introduces the problem that our lambda functions are created after we want to reference them in terraform.

We are now thinking about moving the declaration of the lambda functions to Terraform, use them elsewhere in terraform to link them to certain resources and then deploying the code using the serverless framework.

Is this a common approach? Is there a better way to handle these kinds of situations?

Thanks in advance.

I handle the definition of my AWS Lambdas in terraform, but handle the code updates in our CI/CD pipeline without using terraform. If you want to still define your Lambdas in your current fashion, you can reference your current Lambda function as a data source which you can then reference from other terraform resources.