Terraform CLI: fmt, taint & import

Terraform fmt (format)

  • Format Terraform code for readability.

  • Helps in keeping code consistent.

  • Safe to run at any time

  • Command Syntax: "terraform fmt"

Scenario:

  • Before pushing your code to version control

  • After upgrading Terraform or its modules

  • Any time you've made changes to the code

Terraform Taint

  • Taints a resource, forcing it to be destroyed or created

  • Modifies the state file, which causes the creation workflow

  • Tainting a resource may cause other resources to be modified

  • Command Syntax: "terraform taint RESOURCE_ADDRESS"

Scenario:

  • To cause provisioners to run

  • Replace misbehaving resources forcefully

  • To mimic the side effects of recreation not modeled by any attributes of the resource.

Terraform import

  • Map existing resources to Terraform using an "ID"

  • "ID" is dependent on the underlying vendor, for example, to import an AWS EC2 instance you'll need to provide it with instance ID

  • Importing the same resource to multiple Terraform resources can cause unknown behavior and is not recommended

  • Command Syntax: "terraform import RESOURCE_ADDRESS_ID"

Scenario:

  • When you need to work with existing resources

  • Not allowed to create new resources

  • When you are not in control of the creation process of infrastructure.

Last updated