Aztfexport fails to export resources when there are two data disk or two nic even if I use --append flag in the command

!thr@ 0 Reputation points
2025-06-17T11:10:10.3466667+00:00

Aztfexport fails to export resources when there are two data disk or two nic attached to an azure vm even if I use --append flag in the command.

Error: [aztfexport] 2025/06/17 08:39:23 DeInitializing...

Error: parallel importing: 1 error occurred:

  • task handler error: failed to merge state file: 1 error occurred:
  • resource azurerm_managed_disk.res-0 is defined in both state files C:\Windows\SystemTemp\34534\terraform.tfstate and C:\Windows\SystemTemp\aztfexport-2342\terraform.tfstate
aztfexport resource --append --generate-import-block --plain-ui -n -o newfolder "$osdiskid"

Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
9,015 questions
{count} votes

4 answers

Sort by: Most helpful
  1. Ashok Gandhi Kotnana 10,115 Reputation points Microsoft External Staff Moderator
    2025-06-17T13:44:12.13+00:00

    @!thr@

    Error indicates a state file conflict. This typically arises when multiple resources share the same default name or identifier, leading to collisions during the export process.

     Resource Naming Conflicts: Azure resources like managed disks or network interfaces often have default names such as res-0, nic-0, etc. If multiple resources share the same default name, aztfexport may attempt to export them into the same state file, causing conflicts.

     Use of --append Flag: While the --append flag is intended to add resources to an existing state file, it doesn't resolve naming conflicts. If two resources have identical names, aztfexport cannot distinguish between them, resulting in the error you're seeing.

     

    Recommendation:

     1.Use the --pattern Flag you can use the --pattern flag to filter resources by name or type during export. For example:

    aztfexport resource --append --pattern "nic" --generate-import-block --plain-ui -n -o newfolder "$osdiskid"
    

     This command filters and exports only the resources that match the specified pattern, reducing the chance of conflicts.

     2. Export Resources Individually

     Export resources one at a time to isolate potential conflicts. For example:

     

    aztfexport resource --append --generate-import-block --plain-ui -n -o newfolder "$osdiskid" 
    aztfexport resource --append --generate-import-block --plain-ui -n -o newfolder "$nicid1"
    aztfexport resource --append --generate-import-block --plain-ui -n -o newfolder "$nicid2"
    

     By exporting each resource separately, you can identify and address conflicts more easily.

    Please let me know how it goes

    1 person found this answer helpful.
    0 comments No comments

  2. !thr@ 0 Reputation points
    2025-06-19T08:53:14.5+00:00

    Hi, Thanks for the response.

    My scenario is, am creating a pipeline that has to import the azure vm and its attached resources using aztfexport. The vm has two data disk attached to it. Now when I import the data disk, I have to use --name-pattern flag, as the default "res-0" is already used to import virtual machine resource. Now when I use the --generate-import-block flag, its create a import.tf file with two data disk resource name as res-0 and the terraform plan throws error as it doesn't exist but it exist with the different name specified in --name-pattern.

    0 comments No comments

  3. Siva Pavuluri 490 Reputation points Microsoft External Staff Moderator
    2025-06-23T06:50:05.62+00:00

    Hi !thr@,

    I was tried non-interactive mode its working fine for me.Screenshot 2025-06-23 121312

    I used the following command:

    aztfexport resource-group --non-interactive --name-pattern azureexporttf --generate-import-block myResourceGroup
    

    Could you please share the error message you encountered when running the command, in a private message? This will help me better understand the issue and provide more accurate assistance.

    If you have any further queries, let me know

    Thank you.


  4. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.