chapter ten

10 Advanced Terraform Topics

 

This chapter covers

  • DNS and Resource Naming Strategies
  • Network creation with dynamic subnetting
  • Using Provisioners to break out of Terraform
  • The Local and External Providers
  • Validation with Checks and Conditions
  • When not to use Terraform (and what to do instead)

The first two parts of the book covered the Terraform language itself and how to use Terraform in production. This knowledge should be more than enough to get you through most of the problems that you’re going to encounter. That being said, there are topics you may encounter that require some additional tools to work through.

This chapter is going to be a bit different than previous ones. Rather than dive into a single topic we are going to explore a variety of useful patterns, niche providers, and advanced features of Terraform. Some of what we discuss, such as how to name your resources or the use of conditions and checks, may end up being tools that you use every day. Other parts of this chapter, such as the use of the external provider, will offer you tools that you likely won’t use every day but will be grateful to have when you encounter a particularly thorny problem.

10.1 Names and Domains

10.1.1 Naming Considerations

10.1.2 Hierarchical Naming Schemes

10.1.3 Domains

10.2 Network Management

10.2.1 Subnetting with CIDR

10.2.2 Common Topologies

10.2.3 Location Module

10.2.4 High Level Module

10.3 Provisioners

10.3.1 Connections

10.3.2 Command Provisioners

10.3.3 File Provisioners

10.3.4 Provisioner Control

10.3.5 terraform_data

10.3.6 Alternatives to using provisioners

10.4 External Provider

10.4.1 External Datasource

10.4.2 Wrapper Program Languages

10.4.3 Writing Wrapper Programs

10.4.4 Alternatives to external providers

10.5 Local Provider

10.5.1 Functions

10.5.2 Data Sources

10.5.3 Resources

10.6 Checks and Conditions

10.6.1 Preconditions and Postconditions

10.6.2 Checks

10.7 OpenTofu and Terraform Compatibility

10.7.1 Tofu Files

10.8 When Terraform isn’t Appropriate

10.8.1 Kubernetes

10.8.2 Container Image Building

10.8.3 Machine Image Building

10.8.4 Artifact Management

10.9 Summary