### Import Module Example as Stack Source: https://github.com/boltops-tools/terraspace/blob/master/lib/terraspace/cli/help/bundle.md Import a module's example as a stack. Replace MODULE and EXAMPLE with the actual names. ```bash terraspace bundle example MODULE EXAMPLE ``` -------------------------------- ### Deploy to Production Example Source: https://context7.com/boltops-tools/terraspace/llms.txt Example of deploying all Terraspace stacks to production environment with confirmation. ```bash TS_ENV=prod terraspace all up --yes ``` -------------------------------- ### Verify Shim Installation Source: https://github.com/boltops-tools/terraspace/blob/master/lib/terraspace/cli/help/new/shim.md After generating the shim, verify that it is accessible in your PATH using the `which` command. ```bash $ which terraspace /usr/local/bin/terraspace ``` -------------------------------- ### Terraform State Help Example Source: https://github.com/boltops-tools/terraspace/blob/master/lib/terraspace/cli/help/state.md Shows how to access the help for a specific Terraform state subcommand. This is useful for understanding available arguments. ```bash terraform state list -h ``` -------------------------------- ### Example Output of Untaint Command Source: https://github.com/boltops-tools/terraspace/blob/master/lib/terraspace/cli/help/untaint.md This shows the typical output when untainting a resource, including the build process and the confirmation of the resource being untainted. ```bash $ terraspace untaint ec2 aws_instance.my_instance Building .terraspace-cache/us-east-1/dev/stacks/ec2 Hook: Running terraspace before build hook. Current directory: .terraspace-cache/us-east-1/dev/stacks/ec2 => terraform untaint aws_instance.my_instance Resource instance aws_instance.my_instance has been successfully untainted. Releasing state lock. This may take a few moments... ``` -------------------------------- ### Check Terraspace Setup and Configuration Source: https://context7.com/boltops-tools/terraspace/llms.txt Validates that Terraform is installed and the Terraspace project is correctly configured, reporting any issues found. ```bash terraspace check ``` -------------------------------- ### Install Terrafile modules with terraspace bundle Source: https://context7.com/boltops-tools/terraspace/llms.txt Installs all modules listed in the Terrafile. Vendors modules to vendor/modules/ and creates/updates the Terrafile.lock file. ```bash # Install all modules listed in Terrafile terraspace bundle # Vendor modules are installed to vendor/modules/ # The Terrafile.lock file is created/updated ``` -------------------------------- ### Create a new Terraspace project Source: https://github.com/boltops-tools/terraspace/blob/master/README.md Use the `terraspace new` command to generate a starter project with a specified plugin and examples. Navigate into the created directory and deploy infrastructure with `terraspace up`. ```bash terraspace new project infra --plugin aws --examples cd infra terraspace up demo ``` -------------------------------- ### Generate New Terraspace Project Source: https://context7.com/boltops-tools/terraspace/llms.txt Scaffolds a new Terraspace project with essential files and example stacks for a chosen cloud provider. Ensure you run `bundle install` after project creation. ```bash terraspace new project infra --plugin aws --examples cd infra bundle install ``` ```bash terraspace new project infra --plugin azurerm --examples ``` ```bash terraspace new project infra --plugin google --lang rb --examples ``` -------------------------------- ### Terraspace Bundle Install and Update Commands Source: https://github.com/boltops-tools/terraspace/blob/master/lib/terraspace/cli/help/bundle.md Use these commands to install or update modules. 'install' is an alias for 'bundle'. 'update' refreshes the Terrafile.lock. ```bash terraspace bundle install # same as bundle ``` ```bash terraspace bundle update # Updates Terrafile.lock ``` -------------------------------- ### Example Output of Pruning TFC Runs Source: https://github.com/boltops-tools/terraspace/blob/master/lib/terraspace/cli/help/tfc/runs/prune.md This example shows the output of the `terraspace tfc runs prune demo` command, illustrating which runs are kept, which are marked for pruning, and the confirmation prompt. ```bash $ terraspace tfc runs prune demo Will keep: run-9muMrjrd22vhsP4u pending test 2020-09-18T12:47:11 Will prune: run-fYTDzmKfCQf558UN pending test 2020-09-18T12:46:34 run-6bgSTattJGpaRn9X pending test 2020-09-18T12:46:28 run-jDHEtZb3vuFnuXqJ planned test 2020-09-18T12:38:35 Are you sure? (y/N) y Cancelled run-fYTDzmKfCQf558UN test Cancelled run-6bgSTattJGpaRn9X test Discarded run-jDHEtZb3vuFnuXqJ test $ ``` -------------------------------- ### Get Module Info Source: https://github.com/boltops-tools/terraspace/blob/master/lib/terraspace/cli/help/bundle.md Retrieve information about a specific module. ```bash terraspace bundle info MODULE ``` -------------------------------- ### Deploying Multi-Instance Stacks with `--instance` Flag Source: https://context7.com/boltops-tools/terraspace/llms.txt Shows how to deploy multiple instances of the same stack in a single environment using the `--instance` flag and setting the `TS_EXTRA` environment variable for differentiation. Each instance gets its own state file and cache directory. ```bash # Deploy two instances of the "app" stack TS_EXTRA=blue terraspace up app --instance blue TS_EXTRA=green terraspace up app --instance green # Each gets its own state file and cache directory: # .terraspace-cache/us-east-1/dev/stacks/app-blue/ # .terraspace-cache/us-east-1/dev/stacks/app-green/ ``` -------------------------------- ### Basic Terraspace Plan Source: https://github.com/boltops-tools/terraspace/blob/master/lib/terraspace/cli/help/plan.md Executes a basic `terraspace plan` command for a given example. This shows the Terraform plan output without saving it to a file. ```bash $ terraspace plan demo => terraform plan Refreshing Terraform state in-memory prior to plan... The refreshed state will be used to calculate this plan, but will not be persisted to local or remote state storage. random_pet.this: Refreshing state... [id=fond-sheep] module.bucket.aws_s3_bucket.this: Refreshing state... [id=bucket-fond-sheep] ------------------------------------------------------------------------ An execution plan has been generated and is shown below. Resource actions are indicated with the following symbols: -/+ destroy and then create replacement ... Plan: 2 to add, 0 to change, 2 to destroy. Changes to Outputs: ~ bucket_name = "bucket-fond-sheep" -> (known after apply) ------------------------------------------------------------------------ Note: You didn't specify an "-out" parameter to save this plan, so Terraform can't guarantee that exactly these actions will be performed if "terraform apply" is subsequently run. $ ``` -------------------------------- ### Terraspace CLI Auto-completion Usage Examples Source: https://github.com/boltops-tools/terraspace/blob/master/lib/terraspace/cli/help/completion.md These examples show how to use TAB to trigger auto-completion at different stages of typing a Terraspace command. This helps discover available commands, subcommands, and options. ```bash terraspace [TAB] ``` ```bash terraspace up [TAB] ``` ```bash terraspace up name [TAB] ``` ```bash terraspace up name --[TAB] ``` -------------------------------- ### Example GitHub Actions Workflow for Terraspace Deploy Source: https://context7.com/boltops-tools/terraspace/llms.txt This workflow automates Terraspace deployments on push to the main branch. It requires AWS credentials to be set as secrets. Ensure Ruby and Bundler are installed and dependencies are cached. ```yaml name: Terraspace Deploy on: push: branches: [main] env: TS_ENV: prod AWS_REGION: us-east-1 jobs: deploy: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - uses: ruby/setup-ruby@v1 with: bundler-cache: true - name: Bundle Terraform modules run: bundle exec terraspace bundle - name: Plan all stacks run: bundle exec terraspace all plan --auto env: AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} - name: Deploy all stacks run: bundle exec terraspace all up --yes env: AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} ``` -------------------------------- ### Terraspace Output Command Example Source: https://github.com/boltops-tools/terraspace/blob/master/lib/terraspace/cli/help/output.md Demonstrates how to use the 'terraspace output' command to display Terraform outputs. This command is useful for inspecting the values produced by your Terraform configurations. ```bash $ terraspace output demo => terraform output bucket_name = bucket-fond-sheep ``` -------------------------------- ### Example Import Output Source: https://github.com/boltops-tools/terraspace/blob/master/lib/terraspace/cli/help/import.md This output demonstrates a successful import of an AWS Internet Gateway. It shows the Terraform command being executed within the cached directory, the import process, and confirmation of successful state refresh. ```bash $ terraspace import vpc module.vpc.aws_internet_gateway.this[0] igw-0fa4bec3b4b46948a Building .terraspace-cache/us-west-2/dev/stacks/vpc Current directory: .terraspace-cache/us-west-2/dev/stacks/vpc => terraform import module.vpc.aws_internet_gateway.this[0] igw-0fa4bec3b4b46948a module.vpc.aws_internet_gateway.this[0]: Importing from ID "igw-0fa4bec3b4b46948a"... module.vpc.aws_internet_gateway.this[0]: Import prepared! Prepared aws_internet_gateway for import module.vpc.aws_internet_gateway.this[0]: Refreshing state... [id=igw-0fa4bec3b4b46948a] Import successful! The resources that were imported are shown above. These resources are now in your Terraform state and will henceforth be managed by Terraform. ``` -------------------------------- ### Terraspace Setup Check Output Source: https://github.com/boltops-tools/terraspace/blob/master/lib/terraspace/cli/help/setup.md This output shows the result of running the `terraspace check_setup` command. It details the detected Terraspace and Terraform versions and confirms compatibility. ```bash $ terraspace check_setup Detected Terraspace version: 0.3.3 Detected Terraform bin: /home/ec2-user/.tfenv/bin/terraform Detected Terraform v0.13.2 Terraspace requires Terraform v0.12.x and above You're all set! $ ``` -------------------------------- ### Terraspace Expansion Placeholder Configuration Source: https://context7.com/boltops-tools/terraspace/llms.txt Demonstrates how to configure Terraspace build cache directories and cloud stack naming conventions using expansion placeholders. Also shows an example of using expansion in a Ruby stack file for S3 bucket naming. ```ruby # Available placeholders: # :APP → TS_APP env var # :ROLE → TS_ROLE env var # :ENV → TS_ENV (dev, staging, prod) # :EXTRA → TS_EXTRA env var # :PROJECT → TS_PROJECT (default: main) # :REGION → cloud region (e.g., us-east-1) # :MOD_NAME → stack/module name # :BUILD_DIR → relative build directory (e.g., stacks/demo) # :NAMESPACE → account ID / subscription / project ID # Example expansion in config/app.rb: Terraspace.configure do |config| config.build.cache_dir = ":REGION/:ENV/:BUILD_DIR" # => .terraspace-cache/us-east-1/dev/stacks/demo config.cloud.stack = ":APP-:ENV-:MOD_NAME-:REGION" # => payments-prod-demo-us-east-1 end # In a Ruby stack file: # app/stacks/demo/main.rb resource("aws_s3_bucket", "state", bucket: expansion(":PROJECT-:ENV-:MOD_NAME-:REGION-tfstate") # => "myplatform-prod-demo-us-east-1-tfstate" ) ``` -------------------------------- ### Taint a Terraform Resource with Output Source: https://github.com/boltops-tools/terraspace/blob/master/lib/terraspace/cli/help/taint.md This example shows the command to taint a resource and the expected output, indicating the resource has been successfully tainted. ```bash $ terraspace taint ec2 aws_instance.my_instance Building .terraspace-cache/us-east-1/dev/stacks/ec2 Hook: Running terraspace before build hook. Current directory: .terraspace-cache/us-east-1/dev/stacks/ec2 => terraform taint aws_instance.my_instance Resource instance aws_instance.my_instance has been successfully tainted. Releasing state lock. This may take a few moments... ``` -------------------------------- ### Import an AWS VPC Resource Source: https://github.com/boltops-tools/terraspace/blob/master/lib/terraspace/cli/help/import.md This example shows how to import an AWS VPC resource. Ensure you provide the correct Terraform resource address (e.g., `module.vpc.aws_vpc.this`) and the VPC ID (e.g., `vpc-000782e4951a734c7`). ```bash terraspace import vpc module.vpc.aws_vpc.this vpc-000782e4951a734c7 ``` -------------------------------- ### Destroying Infrastructure with Terraspace Source: https://github.com/boltops-tools/terraspace/blob/master/lib/terraspace/cli/help/down.md This example shows the typical output when using the `terraspace down` command to destroy a stack named 'demo'. It includes the build process, Terraform destroy execution, confirmation prompt, and the final destruction summary. ```bash $ terraspace down demo Building .terraspace-cache/us-west-2/dev/stacks/demo Built in .terraspace-cache/us-west-2/dev/stacks/demo Current directory: .terraspace-cache/us-west-2/dev/stacks/demo => terraform destroy # ... Plan: 0 to add, 0 to change, 2 to destroy. Changes to Outputs: - bucket_name = "bucket-trusty-marmoset" -> null Do you really want to destroy all resources? Terraform will destroy all your managed infrastructure, as shown above. There is no undo. Only 'yes' will be accepted to confirm. Enter a value: yes module.bucket.aws_s3_bucket.this: Destroying... [id=bucket-trusty-marmoset] module.bucket.aws_s3_bucket.this: Destruction complete after 0s random_pet.this: Destroying... [id=trusty-marmoset] random_pet.this: Destruction complete after 0s Destroy complete! Resources: 2 destroyed. Time took: 21s $ ``` -------------------------------- ### Add Modules to Terrafile Source: https://github.com/boltops-tools/terraspace/blob/master/lib/templates/base/project/README.md Example of how to add external modules to the Terrafile for use in Terraspace projects. Refer to Terraspace documentation for details. ```ruby terraspace "modules/my-app" ``` -------------------------------- ### Define modules in Terrafile Source: https://github.com/boltops-tools/terraspace/blob/master/README.md The Terrafile allows you to specify Terraform modules from Git repositories or the Terraform Registry. Use `terraspace bundle` to install these modules. ```ruby mod "s3", source: "boltops-tools/terraform-aws-s3", tag: "v0.1.0" mod "sg", source: "terraform-aws-modules/security-group/aws", version: "3.10.0" ``` -------------------------------- ### Create New Terraspace Project Source: https://github.com/boltops-tools/terraspace/blob/master/lib/terraspace/cli/help/new/project.md Use the `terraspace new project` command to create a new Terraspace project. Specify the project name, desired plugins (e.g., `aws`), and whether to include examples. ```bash $ terraspace new project infra --plugin aws --examples ``` -------------------------------- ### Run Terraspace Check Source: https://github.com/boltops-tools/terraspace/blob/master/lib/terraspace/cli/help/check.md Execute the `terraspace check` command to verify your installation. This command outputs details about your Terraspace and Terraform versions and confirms if your environment is set up correctly. ```bash $ terraspace check terraspace version: 2.2.11 terraform bin: ~/.tfenv/bin/terraform terraform version: 1.5.5 You're all set! ``` -------------------------------- ### Terrafile DSL for Module Management Source: https://context7.com/boltops-tools/terraspace/llms.txt Define Terraform modules to be installed using the Terrafile DSL. Supports various sources like GitHub, Terraform Registry, and local paths. ```ruby # Terrafile # Set a default GitHub organization (used for short-form sources) org "boltops-tools" # Short form — resolves to github.com/boltops-tools/terraform-aws-vpc mod "vpc", source: "terraform-aws-vpc", tag: "v0.3.0" # Explicit GitHub repo mod "s3", source: "boltops-tools/terraform-aws-s3", tag: "v0.1.0" # Terraform Registry module mod "sg", source: "terraform-aws-modules/security-group/aws", version: "4.17.1" # Private GitHub repo using SSH mod "internal-db", source: "git@github.com:myorg/terraform-aws-rds.git", tag: "v1.2.0" # HTTPS repo on a specific branch mod "dynamic", source: "https://github.com/myorg/terraform-aws-lambda", ref: "feature/vpc" # Local module path (for development) mod "shared-tags", source: "../shared-modules/tags" # After editing Terrafile: # $ terraspace bundle # Modules installed to vendor/modules/ ``` -------------------------------- ### Run Output Command Across All Stacks Source: https://github.com/boltops-tools/terraspace/blob/master/lib/terraspace/cli/help/all/output.md Execute the `terraspace output` command for all stacks. This example demonstrates how the command groups stacks into batches for execution and displays the output logs for each stack. ```bash $ terraspace all output Running: terraspace output c1 # batch 1 terraspace output b1 # batch 2 terraspace output b2 # batch 2 terraspace output a1 # batch 3 Batch Run 1: Running: terraspace output c1 Logs: log/output/c1.log terraspace output c1: length = 1 Batch Run 2: Running: terraspace output b1 Logs: log/output/b1.log Running: terraspace output b2 Logs: log/output/b2.log terraspace output b1: length = 1 terraspace output b1: length2 = 1 terraspace output b2: length = 1 Batch Run 3: Running: terraspace output a1 Logs: log/output/a1.log terraspace output a1: Warning: No outputs found Time took: 12s $ ``` -------------------------------- ### Display Terraspace Stack Info (JSON Format) Source: https://github.com/boltops-tools/terraspace/blob/master/lib/terraspace/cli/help/info.md Use the `--format json` flag to get detailed information about a Terraspace stack in JSON format. This is ideal for scripting and integration with other tools. ```bash $ terraspace info demo --format json [ { "Name": "build_dir", "Value": "stacks/demo" }, { "Name": "cache_dir", "Value": ".terraspace-cache/us-west-2/dev/stacks/demo" }, { "Name": "name", "Value": "demo" }, { "Name": "root", "Value": "app/stacks/demo" }, { "Name": "type", "Value": "stack" }, { "Name": "type_dir", "Value": "stacks" } ] ``` -------------------------------- ### Deploy Infrastructure Using a Plan File Source: https://github.com/boltops-tools/terraspace/blob/master/lib/terraspace/cli/help/up.md This command deploys the 'demo' stack using a previously generated plan file named 'my.plan'. This allows for a more controlled and repeatable deployment process. ```bash $ terraspace up demo --plan "my.plan" ``` -------------------------------- ### Generating and Using Terraspace Plans Source: https://github.com/boltops-tools/terraspace/blob/master/lib/terraspace/cli/help/all/up.md Demonstrates how to generate a plan file with a dynamic output path and then use that plan file for a `terraspace all up` deployment. ```bash $ terraspace all plan --out ":MOD_NAME.plan" ``` ```bash $ terraspace all up --plan ":MOD_NAME.plan" ``` -------------------------------- ### Generate CI Starter Files Source: https://context7.com/boltops-tools/terraspace/llms.txt Use `terraspace new ci` with a provider name (github, gitlab, bitbucket) to generate starter CI configuration files for your project. ```bash # Generate CI starter files terraspace new ci github # .github/workflows/ terraspace new ci gitlab # .gitlab-ci.yml terraspace new ci bitbucket # bitbucket-pipelines.yml ``` -------------------------------- ### Deploy Infrastructure with Terraspace Up Source: https://github.com/boltops-tools/terraspace/blob/master/lib/terraspace/cli/help/up.md This command deploys the 'demo' stack. It shows the build process, Terraform apply execution, and the final output including created resources and their attributes. ```bash $ terraspace up demo Building .terraspace-cache/us-west-2/dev/stacks/demo Built in .terraspace-cache/us-west-2/dev/stacks/demo Current directory: .terraspace-cache/us-west-2/dev/stacks/demo => terraform apply ... Plan: 2 to add, 0 to change, 0 to destroy. Changes to Outputs: + bucket_name = (known after apply) Do you want to perform these actions? Terraform will perform the actions described above. Only 'yes' will be accepted to approve. Enter a value: yes random_pet.this: Creating... random_pet.this: Creation complete after 0s [id=trusty-marmoset] module.bucket.aws_s3_bucket.this: Creating... module.bucket.aws_s3_bucket.this: Creation complete after 2s [id=bucket-trusty-marmoset] Apply complete! Resources: 2 added, 0 changed, 0 destroyed. Outputs: bucket_name = bucket-trusty-marmoset Time took: 39s $ ``` -------------------------------- ### Display All Stacks Information Source: https://github.com/boltops-tools/terraspace/blob/master/lib/terraspace/cli/help/all/show.md Use this command to show resources and outputs for all stacks. The output is grouped into batches for clarity. ```bash $ terraspace all show Running: terraspace show c1 # batch 1 terraspace show b1 # batch 2 terraspace show b2 # batch 2 terraspace show a1 # batch 3 Batch Run 1: Running: terraspace show c1 Logs: log/show/c1.log terraspace show c1: Resources: 0 Outputs: 1 Batch Run 2: Running: terraspace show b1 Logs: log/show/b1.log Running: terraspace show b2 Logs: log/show/b2.log terraspace show b1: Resources: 0 Outputs: 2 terraspace show b2: Resources: 0 Outputs: 1 Batch Run 3: Running: terraspace show a1 Logs: log/show/a1.log terraspace show a1: Resources: 0 Outputs: 0 Time took: 12s $ ``` -------------------------------- ### Layered Tfvars with HCL Format Source: https://context7.com/boltops-tools/terraspace/llms.txt Example of tfvars defined in HCL format for a specific environment. ```hcl # config/stacks/demo/tfvars/dev.tfvars (HCL format) instance_type = "t3.small" ami = "ami-0c55b159cbfafe1f0" enable_https = false ``` -------------------------------- ### Create a New Terraspace Project Source: https://github.com/boltops-tools/terraspace/blob/master/lib/terraspace/cli/help/new/test.md Use this command to bootstrap a new Terraspace project, setting up the basic RSpec and spec_helper files for your project. ```bash $ terraspace new test my --type project => Creating test bootstrap structure create .rspec create spec/spec_helper.rb $ ``` -------------------------------- ### Get Terraspace Stack Built Directory Path Source: https://context7.com/boltops-tools/terraspace/llms.txt Prints only the built directory path for a Terraspace stack. ```bash terraspace info demo --path ``` -------------------------------- ### Show All Logs with -a Option Source: https://github.com/boltops-tools/terraspace/blob/master/lib/terraspace/cli/help/logs.md Use the -a option to display all logs, overriding the default behavior of showing only the last 10 lines. This applies when both an action and stack are specified. ```bash terraspace logs up -a ``` -------------------------------- ### Get Terraspace Stack Information Source: https://context7.com/boltops-tools/terraspace/llms.txt Shows metadata about a built Terraspace stack, including its cache directory path. ```bash terraspace info demo ``` -------------------------------- ### Using Secrets Helpers in TFvars Source: https://context7.com/boltops-tools/terraspace/llms.txt Example of how to use the secrets helper methods within a Terraspace tfvars DSL file. ```ruby # Use in a tfvars DSL file: # config/stacks/demo/tfvars/prod.rb @db_password = ssm_param("/myapp/prod/db_password") @api_key = vault_secret("secret/myapp/api_key") ``` -------------------------------- ### Using Secrets Helpers in ERB Terraform Source: https://context7.com/boltops-tools/terraspace/llms.txt Example of how to use secrets helper methods directly within an ERB-templated Terraform file. ```erb <%# Use in an ERB Terraform file: app/stacks/demo/main.tf.erb %> resource "aws_db_instance" "this" { password = "<%= ssm_param('/myapp/prod/db_password') %>" } ``` -------------------------------- ### Deploy a Terraspace Stack Source: https://context7.com/boltops-tools/terraspace/llms.txt Builds the project cache, initializes Terraform, and applies a specified stack. Use `--yes` for auto-approval or `--plan` to apply a saved plan file. ```bash terraspace up demo ``` ```bash terraspace up demo --yes ``` ```bash terraspace up demo --plan /tmp/demo.plan ``` ```bash terraspace up demo --instance prod ``` -------------------------------- ### Workflow: Plan, Import, and List State Source: https://github.com/boltops-tools/terraspace/blob/master/lib/terraspace/cli/help/import.md A common workflow involves planning to identify missing resources, importing them, and then listing the state to confirm the import. This sequence helps manage infrastructure incrementally. ```bash terraspace plan vpc terraspace import vpc module.vpc.aws_vpc.this vpc-000782e4951a734c7 terraspace plan vpc terraspace import vpc module.vpc.aws_internet_gateway.this[0] igw-0fa4bec3b4b46948a terraspace state list vpc ``` -------------------------------- ### Initialize a Terraspace Project Source: https://github.com/boltops-tools/terraspace/blob/master/lib/terraspace/cli/help/init.md Run the `terraspace init` command followed by a project name to initialize a new Terraspace project. This command sets up the project structure and performs a `terraform init` within the project's cache directory. ```bash $ terraspace init demo Building .terraspace-cache/us-west-2/dev/stacks/demo Built in .terraspace-cache/us-west-2/dev/stacks/demo Current directory: .terraspace-cache/us-west-2/dev/stacks/demo => terraform init -get Initializing modules... Initializing the backend... Initializing provider plugins... - Using previously-installed hashicorp/aws v3.7.0 - Using previously-installed hashicorp/random v2.3.0 The following providers do not have any version constraints in configuration, so the latest version was installed. To prevent automatic upgrades to new major versions that may contain breaking changes, we recommend adding version constraints in a required_providers block in your configuration, with the constraint strings suggested below. * hashicorp/aws: version = "~> 3.7.0" * hashicorp/random: version = "~> 2.3.0" Terraform has been successfully initialized! You may now begin working with Terraform. Try running "terraform plan" to see any changes that are required for your infrastructure. All Terraform commands should now work. If you ever set or change modules or backend configuration for Terraform, rerun this command to reinitialize your working directory. If you forget, other commands will detect it and remind you to do so if necessary. $ ``` -------------------------------- ### Format All Modules and Stacks Source: https://github.com/boltops-tools/terraspace/blob/master/lib/terraspace/cli/help/fmt.md Use the -t all flag to ensure both modules and stacks are formatted. ```bash $ terraspace fmt -t all ``` -------------------------------- ### Create Project-Level Hook Source: https://github.com/boltops-tools/terraspace/blob/master/lib/terraspace/cli/help/new/hook.md Use this command to create a project-level hook. It generates the necessary configuration files. ```bash $ terraspace new hook --type project create config/hooks create config/hooks/terraform.rb ``` -------------------------------- ### Secrets Management Helpers in Ruby Source: https://context7.com/boltops-tools/terraspace/llms.txt Helper methods for fetching secrets from Vault and AWS SSM. Ensure the respective gems are installed. ```ruby module Terraspace::Project::SecretsHelper def vault_secret(path) require 'vault' Vault.logical.read(path)&.data&.fetch(:value) end def ssm_param(name) client = Aws::SSM::Client.new client.get_parameter(name: name, with_decryption: true).parameter.value end end ``` -------------------------------- ### Terraspace CLI Completion Commands Source: https://github.com/boltops-tools/terraspace/blob/master/lib/terraspace/cli/help/completion.md These commands demonstrate how to use the `terraspace completion` command to get auto-completion suggestions for various Terraspace commands and arguments. ```bash terraspace completion ``` ```bash terraspace completion up ``` ```bash terraspace completion up name ``` -------------------------------- ### List All Modules and Stacks Source: https://github.com/boltops-tools/terraspace/blob/master/lib/terraspace/cli/help/list.md Use the `terraspace list` command without any flags to display all available modules and stacks in the project. ```bash $ terraspace list app/modules/example app/stacks/demo ``` -------------------------------- ### Create Project Helper (Conventional Name) Source: https://github.com/boltops-tools/terraspace/blob/master/lib/terraspace/cli/help/new/helper.md Use this command to create a new helper file for a Terraspace project with a conventional name. ```bash $ terraspace new helper custom --type project create config/helpers create config/helpers/custom_helper.rb ``` -------------------------------- ### View Specific Number of Log Lines Source: https://github.com/boltops-tools/terraspace/blob/master/lib/terraspace/cli/help/logs.md Adjust the number of log lines displayed using the -n option. This example shows the last 2 lines of all logs. ```bash terraspace logs -n 2 ``` -------------------------------- ### Set TFC Credentials and Deploy Source: https://context7.com/boltops-tools/terraspace/llms.txt Export your Terraform Cloud token and organization as environment variables. Then, use the `terraspace up` command to deploy, which automatically creates or updates the workspace. ```bash # Set TFC credentials export TFE_TOKEN="your-terraform-cloud-token" export TF_CLOUD_ORGANIZATION="myorg" # Deploy — Terraspace creates/updates the workspace automatically terraspace up demo ``` -------------------------------- ### Instance-Specific TFvars for Multi-Instance Stacks Source: https://context7.com/boltops-tools/terraspace/llms.txt Example of how to define instance-specific tfvars in a Ruby file, utilizing `Terraspace.extra` to access the instance identifier set by `TS_EXTRA` or the `--instance` flag. ```ruby # config/stacks/app/tfvars/base.rb # Each instance can load instance-specific tfvars: @color = Terraspace.extra # "blue" or "green" @instance_type = "t3.small" ``` -------------------------------- ### Run terraspace all plan Source: https://github.com/boltops-tools/terraspace/blob/master/lib/terraspace/cli/help/all/plan.md Executes the plan command for all stacks, organizing them into batches based on dependencies. Shows the execution flow and planning results for each stack within its batch. ```bash $ terraspace all plan Running: terraspace plan c1 # batch 1 terraspace plan b1 # batch 2 terraspace plan b2 # batch 2 terraspace plan a1 # batch 3 Batch Run 1: Running: terraspace plan c1 Logs: log/plan/c1.log terraspace plan c1: Plan: 1 to add, 0 to change, 0 to destroy. terraspace plan c1: Changes to Outputs: Batch Run 2: Running: terraspace plan b1 Logs: log/plan/b1.log Running: terraspace plan b2 Logs: log/plan/b2.log terraspace plan b1: Plan: 2 to add, 0 to change, 0 to destroy. terraspace plan b1: Changes to Outputs: terraspace plan b2: Plan: 1 to add, 0 to change, 0 to destroy. terraspace plan b2: Changes to Outputs: Batch Run 3: Running: terraspace plan a1 Logs: log/plan/a1.log terraspace plan a1: Plan: 2 to add, 0 to change, 0 to destroy. terraspace plan a1: Changes to Outputs: Time took: 11s $ ``` -------------------------------- ### Terraspace All Show Command Source: https://github.com/boltops-tools/terraspace/blob/master/lib/terraspace/cli/help/summary.md Use `terraspace all show` as an alternative to `terraspace summary` for a comprehensive view of all resources across your Terraspace project. ```bash terraspace all show ``` -------------------------------- ### Summarize Terraform Resources Source: https://context7.com/boltops-tools/terraspace/llms.txt Use `terraspace summary` to get a count of all Terraform-managed resources across your stacks. Use the `--details` flag to see individual resource names. ```bash # Summarize all stacks terraspace summary # Output: # Stack Resources # vpc 8 # mysql 5 # instance 3 # Total: 16 # Show individual resource details terraspace summary --details # vpc # aws_vpc.this # aws_subnet.public[0] # ... ``` -------------------------------- ### Format All Terraspace Stacks and Modules Source: https://context7.com/boltops-tools/terraspace/llms.txt Runs `terraform fmt` on all Terraspace stacks and modules in the project. ```bash terraspace fmt --type all ``` -------------------------------- ### Specify plan output path with pattern Source: https://github.com/boltops-tools/terraspace/blob/master/lib/terraspace/cli/help/all/plan.md Use the `--out` argument to specify a pattern for the plan output file. This allows for dynamic naming based on the module name, facilitating later use with `terraspace up`. ```bash $ terraspace all plan --out ":MOD_NAME.plan" ``` -------------------------------- ### Display Terraform Show Output Source: https://github.com/boltops-tools/terraspace/blob/master/lib/terraspace/cli/help/show.md Use the `terraspace show` command followed by the stack name to view the Terraform plan. This is useful for inspecting the resources that will be created, modified, or destroyed. ```bash $ terraspace show demo => terraform show # random_pet.this: resource "random_pet" "this" { id = "fond-sheep" length = 2 separator = "-" } # module.bucket.aws_s3_bucket.this: resource "aws_s3_bucket" "this" { acl = "private" arn = "arn:aws:s3:::bucket-fond-sheep" bucket = "bucket-fond-sheep" bucket_domain_name = "bucket-fond-sheep.s3.amazonaws.com" bucket_regional_domain_name = "bucket-fond-sheep.s3.us-west-2.amazonaws.com" force_destroy = false hosted_zone_id = "Z3BJ6K6RIION7M" id = "bucket-fond-sheep" region = "us-west-2" request_payer = "BucketOwner" tags = {} versioning { enabled = false mfa_delete = false } } Outputs: bucket_name = "bucket-fond-sheep" $ ``` -------------------------------- ### Run All Providers Command Source: https://github.com/boltops-tools/terraspace/blob/master/lib/terraspace/cli/help/all/providers.md Execute the `terraspace providers` command for all stacks. This command can be used to check the provider configurations for all your stacks. ```bash $ terraspace all providers ``` -------------------------------- ### Generate Starter tfvars for a Terraspace Stack Source: https://context7.com/boltops-tools/terraspace/llms.txt Inspects a Terraspace stack's `variables.tf` and generates a starter tfvars file. ```bash terraspace seed demo ``` -------------------------------- ### Terraspace Bundle Command Source: https://github.com/boltops-tools/terraspace/blob/master/lib/terraspace/cli/help/bundle.md Run the main terraspace bundle command. ```bash terraspace bundle ``` -------------------------------- ### Deploy and Destroy Terraspace Project Source: https://github.com/boltops-tools/terraspace/blob/master/lib/terraspace/cli/help/new/project.md After creating a project, navigate into the project directory and use `terraspace up` to deploy a stack or `terraspace down` to destroy it. The `-y` flag confirms the action. ```bash cd infra terraspace up demo -y # to deploy ``` ```bash cd infra terraspace down demo -y # to destroy ``` -------------------------------- ### Format All Source Files Source: https://github.com/boltops-tools/terraspace/blob/master/lib/terraspace/cli/help/fmt.md Run this command to format all Terraform source files in your project. It will list the files being formatted. ```bash $ terraspace fmt Formating terraform files app/modules/example main.tf outputs.tf variables.tf app/stacks/demo main.tf ``` -------------------------------- ### List Required Providers Source: https://github.com/boltops-tools/terraspace/blob/master/lib/terraspace/cli/help/providers.md Use the `terraspace providers demo` command to see a breakdown of providers required by your Terraspace configuration and state. This helps identify any missing or mismatched provider versions. ```bash $ terraspace providers demo => terraform providers Providers required by configuration: . ├── provider[registry.terraform.io/hashicorp/random] └── module.bucket └── provider[registry.terraform.io/hashicorp/aws] Providers required by state: provider[registry.terraform.io/hashicorp/aws] provider[registry.terraform.io/hashicorp/random] $ ``` -------------------------------- ### Format All Terraspace Modules Source: https://context7.com/boltops-tools/terraspace/llms.txt Runs `terraform fmt` on all Terraspace modules in the project. ```bash terraspace fmt --type module ``` -------------------------------- ### Generate a Terraform Plan File Source: https://github.com/boltops-tools/terraspace/blob/master/lib/terraspace/cli/help/up.md This command generates a Terraform plan for the 'demo' stack and saves it to a specified output file. This plan can be used later with `terraspace up`. ```bash $ terraspace plan demo --out "my.plan" ``` -------------------------------- ### Initialize All Stacks Source: https://github.com/boltops-tools/terraspace/blob/master/lib/terraspace/cli/help/all/init.md This command initializes all Terraform stacks in the project. It automatically determines dependencies and runs initialization in batches. Logs for each stack's initialization are stored in `log/init/`. ```bash $ terraspace all init Building one stack to build all stacks Building .terraspace-cache/us-west-2/dev/stacks/c1 Downloading tfstate files for dependencies defined in tfvars... Built in .terraspace-cache/us-west-2/dev/stacks/c1 Running: terraspace init c1 # batch 1 terraspace init b1 # batch 2 terraspace init b2 # batch 2 terraspace init a1 # batch 3 Batch Run 1: Running: terraspace init c1 Logs: log/init/c1.log terraspace init c1: Terraform has been successfully initialized! Batch Run 2: Running: terraspace init b1 Logs: log/init/b1.log Running: terraspace init b2 Logs: log/init/b2.log terraspace init b1: Terraform has been successfully initialized! terraspace init b2: Terraform has been successfully initialized! Batch Run 3: Running: terraspace init a1 Logs: log/init/a1.log terraspace init a1: Terraform has been successfully initialized! Time took: 6s $ ``` -------------------------------- ### Deploy multiple stacks with Terraspace Source: https://github.com/boltops-tools/terraspace/blob/master/README.md Use the `terraspace all up` command to deploy all infrastructure stacks in the correct dependency order. You can also specify multiple stacks to deploy. ```bash terraspace all up terraspace all up mysql redis ``` -------------------------------- ### Generate New Terraspace Stack or Module Source: https://context7.com/boltops-tools/terraspace/llms.txt Creates starter files for a new stack or a reusable module. Use `--lang rb` for Ruby DSL stacks. ```bash terraspace new stack vpc ``` ```bash terraspace new stack vpc --lang rb ``` ```bash terraspace new module security-group ``` -------------------------------- ### Generate Full Terraspace Graph with All Stacks Highlighted Source: https://context7.com/boltops-tools/terraspace/llms.txt Generates a diagram of the Terraspace project, highlighting all stacks. ```bash terraspace all graph --full --format diagram ``` -------------------------------- ### Deploy Individual Terraspace Stack Source: https://github.com/boltops-tools/terraspace/blob/master/lib/templates/base/project/README.md Use this command to deploy a specific infrastructure stack. Replace 'demo' with the actual stack name. ```bash terraspace up demo # where demo is app/stacks/demo ``` -------------------------------- ### Run Terraspace Tests Source: https://github.com/boltops-tools/terraspace/blob/master/lib/terraspace/cli/help/test.md Execute the terraspace test command to run your configured tests. The output shows the test framework being invoked, followed by the build process for the test harness, infrastructure deployment, and finally, the destruction of resources. ```bash $ terraspace test => rspec main Building test harness... ... Test harness built: /tmp/terraspace/test-harnesses/demo-harness => terraspace up demo -y Building .terraspace-cache/us-west-2/test/stacks/demo Built in .terraspace-cache/us-west-2/test/stacks/demo Current directory: .terraspace-cache/us-west-2/test/stacks/demo => terraform init -get >> /tmp/terraspace/log/init/demo.log => terraform plan -out /tmp/terraspace/plans/demo-20200920160313.plan ... => terraform apply -auto-approve /tmp/terraspace/plans/demo-20200920160313.plan ... => terraform destroy -auto-approve random_pet.this: Refreshing state... [id=hopelessly-outgoing-serval] module.bucket.aws_s3_bucket.this: Refreshing state... [id=bucket-hopelessly-outgoing-serval] module.bucket.aws_s3_bucket.this: Destroying... [id=bucket-hopelessly-outgoing-serval] module.bucket.aws_s3_bucket.this: Destruction complete after 0s random_pet.this: Destroying... [id=hopelessly-outgoing-serval] random_pet.this: Destruction complete after 0s Destroy complete! Resources: 2 destroyed. Time took: 5s Finished in 22.08 seconds (files took 0.48602 seconds to load) 1 example, 0 failures $ ``` -------------------------------- ### Create Module Helper (Conventional Name) Source: https://github.com/boltops-tools/terraspace/blob/master/lib/terraspace/cli/help/new/helper.md Use this command to create a new helper file for a Terraspace module with a conventional name. ```bash $ terraspace new helper example --type module create app/module/example/config/helpers create app/module/example/config/helpers/example_helper.rb ``` -------------------------------- ### Import Existing Infrastructure with Instance Identifier Source: https://context7.com/boltops-tools/terraspace/llms.txt Imports an existing resource into a Terraspace stack's state using a specific instance identifier. ```bash terraspace import demo --instance prod aws_instance.this i-0abc123def456 ``` -------------------------------- ### Generate Project-Level Arg Source: https://github.com/boltops-tools/terraspace/blob/master/lib/terraspace/cli/help/new/arg.md Use this command to create argument configuration files for a new Terraspace project. ```bash $ terraspace new arg --type project create config/args create config/args/terraform.rb ``` -------------------------------- ### Format All Terraspace Stacks Source: https://context7.com/boltops-tools/terraspace/llms.txt Runs `terraform fmt` on all Terraspace stacks in the project. ```bash terraspace fmt --type stack ``` -------------------------------- ### Create Stack Helper (Conventional Name) Source: https://github.com/boltops-tools/terraspace/blob/master/lib/terraspace/cli/help/new/helper.md Use this command to create a new helper file for a Terraspace stack with a conventional name. ```bash $ terraspace new helper demo --type stack create app/stacks/demo/config/helpers create app/stacks/demo/config/helpers/demo_helper.rb ``` -------------------------------- ### Authenticate and Deploy with Terraspace Cloud Source: https://context7.com/boltops-tools/terraspace/llms.txt Set your Terraspace Cloud organization and token as environment variables. All subsequent `terraspace all up/plan/down` commands will be automatically recorded in the Terraspace Cloud dashboard. ```bash # Authenticate export TS_ORG="myorg" export TS_TOKEN="tscloud-token-abc123" # All up/plan/down runs are automatically recorded in the dashboard terraspace all up --yes ``` -------------------------------- ### Running Terraspace All Up Source: https://github.com/boltops-tools/terraspace/blob/master/lib/terraspace/cli/help/all/up.md Executes `terraspace all up` to deploy modules in parallel. It shows the planned execution order and prompts for confirmation before proceeding with the deployment. ```bash $ terraspace all up Will run: terraspace up c1 # batch 1 terraspace up b1 # batch 2 terraspace up b2 # batch 2 terraspace up a1 # batch 3 Are you sure? (y/N) ``` ```bash Are you sure? (y/N) y Batch Run 1: Running: terraspace up c1 Logs: log/up/c1.log terraspace up c1: Apply complete! Resources: 1 added, 0 changed, 0 destroyed. Batch Run 2: Running: terraspace up b1 Logs: log/up/b1.log Running: terraspace up b2 Logs: log/up/b2.log terraspace up b1: Apply complete! Resources: 2 added, 0 changed, 0 destroyed. terraspace up b2: Apply complete! Resources: 1 added, 0 changed, 0 destroyed. Batch Run 3: Running: terraspace up a1 Logs: log/up/a1.log terraspace up a1: Apply complete! Resources: 2 added, 0 changed, 0 destroyed. Time took: 25s ``` -------------------------------- ### Enter Terraspace Console Source: https://github.com/boltops-tools/terraspace/blob/master/lib/terraspace/cli/help/console.md Use the `terraspace console` command to enter an interactive Terraform console. This command builds the stack and then drops you into a `terraform console` session within the built stack's directory. ```bash $ terraspace console demo Building .terraspace-cache/us-west-2/dev/stacks/demo Built in .terraspace-cache/us-west-2/dev/stacks/demo Current directory: .terraspace-cache/us-west-2/dev/stacks/demo => terraform console > ``` -------------------------------- ### Deploy infrastructure with Terraspace Source: https://github.com/boltops-tools/terraspace/blob/master/README.md The `terraspace up` command creates infrastructure, such as an S3 bucket. The `terraspace down` command cleans up and destroys the created resources. ```bash terraspace up demo ``` ```bash terraspace down demo ``` -------------------------------- ### Deploy All Terraspace Stacks Source: https://github.com/boltops-tools/terraspace/blob/master/lib/templates/base/project/README.md Use this command to deploy all infrastructure stacks defined in the Terraspace project. ```bash terraspace all up ``` -------------------------------- ### Use saved plan with terraspace up Source: https://github.com/boltops-tools/terraspace/blob/master/lib/terraspace/cli/help/all/plan.md Re-use a previously generated plan file with the `terraspace all up` command by referencing the plan file using the `--plan` argument. ```bash $ terraspace all up --plan ":MOD_NAME.plan" ``` -------------------------------- ### Follow All Logs Source: https://github.com/boltops-tools/terraspace/blob/master/lib/terraspace/cli/help/logs.md Follow all logs in real-time as Terraspace operations run. Terraspace checks for new logs every second. ```bash terraspace logs -f ``` -------------------------------- ### Display Terraspace Stack Info (Table Format) Source: https://github.com/boltops-tools/terraspace/blob/master/lib/terraspace/cli/help/info.md Use this command to view basic information about a Terraspace stack in a human-readable table. This is useful for quick checks during development. ```bash $ terraspace info demo +-----------+---------------------------------------------+ | Name | Value | +-----------+---------------------------------------------+ | build_dir | stacks/demo | | cache_dir | .terraspace-cache/us-west-2/dev/stacks/demo | | name | demo | | root | app/stacks/demo | | type | stack | | type_dir | stacks | +-----------+---------------------------------------------+ ```