2 Life cycle of a Terraform resource

 

This chapter covers

  • Generating and applying execution plans
  • Analyzing when Terraform triggers function hooks
  • Using the Local provider to create and manage files
  • Simulating, detecting, and correcting for configuration drift
  • Understanding the basics of Terraform state management

When you do away with all the bells and whistles, Terraform is a surprisingly simple technology. Fundamentally, Terraform is a state management tool that performs CRUD operations (create, read, update, delete) on managed resources. Often, managed resources are cloud-based resources, but they don’t have to be. Anything that can be represented as CRUD can be managed as a Terraform resource.

In this chapter, we deep-dive into the internals of Terraform by walking through the life cycle of a single resource. We can use any resource for this task, so let’s use a resource that doesn’t call any remote network APIs. These special resources are called local-only resources and exist within the confines of Terraform or the machine running Terraform. Local-only resources typically serve marginal purposes, such as to glue “real” infrastructure together, but they also make a great teaching aid. Examples of local-only resources include resources for creating private keys, self-signed TLS certificates, and random ids.

2.1 Process overview

 
 
 

2.1.1 Life cycle function hooks

 
 
 
 

2.2 Declaring a local file resource

 
 
 
 

2.3 Initializing the workspace

 
 

2.4 Generating an execution plan

 
 
 
 

2.4.1 Inspecting the plan

 

2.5 Creating the local file resource

 
 

2.6 Performing No-Op

 
 

2.7 Updating the local file resource

 
 
 
 

2.7.1 Detecting configuration drift

 

2.7.2 Terraform refresh

 
 
 
 

2.8 Deleting the local file resource

 
 
 

2.9 Fireside chat

 
 
 
 

Summary

 
 
 
sitemap

Unable to load book!

The book could not be loaded.

(try again in a couple of minutes)

manning.com homepage
test yourself with a liveTest