ARTIFACTORY: How to migrate the Terraform state file from local to JFrog Backend repository
From JFrog Artifactory v7.38.4, the Terraform Backend repository serves as a dedicated Remote State Storage Provider. It works together with and in parallel to the Terraform registry, which also serves as the dedicated Terraform registry for hosting your modules and providers in the JFrog Platform.
In-order to migrate your terraform state file from your local to the Remote Backend repository hosted in JFrog Artifactory, we could perform the below steps:
1.) Create a New Backend Terraform Repository using the UI
2.) Add the backend configuration to your terraform scripts
Example backend.tf file for your reference:
terraform {
backend "remote" {
hostname = "<hostname>"
organization = "<backendreponame>"
workspaces {
prefix = "testing"
}
}
}
3.) Once the backend configuration is placed, perform a “terraform init”.
#terraform init Initializing the backend... The "remote" backend configuration only allows named workspaces! Please provide a new workspace name (e.g. dev, test) that will be used to migrate the existing default workspace. Enter a value: demo-backendmigration Acquiring state lock. This may take a few moments... Do you want to copy existing state to the new backend? Pre-existing state was found while migrating the previous "local" backend to the newly configured "remote" backend. No existing state was found in the newly configured "remote" backend. Do you want to copy this state to the new "remote" backend? Enter "yes" to copy and "no" to start with an empty state. Enter a value: yes Releasing state lock. This may take a few moments... Successfully configured the backend "remote"! Terraform will automatically use this backend unless the backend configuration changes. Initializing provider plugins... - Reusing previous version of jfrog/artifactory from the dependency lock file - Using previously-installed jfrog/artifactory v9.0.0 Terraform has been successfully initialized!
4.) Once the state file is migrated to the remote backend JFrog repository, you can perform:
#terraform plan #terraform apply
The state will be referred from the remote backend JFrog repository and you can remove the state files from your local.