Coder Social home page Coder Social logo

utk1106 / migration-of-terraform-state-file-to-terraform-cloud-workspace Goto Github PK

View Code? Open in Web Editor NEW

This project forked from aniketkumarsinha/migration-of-terraform-state-file-to-terraform-cloud-workspace

0.0 0.0 0.0 2 KB

devops proj

HCL 100.00%

migration-of-terraform-state-file-to-terraform-cloud-workspace's Introduction

Migration of Terraform State file from Azure Storage Account to Terraform Cloud workspace

Migration of Terraform State file from Azure Storage Account to Terraform Cloud workspace

What is Terraform State file?

Terraform stores information about your infrastructure in a State file. This state file keeps track of resources created by your configuration and maps them to real-world resources.

Migration Steps involves:

  • Download the latest State file from the Azure storage account, and rename it to terraform.tfstate.
  • Create a new directory/folder and create a new main.tf file with following configurations:
terraform {
 cloud {
  organization = "YOUR_TFC_ORGANIZATION"

  workspaces {
   name = "WORKSPACE_NAME"
  }
 }
}
  • Copy the downloaded state file into this new directory/folder in which you created the new main.tf file.
  • Make sure that the local version of Terraform match with the Terraform version of your Terraform Cloud workspace. If not install the required version.
  • Now run terraform init command. It will show you something similar:
Initializing Terraform Cloud...
Do you wish to proceed?
  As part of migrating to Terraform Cloud, Terraform can optionally copy your
  current workspace state to the configured Terraform Cloud workspace.

  Answer "yes" to copy the latest state snapshot to the configured
  Terraform Cloud workspace.

  Answer "no" to ignore the existing state and just activate the configured
  Terraform Cloud workspace with its existing state, if any.

  Should Terraform migrate your existing state?

  Enter a value: 

Type "yes".

  • Now you can check over your TFC workspace and you should see the migrated state file.

After Migration:

  • Go back to your actual directory/folder containing your Terraform infrastructure code.
  • Add this same code block to your main.tf file or providers.tf file:
terraform {
 cloud {
  organization = "YOUR_TFC_ORGANIZATION"

  workspaces {
   name = "WORKSPACE_NAME"
  }
 }
}
  • Run terraform init and terraform plan commands or initiate a run over Terraform Cloud. You should see that Terraform Plan phase is not showing any changes to be done.

You have successfully migrated your TF state file from storage account to TFC workspace.

Note:

One TFC workspace can hold only a single state file. If you have multiple environments with multiple state files, you need to create a separate workspace for individual environment's state files respectively and follow the same migration steps.

migration-of-terraform-state-file-to-terraform-cloud-workspace's People

Contributors

aniketkumarsinha 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.