DEV Community

loading...

Discussion on: šŸ‘· How to make conditionnal resources in terraform?

Collapse
orcalock profile image
Warlock Orca • Edited

You can do something like:

resource "aws_lambda_function" "my_lambda" {
  filename = "lambda.jar"
  function_name = "${local.my_function_name}"
  handler = "${var.lambda_type == "java" ? "Handler" : "index.handler"}"
  runtime = "${var.lambda_type == "java" ? "java8" : "nodejs10.x"}"
}

and no need to create 2 resources, and data to refer the one that got created.

Collapse
tbetous profile image
Thomas Betous Author • Edited

I havn't tested your suggestion but it seems to be a great solution ! I'll definitvly test that next time !

Thanks for your comment.