DEV Community

Discussion on: Importing Existing Infrastructure to Terraform

Collapse
 
ankysinha profile image
Ankur Sinha

how to use imported terraform.tfstate file in Azure DevOps setup ?

I mean how we can connect to the imported terraform.tfstate file in a Azure DevOps setup after migrating/uploading terraform.tfstate to Azure Storage ?

Main purpose is to import the existing resources to terraform.tfstate and then use the imported terraform.tfstate file in Azure DevOps instead of creating a new terraform.tfstate through Azure DevOps

Collapse
 
vivekanandrapaka profile image
Vivekanand Rapaka

The suggested way is to keep the tfstate file in a storage account rather than in Azure DevOps and have it configured as remote backend..please see my other post on using terraform with Azure devops.

Hope this helps.

Collapse
 
ankysinha profile image
Ankur Sinha

So If I import state file and store it in Azure Storage and give path to this state file in the Azure DevOps , will it create a new state file or pick this one ?

Thread Thread
 
vivekanandrapaka profile image
Vivekanand Rapaka • Edited

You should be giving the configuring location of the tfstate file in your terraform script rather than Azure DevOps as below and Configure Azure DevOps Pipelines to run:

terraform {
backend "azurerm" {
resource_group_name = "StorageAccount-ResourceGroup"
storage_account_name = "abcd1234"
container_name = "tfstate"
key = "prod.terraform.tfstate"
}
}