Coder Social home page Coder Social logo

silinternational / tfc-dump Goto Github PK

View Code? Open in Web Editor NEW
0.0 3.0 0.0 23 KB

Perl command using the Terraform Cloud API to export workspaces, variables, and variable sets to JSON files.

License: MIT License

Perl 47.43% Dockerfile 10.04% Shell 42.53%
hashicorp-terraform perl5 terraform terraform-cloud terraform-enterprise tf-cloud

tfc-dump's Introduction

tfc-dump

Perl script using the Terraform Cloud API to export workspaces, variables, and variable sets to JSON files.

Motivation

During the review of a disaster recovery plan, we realized that we didn't have a record of the values we set for variables in Terraform Cloud workspaces. It would be difficult to recover from the accidental deletion of a Terraform Cloud workspace. This Perl script was quickly written to export information to JSON files using the Terraform Cloud API. The exported information includes workspaces, variables, and variable sets which covers most of what we need.

How to use tfc-dump.pl

  1. Install tfc-ops. tfc-dump was tested with tfc-ops version 3.1.2.
  2. Obtain a Terraform Cloud access token. Go to https://app.terraform.io/app/settings/tokens to create an API token.
  3. Set and export the environment variable ATLAS_TOKEN with the Terraform Cloud access token as its value (e.g., use a command like export ATLAS_TOKEN=terraform-cloud-access-token). Note that preceding the export command with a space may prevent the command from being stored in the shell history. Refer to the description of the HISTCONTROL shell variable in the bash man page for details.
  4. To dump one workspace: tfc-dump.pl --org terraform-cloud-organization --workspace terraform-cloud-workspace-name
  5. To dump all workspaces in an organization: tfc-dump.pl --org terraform-cloud-organization --all

Outputs

Two files are created for each Terraform Cloud workspace:

  • workspace-name-workspace.json
  • workspace-name-variables.json

Two files are created for each Terraform Cloud Variable Set:

  • varset-variable-set-name.json
  • varset-variable-set-name-variables.json

Spaces in the variable set name are replaced with hyphens (-).

Restrictions

The code assumes that all of the Terraform Cloud Variable Sets are contained within the first result page of 20 entries.

Example use with Docker and Backblaze

The image created by the Dockerfile will run tfc-dump and use Restic to back up the resulting files to a repository stored in a Backblaze B2 bucket.

  1. Copy local.env.dist to local.env.
  2. Set the values for the variables contained in local.env.
  3. Obtain a Terraform Cloud access token. Go to https://app.terraform.io/app/settings/tokens to create an API token.
  4. Add the access token value to local.env.
  5. Create a Backblaze B2 bucket. Set the File Lifecycle to Keep only the last version.
  6. Add the B2 bucket name to RESTIC_REPOSITORY in local.env.
  7. Obtain a Backblaze Application Key. Restrict its access to the B2 bucket you just created. Ensure the application key has these capabilities: deleteFiles, listBuckets, listFiles, readBuckets, readFiles, writeBuckets, writeFiles.
  8. Add the application key and secret to local.env as the values of B2_ACCOUNT_ID and B2_ACCOUNT_KEY respectively.
  9. Build the Docker image: docker build --tag tfc-backup:latest .
  10. Initialize the Restic repository (one time only): docker run --env-file=local.env --env BACKUP_MODE=init tfc-backup:latest
  11. Run the Docker image: docker run --env-file=local.env tfc-backup:latest

tfc-dump's People

Contributors

dalenewby avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.