When you start writing Terraform configuration, you will notice very quickly that the language provided by Terraform is very rich and allows for a lot of manipulation.
In the recipes in this chapter, you will learn how to use the Terraform language effectively in order to apply it to real-life business scenarios. We will discuss how to specify the versions of the provider to be used, as well as how to make the code more dynamic with variables and outputs. Then, we will use these concepts to provision several environments with Terraform. After that, we will consider the use of functions and conditions.
We will also learn how to retrieve data from external systems with data blocks, other Terraform state files, and external resources. Finally, we will cover the use of Terraform for local operations, such as running a local executable and manipulating local files.
In this chapter, we will cover the following recipes:
- Configuring Terraform and the provider version to use
- Manipulating variables
- Using local variables for custom functions
- Using outputs to expose Terraform provisioned data
- Provisioning infrastructure in multiple environments
- Obtaining external data with data sources
- Using external resources from other state files
- Querying external data with Terraform
- Calling Terraform built-in functions
- Writing conditional expressions
- Manipulating local files with Terraform
- Executing local programs with Terraform
- Generating passwords with Terraform
Let's get started!