Skip to content

Latest commit

 

History

History
90 lines (77 loc) · 9.01 KB

resource-lifecycle-methods.md

File metadata and controls

90 lines (77 loc) · 9.01 KB

Resource Lifecycle Methods

An overview of a resource's lifecycle methods called for the "terraform refresh" and "terraform apply" actions


The Create, Read & Delete Methods

resource   terraform refresh terraform apply
  - not in infrastructure      
    -- not in terraform state      
      --- not in terraform config - --- ---
      --- in terraform config 1 --- Create, Read
    -- in terraform state      
      --- not in terraform config 2 Read (clear state)  
      --- in terraform config 3 Read (clear state) Create, Read
  - in infrastructure      
    -- not in terraform state      
      --- not in terraform config - --- ---
      --- in terraform config 4 --- Create (error)
    -- in terraform state      
      --- not in terraform config 5 Read (refresh state) Delete
      --- in terraform config      
        > config same as state 6 Read (refresh state) ---
          >> changed computed fields 7 Read (refresh state) ---
        > config different from state      
          >> changed force-new fields 8 Read (refresh state) Delete, Create, Read
          >> changed common fields - n.a. n.a.

ℹ️
ForceNew: true, must be set for all fields in the schema, except the Computed fields


Adding The Update Method

💡
terraform-provider-hosts DOES support the Update method

resource   terraform refresh terraform apply
  - not in infrastructure      
    -- not in terraform state      
      --- not in terraform config - --- ---
      --- in terraform config 1 --- Create, Read
    -- in terraform state      
      --- not in terraform config 2 Read (clear state)  
      --- in terraform config 3 Read (clear state) Create, Read
  - in infrastructure      
    -- not in terraform state      
      --- not in terraform config - --- ---
      --- in terraform config 4 --- Create (error)
    -- in terraform state      
      --- not in terraform config 5 Read (refresh state) Delete
      --- in terraform config      
        > config same as state 6 Read (refresh state) ---
          >> changed computed fields 7 Read (refresh state) ---
        > config different from state      
          >> changed force-new fields 8 Read (refresh state) Delete, Create, Read
          >> changed common fields 9 Read (refresh state) Update, Read

Adding The Exists Method

💡
terraform-provider-hosts DOES NOT supports the Exists method

resource   terraform refresh terraform apply
  - not in infrastructure      
    -- not in terraform state      
      --- not in terraform config - --- ---
      --- in terraform config 1 --- Create, Read
    -- in terraform state      
      --- not in terraform config 2 Exists (clear state)  
      --- in terraform config 3 Exists (clear state) Create, Read
  - in infrastructure      
    -- not in terraform state      
      --- not in terraform config - --- ---
      --- in terraform config 4 --- Create (error)
    -- in terraform state      
      --- not in terraform config 5 Exists, Read (refresh state) Delete
      --- in terraform config      
        > config same as state 6 Exists, Read (refresh state) ---
          >> changed computed fields 7 Exists, Read (refresh state) ---
        > config different from state      
          >> changed force-new fields 8 Exists, Read (refresh state) Delete, Create, Read
          >> changed common fields 9 Exists, Read (refresh state) Update, Read