10 Advanced Terraform topics

This chapter covers

  • Domain Name System and resource naming strategies
  • Network creation with dynamic subnetting
  • Using provisioners to break out of Terraform
  • 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 a bit different from previous ones. Rather than dive into a single topic, we 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 you 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 Classless Inter-Domain Routing

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