Nisman
Nisman

Reputation: 1309

How to invoke a lambda after create/update in terraform?

I'm creating/updating a lambda function using terraform and I need to run it AFTER it is created or updated. I know there is a terraform data source aws_lambda_invocation but it runs BEFORE the lambda function created/updated. Is there any way to achieve this in terraform?

Upvotes: 1

Views: 2653

Answers (2)

Akshay Gopani
Akshay Gopani

Reputation: 491

Store your terraform state file in S3. Set trigger on state files update action. So whenever there is a change in terraform it will update statte file in S3. You can set trigger from S3 to trigger lambda. https://docs.aws.amazon.com/lambda/latest/dg/with-s3-example.html

Upvotes: 0

Marcin
Marcin

Reputation: 238061

Normally you would use depends_on for that:

data "aws_lambda_invocation" "fun" {

  # ...

  depends_on = [aws_lambda_function.fun]
}

Upvotes: 4

Related Questions