Terraform 0.12 aws_lambda_permission resource replaced every apply


I’m dynamically creating the following resource in a Terraform v0.12 module:



The inputs don’t change. But every apply I receive the following notification:


When using the aws_lambda_permission resource your function name should be the unqualified Lambda function name. If you need to specify an alias to version your Lambda then this should be done by using the qualifier parameter instead.

Right now Terraform is trying to set the function name to include the qualifier and setting the qualifier to nil. The AWS API happily accepts this and does what you want it to do but then when Terraform refreshes and updates its state it see that the function name has had the qualifier stripped and the qualifier parameter has been set so it attempts to force things back into the way the code tells it should be. Unfortunately this is also an operation that doesn’t support an upgrade in place on the Lambda permission resource so it also needs to delete the existing Lambda permission and recreate.

Stripping the qualifier from the function name and adding it in the proper qualifier parameter should fix this:

In the above example I also replaced your element functions with a straight list index with square bracket notation instead. element is useful if you need to loop back through a list multiple times without doing the modulo in the index but otherwise the square bracket notation tends to be slightly more readable and has the same behaviour.

As you mentioned that you’re on Terraform 0.12 you can also move to the newer syntax when you aren’t concatenating strings and variables as well:

Leave a Reply