· Tutorials  · 3 min read

Managing Similar Resources in Terraform

Reduce the noise in your modules.

One of the best parts of Terraform is the ability to integrate with other parts of your infrastructure. Creating lambda functions and API endpoints can be tedious though. Manging multiple configurations, even worse.

Imagine building this API with Lambda and API Gateway. We’re going to define each Endpoint with its own Lambda so we reduce the risk of impacting other endpoints if one is bad.

Zoomable

It also allows us to scale out lambdas independently based on the endpoints usage (run time and resoruces).

We’re going to use for_each meta-argument to loop over a map defined in a local variable called “api_lambda_functions.”

You generally don’t want to define each lambda individually and end up with something that looks like this:

You might notice that not all objects in the map have the memory_size key. This is where the neat stuff happens. Using the try function, we can set default values for keys. This allows us to significantly trim the maps in our local variables.

Back to Blog

Related Posts

View All Posts »