Terraform — Declarative Infrastructure Provisioning

qomarullah
1 min readNov 25, 2021

Terraform is an infrastructure provisioning tool by hashicorp. Terraform use declarative approach means your infrastructure is same as declare in your terraform code. Based on your terraform code any changes to code will reflect how changes in infrastructure happen. infrasturcture can add, modify, or destroy. If you remove object name from your code it will destroy related infrastructure. This picture show how declarative in more detail :

  • Object A is existing object created manually and will not impacted by terraform execution. If you need to include object A to your code you need command terraform import with unique ID/name in code.
  • Object B, C, D, E create from code terraform and have unique ID based on id/name

Actual code is the goal state of object in your infra/providers’s target. When you execute the code it will compare to previous state and make decision :

  1. If existing state object doesn’t exist, execution will add this object
  2. If existing state have same ID and same config parameter, execution will no change
  3. If existing state have same ID and different config parameter, execution will modify the object
  4. If existing state object not exist in goal state (code), execution will destroy this object

--

--