svg
Post Image
By Daniel Tanque20 de Novembro, 2023In Sem categoria

Terraform: Commands

Terraform commands are used to interact with Terraform, an open-source Infrastructure as Code (IaC) tool. These commands allow users to initialize, plan, apply, and manage infrastructure using Terraform configurations.

In this article you will learn some of the main ones.

  1. terraform init:
    • Initializes a new or existing Terraform configuration by downloading the necessary provider plugins and setting up the backend.

    terraform init
  2. terraform plan:
    • Generates an execution plan describing the changes Terraform will make to reach the desired state, without actually making any changes.

    codeterraform plan
  3. terraform apply:
    • Applies the changes described in the Terraform execution plan, making the necessary updates to the infrastructure.

    terraform apply
  4. terraform destroy:
    • Destroys all resources managed by Terraform, effectively tearing down the entire infrastructure.

    terraform destroy
  5. terraform validate:
    • Validates the syntax and structure of the Terraform configuration files.

    terraform validate
  6. terraform fmt:
    • Rewrites Terraform configuration files to a canonical format, making the code consistent.

    terraform fmt
  7. terraform get:
    • Downloads and installs modules defined in the Terraform configuration.

    terraform get
  8. terraform refresh:
    • Updates the state file to match the real-world resources. This command is useful when changes are made outside of Terraform.

    terraform refresh
  9. terraform show:
    • Displays the current state or a saved execution plan in a human-readable format.

    terraform show
  10. terraform state:
    • Performs operations on the Terraform state, such as listing resources, moving resources, and removing resources.

terraform state list

  1. terraform import:
    • Imports existing infrastructure into Terraform. This allows Terraform to manage resources that were created outside of Terraform.

terraform import aws_instance.example i-0123456789abcdef0

  1. terraform output:
    • Displays the values of output variables defined in the Terraform configuration.

terraform output

13. terraform graph:

Is used to generate a visual representation of the dependency graph for your Terraform infrastructure. This graph illustrates the relationships between different resources in your configuration, helping you understand the order in which Terraform plans to create, update, or delete resources during an apply.

You can install graphviz and run the following command to get an image of the dependency graph:

terraform graph | dot -Tsvg > graph.svg

These are just a few examples of the many Terraform commands available. Each command serves a specific purpose in the Terraform workflow, helping users manage and manipulate infrastructure as code in a reliable and efficient manner.

svgTerraform: Variables
svg
svgTerraform: Lifecycle

Leave a reply