I have two resources to invoke lambdas, here I want to create a variable dependencies and null_resource so I can use something like this below which mean the resource 1 invocation has been done before invoke 2
resource “aws_lambda_invocation” “invoke2” {
dependencies =
}
How can this be done?
Hi @anon91627031,
I’m not quite sure what you mean by “variable dependencies” or where a null_resource would fit in here, but if aws_lambda_invocation.invoke2
references aws_lambda_invocation.invoke1
in any way, then the latter must be applied before the former. If there is no natural attributes which you would use to reference the the resource, you can use:
depends_on = [aws_lambda_invocation.invoke1]
I’m very new to terraform, something like this : variable “dependencies” {}
I wanted to avoid the depends_on because it recreates the resource everytime after readind this : Beware of depends_on for Terraform modules. It might bite you! | by Daniel Jimenez Garcia | ITNEXT
You’re not using depends_on with a module here, you would be using it on specific managed resources so the linked blog post is not relevant. You need to describe what you expect variable “dependencies” {}
to do. Dependencies in Terraform are statically defined by the references in the configuration.
Yes, you’re correct. I tried to put dependencies on resource but I see with module its totally fine. Thanks for your help! Quickest response ever 
Need more help here please, I am experiencing another issue related to dependencies now : Error: Cycle module1.null_resource.dependency, module2.null_resource.dependency, time_sleep.wait
I have this scenario :
module “module1” {}
module “module2” {
dependencies = [aws_lambda_invocation.invoke1.result]
}
resource “time_sleep” “wait” {
duration = “5s”
triggers = {
arn = module.module1.arn
}}
resource “aws_lambda_invocation” “invoke1” {
depends_on = [time_sleep.wait]
}
resource “aws_lambda_invocation” “invoke2” {
depends_on = [aws_lambda_invocation.invoke1, module.module2]
}
I also have :
resource “aws_lambda_function” “this” {
depends_on = [
#(resource)
null_resource.dependency
]}
This is basically telling you that module1
depends on module2
that depends on time_sleep
that in turn depends on module1
, causing cyclical dependency.
That doesn’t necessarily mean that a meta-argument depends_on
is declared within the modules. It just means that an output of one of these modules is being used as an input of the other (or similarly as an argument value of a resource).
I personally feel this code is close to unreadable and there are way too many explicit dependencies for which I believe a different solution must exist.
Trying to use Terraform and hcl as a procedural language is in my opinion a recipe for disaster.
I and my team thought of multiple solution but our requirement was edge case and this case was preferred.
Thanks for your comment!