Hello Experts,
I am trying to import tf state of 3 azure data factories. I have created a powershell script to collect resource id in each loop & run terraform import on that resource id. The resource block in main.tf is created as for_each loop.
The first import was successful but for second & third it failed with error
"Terraform already managing a remote object for azurerm_data_factory.adf1. To import to this address you must first remove the existing object from the state.
Main.tf
resource “azurerm_data_factory” “adf1” {
for_each = var.purposes
name = lower("{var.component}-{var.project}-{var.regionname}-{var.environment}-${each.value.purposes}")
location = data.azurerm_resource_group.rg.location
resource_group_name = data.azurerm_resource_group.rg.name
identity {
type=“SystemAssigned”
}
}
Powershell script
terraform init
$resourceId= az resource list --resource-type Microsoft.DataFactory/factories --resource-group rg-pioneer-us-wus-dev-1 --query ‘.{Id:id}’ --output table
foreach($object in $resourceId){terraform import --var-file=input.tfvars ‘azurerm_data_factory.adf1[“example”]’ $object}
Kindly help on how to proceed on this.
Thanks in advance.