3
votes

I have a lambda which I want to invoke once during terraform apply since it updates a database and should be triggered only once in the apply phase.
My problem is that terraform invokes it during the plan phase as well.
Is there a way to run it only during the apply phase?
Example:

data "aws_lambda_invocation" "run_lambda" {
  function_name = "test"

  input = <<JSON
  {}
  JSON
}
1
Interesting problem. I suspect you cannot restrict this particular resource from invoking the lambda upon plan - it is set up as a data source, so Terraform will "read" it during the plan phase. Since you are writing data with this lambda, you will need something else. Here's a module that I've never used but could be worth trying: registry.terraform.io/modules/crisboarna/lambda-invoke/aws/… - lxop

1 Answers

-1
votes

late for requester but answer for future reference: Try using depends_on: [some_resource] construct in aws_lamdbda_invocation. let the invocation depend on any other resource. If no dependency (which I hardly believe), introduce artificial one, like time_sleep. Let execution waits for 1s and make lambda dependant on it. This way terraform plan would not complain.