chapter two

2 Lifecycle of a Terraform Resource

 

This chapter covers:

  • Utilizing the local provider to create and manage a file resource
  • Generating execution plans and applying them
  • Observing lifecycle events of a managed resource in Terraform
  • Updating resources and detecting configuration drift
  • Basics of state file management

This chapter is focused on the steps that Terraform takes to create and manage resources on your behalf. Specifically, we’ll be examining the lifecycle function hooks that Terraform invokes when certain actions or sequences of actions occur. Terraform is fundamentally a glorified state management tool, so having an intuitive understanding of how state is being stored and how Terraform makes decisions based on the current vs. desired state is absolutely essential. If you can grasp this, then you have a solid foundation going forward for more advanced topics.

2.1   Process Overview

2.2   Declaring a Local File Resource

2.3   Initializing the Workspace

2.4   Generating an Execution Plan

2.5   Creating the Local File Resource

2.6   Updating the Local File Resource

2.6.1   Detecting Configuration Drift

2.7   Deleting the Local File Resource

2.8   Summary