Analytics Vidhya
Published in

Analytics Vidhya

Multi-cloud Terraform remote state

Overview

  • AWS S3
  • DynamoDB
  • GitHub
  • Azure Storage Account
  • Google Storage Account

Multi-cloud remote state?

  • Mange state in Terraform Cloud.
  • Consolidate remote state to one cloud provider.
  • Manage state per cloud provider.
  • Google deployments go to Google Storage.
  • AWS deployments go to S3.
  • Azure deployments go to Azure Storage.

Note:

  • Create separate buckets for Prod and NonProd environments.
  • Ensure buckets are versioned.

Rollout

AWS:

export TF_AWS_BUCKET=<remote_state_bucket_name>
export TF_AWS_PROFILE=default
export TF_AWS_BUCKET_REGION=us-west-2

Azure:

export TF_AZURE_STORAGE_ACCOUNT=<storage_account_name>
export TF_AZURE_CONTAINER=<storage_container_name>
ARM_ACCESS_KEY=<storage_access_key>

GCP:

export TF_GCLOUD_BUCKET=<storage_bucket_name>
export TF_GCLOUD_CREDENTIALS=<service_account.json>
export TF_GCLOUD_BUCKET= <remote state bucket>
export TF_GCLOUD_CREDENTIALS= <Path to google service account file>
tf -c=gcloud apply -var='teamid=demo-team' -var='prjid=demo-app' -w=demo-workspace'

Structure in AWS:

  • demo-team -> demo-app -> demo-workspace -> demo-state-key.tfstate
tf -c=aws apply -var='teamid=demo-team' -var='prjid=demo-app' -w=demo-workspace' -s=demo-state

Structure in Azure:

  • foo-team -> bar-app -> demo-workspace -> tryme_key.tfstate

github: https://github.com/tomarv2/tfremote

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store