Terraform Most Important useful commands

Terraform Most Important useful commands

Table of contents

No heading

No headings in the article.

πŸ‘‰πŸΌ Terraform is an open-source Infrastructure as Code (IaC) tool developed by HashiCorp.

πŸ‘‰πŸΌIt allows users to define and provision infrastructure using a declarative configuration language.

πŸ‘‰πŸΌπ‡πžπ«πž 𝐚𝐫𝐞 𝐬𝐨𝐦𝐞 𝐀𝐞𝐲 π“πžπ«π«πšπŸπ¨π«π¦ 𝐜𝐨𝐦𝐦𝐚𝐧𝐝𝐬 𝐚𝐧𝐝 𝐚 π›π«π’πžπŸ 𝐞𝐱𝐩π₯𝐚𝐧𝐚𝐭𝐒𝐨𝐧 𝐨𝐟 𝐞𝐚𝐜𝐑:

1. 𝐭𝐞𝐫𝐫𝐚𝐟𝐨𝐫𝐦 𝐒𝐧𝐒𝐭:

- Initializes a working directory containing Terraform configuration files. This command downloads the required provider plugins and sets up the backend.

2. 𝐭𝐞𝐫𝐫𝐚𝐟𝐨𝐫𝐦 𝐩π₯𝐚𝐧:

  • Generates an execution plan describing what Terraform will do to reach the desired state specified in the configuration files. It shows the changes to be made before actually applying them.

3. 𝐭𝐞𝐫𝐫𝐚𝐟𝐨𝐫𝐦 𝐚𝐩𝐩π₯𝐲:

  • Applies the changes required to reach the desired state of the configuration. It creates, modifies, or deletes infrastructure resources as needed.
  1. 𝐭𝐞𝐫𝐫𝐚𝐟𝐨𝐫𝐦 𝐝𝐞𝐬𝐭𝐫𝐨𝐲:

    • Destroys the infrastructure defined in the Terraform configuration. It's important to review the plan before confirming the destruction, as this operation is irreversible.

5. 𝐭𝐞𝐫𝐫𝐚𝐟𝐨𝐫𝐦 𝐯𝐚π₯𝐒𝐝𝐚𝐭𝐞:

  • Checks and validates the configuration files for syntax errors and other issues. It ensures that the Terraform files are correctly formatted.

6. 𝐭𝐞𝐫𝐫𝐚𝐟𝐨𝐫𝐦 𝐟𝐦𝐭:

  • Rewrites Terraform configuration files to a canonical format. It helps maintain a consistent style across your configuration files.

7. 𝐭𝐞𝐫𝐫𝐚𝐟𝐨𝐫𝐦 𝐬𝐑𝐨𝐰:

-: Outputs the current state or a saved plan. It provides a human-readable representation of the state of your infrastructure.

8. 𝐭𝐞𝐫𝐫𝐚𝐟𝐨𝐫𝐦 𝐬𝐭𝐚𝐭𝐞:

  • Performs operations on Terraform state files. This includes listing resources in the state, removing a resource from the state, and more.

9. 𝐭𝐞𝐫𝐫𝐚𝐟𝐨𝐫𝐦 𝐒𝐦𝐩𝐨𝐫𝐭:

  • Imports existing infrastructure into Terraform. It associates a resource in your Terraform configuration with an existing resource in your infrastructure.

10. 𝐭𝐞𝐫𝐫𝐚𝐟𝐨𝐫𝐦 𝐰𝐨𝐫𝐀𝐬𝐩𝐚𝐜𝐞:

  • Manages workspaces. Workspaces allow you to manage multiple instances of your infrastructure configurations, such as development and production environments.

    1. 𝐭𝐞𝐫𝐫𝐚𝐟𝐨𝐫𝐦 output:
  • Reads an output variable from a Terraform state file. It's used to inspect the values of variables or expressions defined in the configuration.

Terraform is widely used for provisioning and managing infrastructure across various cloud providers and on-premises environments.

#devops #terraform #learning #commands

Β