5 Key Terms You Need to Know in Terraform

Below are the five key terms that you need to know. These are Declare, Init, Plan, apply, and destroy.

Declare

The first step is declaring the resources. You can do this in any directory where no other details should be present. It is not a command. It is just an initial step to declaring resources.

Init

  • terraform isn’t aware of your workspace, let alone that it’s supposed to create or manage anything, because it hasn’t been initialized.
  • Terraform configuration must always be initialized at least once, but you may have to initialize again if you add new providers or modules.
  • Don’t fret about when to run terraform init, because Terraform will always remind you. Moreover, terraform init is an idempotent command, which means you can call it as many times as you want in a row with no side effects.
$ terraform init 

After initialization, Terraform creates a hidden .terraform directory for installing plugins and modules. 

Plan

  • Terraform intends to do this by running terraform plan. You should always run terraform plan before deploying.
  • terraform plan informs you about what Terraform intends to do and acts as a linter, letting you know about any syntax or dependency errors.
  • It’s a read-only action that does not alter the state of deployed infrastructure, and like terraform init, it’s idempotent.

Apply

The apply command compares the output against the generated execution plan.

Destroy

In the terraform destroy, first generates an execution plan as if there were no resources in the configuration files by performing a Read() on each resource and marking all existing resources for deletion.

$ terraform destroy -auto-approve

The optional flag -auto-approve for terraform destroy, which is exactly the same as for; it automatically approves the result of the execution plan.

References

Related posts

Author: Srini

Experienced software developer. Skills in Development, Coding, Testing and Debugging. Good Data analytic skills (Data Warehousing and BI). Also skills in Mainframe.