3 Functional Programming and Advanced Templating Techniques
This chapter covers:
- Functional programming with declarative functions and expressions
- Templating patterns and techniques with local only resources
- Parameterizing configuration files with input variables
- Mix and matching multiple providers in a single project
- Creating dynamic Terraform configurations with count
In this chapter, we’ll be building an engine for generating Mad Libs from template files. Mad Libs, in case you don’t know, is a phrasal templating word game in which one player prompts another for words to fill in the blanks of a story, before reading the story aloud. If you’ve ever played Apples to Apples or Cards against Humanity, it’s a lot like that except with a whole story rather than a single sentence or two. What makes these kinds of games fun is the juxtaposition that exists between an otherwise normal story, and the odd words chosen to fill in the blanks. An example input for a Mad Libs is shown below. Given this input, it should ask for a noun, an adjective, and another noun, then replace the blanks with these values.
To make a pizza, you need to take a lump of <noun>, and make a thin, round <adjective> <noun>.