Terraspace Documentation

repository·master·Indexed 20 days ago

https://github.com/boltops-tools/terraspace

A Terraform framework designed for DRY, scalable infrastructure management. Terraspace provides a CLI for multi-stack deployment with dependency awareness, environment layering, and module management via a Ruby-based Terrafile. It supports major cloud providers including AWS, Azure (azurerm), and GCP (google), and includes features for generating dependency graphs, managing state, and configuring global settings through the Terraspace::App class.

Tokens
28.7K
Snippets
152
Records
172
Agent score
71%

What's inside Terraspace

  1. Configure log timestamp visibility

    master

    Timestamps behave differently depending on the scope of your log request:

    • Multiple files: Timestamps are shown by default (e.g., when viewing all up logs across multiple stacks).
    • Single file: Timestamps are not shown by default when you specify both an action and a specific stack (e.g., terraspace logs up network).

    To explicitly show timestamps for a single stack log, use the --timestamps flag.

    terraspace logs up network --timestamps
  2. Import existing resources using terraspace import

    master

    Use the terraspace import command to bring existing cloud resources into your Terraform state. The command requires the stack name, the resource address (as defined in your Terraform code), and the actual resource ID from your cloud provider.

    General Workflow:

    1. Run terraspace plan <stack> to identify resources that are missing from your state but exist in your configuration.
    2. Use terraspace import <stack> <resource_address> <resource_id> to import the specific resource.
    3. Run terraspace plan <stack> again to verify that the resource is now correctly managed and no longer shows as 'to be created'.
    4. Use terraspace state list <stack> to inspect your current state.
    # Import an EC2 instance
    terraspace import ec2 aws_instance.this i-088a0a47e2e852cc8
    
    # Import a VPC module resource
    terraspace import vpc module.vpc.aws_vpc.this vpc-000782e4951a734c7
    
    # Import a resource with an index (e.g., an element in a list)
    terraspace import vpc module.vpc.aws_internet_gateway.this[0] igw-0fa4bec3b4b46948a
  3. Deploy and Destroy Infrastructure Stacks

    master

    Terraspace provides simple commands to manage the lifecycle of your infrastructure stacks.

    • terraspace up <stack_name>: Builds the stack in a cache directory and runs terraform init and terraform apply.
    • terraspace down <stack_name>: Builds the stack in a cache directory and runs terraform destroy to clean up resources.
    # Deploy a specific stack
    terraspace up demo
    
    # Destroy a specific stack
    terraspace down demo
  4. Deploy multiple stacks in parallel with `terraspace all up`

    master

    The terraspace all up command orchestrates the deployment of multiple stacks by grouping them into batches. Terraspace executes these batches in parallel to optimize deployment time. Before execution, Terraspace displays a list of the commands it will run and asks for confirmation.

    After deployment, Terraspace provides a summary of the runs and the total time taken. Detailed logs for each stack are written to the log/up/<stack_name>.log directory for debugging. You can use the terraspace log command to view these logs.

    $ terraspace all up
    # Terraspace will list batches and ask: Are you sure? (y/N)
    
    # Example output:
    # Batch Run 1:
    # Running: terraspace up c1 Logs: log/up/c1.log
    # terraspace up c1:  Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
  5. Enable TAB auto-completion for the Terraspace CLI

    master

    To enable TAB auto-completion for Terraspace commands and arguments in your shell, add the following command to your shell profile (e.g., .bashrc, .zshrc, or .bash_profile):

    eval $(terraspace completion_script)

    Once enabled, you can use the [TAB] key to autocomplete commands like terraspace up [TAB], stack names terraspace up name [TAB], or flags terraspace up name --[TAB].

  6. Generate a Terraspace shim

    master

    Use the terraspace new shim command to generate a Terraspace shim. This shim is typically installed at /usr/local/bin/terraspace.

    After generation, ensure that /usr/local/bin is included in your system $PATH so the terraspace command can be executed from any terminal session. You can verify the installation by running which terraspace.

    $ terraspace new shim
  7. Create a new Terraspace plugin

    master

    Use the terraspace new plugin command to scaffold a new Terraspace plugin. This command generates a complete directory structure including Ruby templates, HCL templates, RSpec test suites, and necessary configuration files (like .gemspec, Gemfile, and Rakefile) to allow you to build custom provider logic for Terraspace.

    The generated structure includes:

    • Templates: HCL and Ruby templates for modules, stacks, and project configurations.
    • Interfaces: Ruby files for implementing core plugin interfaces such as backend, config, expander, and layer.
    • Testing: A pre-configured RSpec testing environment with fixtures and spec helpers.
    • Boilerplate: Standard Ruby gem files and CLI entrypoints.
    $ terraspace new plugin mycloud
  8. Quick Start with Terraspace

    master

    To get started with Terraspace, you can generate a starter project using the new command, which includes examples and a specified cloud provider plugin. Once the project is created, you can use up to deploy a stack and down to destroy it.

    Supported major cloud providers include aws, azurerm (Azure), and google (GCP).

    # Generate a new project with AWS plugin and examples
    terraspace new project infra --plugin aws --examples
    
    # Navigate to the project
    cd infra
    
    # Deploy a demo stack
    terraspace up demo
    
    # Clean up and delete the demo stack
    terraspace down demo