Today we are going to be looking at dynamic expressions, these are expressions where the result returned is dynamic and can be changed by other factors within the environment or inputs.
Let’s have a look at a simple example, we will use a conditional expression to determine if one or two instances of a resource should be used.
In our examples we will be using the scratch provider to demonstrate the concepts.
Let's look at another example, where we have the following local block:
We will use the above to further dynamically influence Terraforms decision on when resources should or should not be created, let's see that in action!
Dynamic expressions allow us to have our Terraform code make some decisions for us, instead of defining a static number of instances of a particular resource we can turn them on or off using conditional expressions, we can merge together the results without concerning ourselves to how many instances of a thing exists.