Skip to main content

Command Palette

Search for a command to run...

Terraform Cheat Cheet

Terraform is a popular infrastructure as code (IaC) tool used for building, changing, and versioning infrastructure efficiently. Here's a cheat sheet

Updated
โ€ข2 min read
Terraform Cheat Cheet
M

Hello, I'm Mamoona Arshad, a highly motivated and skilled professional with a Master's degree in Information Technology, with research areas of Machine Learning, Computer Networking, Computer Vision, and deep learning. My research areas have provided me with a solid foundation in cutting-edge technologies and a deep understanding of their applications. My academic journey has sparked a passion for working at the intersection of cloud engineering and DevOps. I am deeply fascinated by the seamless integration of cloud technologies and the efficient deployment of software through DevOps practices. I have been actively learning and gaining hands-on experience in both areas to enhance my skills and contribute to organizations' digital transformation. I possess excellent problem-solving skills, a keen eye for detail, and a strong ability to adapt to new technologies and methodologies. My dedication to continuous learning and my passion for DevOps make me a valuable asset to any organization seeking to streamline their software development processes and improve collaboration between development and operations teams. If you are looking for a dedicated and motivated professional who can contribute to your cloud engineering and DevOps initiatives, I would love to discuss opportunities further. Let's connect and explore how my skills and experience align with your organization's goals. Feel free to reach me at out.

Initializing Terraform

  • Initialize a Terraform working directory:

      terraform init
    

    This command initializes a working directory containing Terraform configuration files.

Building Infrastructure

  • Create or update infrastructure:

      terraform apply
    

    This command creates or updates the infrastructure according to the configuration files.

Inspecting State

  • Show the current state:

      terraform show
    

    Displays the current state of the infrastructure.

  • Output the current state in a more human-readable format:

      terraform output
    

    Shows the values of outputs from the current state.

Planning Changes

  • Preview changes before applying:

      terraform plan
    

    This command shows the changes that will be made to the infrastructure.

Destroying Infrastructure

  • Destroy the infrastructure:

      terraform destroy
    

    Destroys the Terraform-managed infrastructure.

Managing Workspaces

  • List available workspaces:

      terraform workspace list
    

    Lists all available workspaces.

  • Create a new workspace:

      terraform workspace new <workspace_name>
    

    Creates a new workspace.

  • Switch to a different workspace:

      terraform workspace select <workspace_name>
    

    Switches to the specified workspace.

Miscellaneous

  • Validate the configuration files:

      terraform validate
    

    Checks the syntax and configuration of Terraform files.

  • Output the execution plan as JSON:

      terraform show -json
    

    Displays the execution plan in JSON format.

    Force unlock the state:

      terraform force-unlock <lock_id>
    

    Manually unlock the Terraform state.

More from this blog

Untitled Publication

14 posts