Skip to main content

Terraform wrapper to manage state across multiple cloud providers

Project description

# Terraform Remote State Manager

A Python package for managing Terraform remote state for: AWS, Azure, and Gcloud(GCP).

To install package run:

pip install tfremote  --upgrade

Environment setup

  • Install Python 3.8+

  • Using virtualenv is strongly recommended:

python3 -m venv <venv name>

Default log level is WARNING, to change:

export TF_LOG_LEVEL to any of these: 'CRITICAL', 'ERROR', 'WARNING', 'INFO', 'DEBUG'

❗️ Important - Two variables are required for using tf package:

  • teamid
  • prjid

These variables are required to set backend path in the remote storage. Variables can be defined using:

  • As inline variables e.g.: -var='teamid=demo-team' -var='prjid=demo-project'
  • Inside .tfvars file e.g.: -var-file=<tfvars file location>

For more information refer to Terraform documentation

Setup environment variables

AWS

❗️ Important - s3 bucket for remote state should reside in us-west-2 (best practice is to have it versioned)

Set below env variables:

export TF_AWS_BUCKET=<your_remote_state_bucket_name>
export TF_AWS_PROFILE=default
export TF_AWS_BUCKET_REGION=us-west-2
export PATH=$PATH:/usr/local/bin/

Azure

To create storage for remote state there is handy script.

Run scripts/remote_state.sh (fill in the required information)

Set below env variables:

export TF_AZURE_STORAGE_ACCOUNT=tfstatexxxxx # Output of remote_state.sh
export TF_AZURE_CONTAINER=tfstate # Output of remote_state.sh
export ARM_ACCESS_KEY=xxxxxxxxxx # Output of remote_state.sh

Gcloud

https://cloud.google.com/community/tutorials/managing-gcp-projects-with-terraform

Set below env variables:

# Google storage bucket name
export TF_GCLOUD_BUCKET= # change it to right value
# Path to google service account file
export TF_GCLOUD_CREDENTIALS= # change it to right value

How to use

Once environment variables are configured, run:

For aws:

tf -cloud aws plan -var-file ../custom.tfvars

or

tf plan -var-file ../demo.tfvars -var 'foo=bar'  -var 'john=doe' -cloud aws

For azure:

tf plan -var-file ../custom.tfvars -cloud azure

or

tf plan -var-file ../custom.tfvars -var 'foo=bar' -var 'john=doe' -cloud azure

For gcloud:

tf plan -var-file ../custom.tfvars -cloud gcloud

or

tf plan -var-file ../custom.tfvars -var 'foo=bar' -cloud gcloud -var 'john=doe'

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tfremote-0.0.4.tar.gz (11.1 kB view hashes)

Uploaded Source

Built Distribution

tfremote-0.0.4-py3-none-any.whl (18.3 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page