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