aztfexport icon indicating copy to clipboard operation
aztfexport copied to clipboard

Aztfexport automation in Azure DevOps

Open chrischeung1126 opened this issue 10 months ago • 5 comments

Hi All,

I'm trying to add aztfexport to the Azure DevOps pipeline. I have installed it on the Azure DevOps Agent, but when I try to export a resource, aztfexport prompts the following messages:

The output directory is not empty. Please choose one of actions below:

* Press "Y" to proceed that will likely pollute the existing files and cause errors
* Press "N" to append new files and add to the existing state instead
* Press other keys to quit 

I tried some commands below, but I still can hit the same messages. I'm not sure how to disable the interactive mode for aztfexport.

aztfexport resource ${{ parameters.resource_id }} --non-interactive --continue --output-dir $(System.DefaultWorkingDirectory)/azure/deployment/${{ parameters.env }}/${{ parameters.project }}/test

aztfexport resource ${{ parameters.resource_id }} --non-interactive --force --output-dir $(System.DefaultWorkingDirectory)/azure/deployment/${{ parameters.env }}/${{ parameters.project }}/test

aztfexport resource ${{ parameters.resource_id }} --non-interactive --overwrite--output-dir $(System.DefaultWorkingDirectory)/azure/deployment/${{ parameters.env }}/${{ parameters.project }}/test

chrischeung1126 avatar Mar 05 '25 09:03 chrischeung1126

@chrischeung1126 Thank you for reaching out! Per the help message below:

$ aztfexport res -h
...
USAGE:
   aztfexport resource [option] [<resourceId> | @<resourceIdFile>...]
...

The option comes before the arguments. Therefore, you shall do something like:

aztfexport resource --non-interactive --force --output-dir $(System.DefaultWorkingDirectory)/azure/deployment/${{ parameters.env }}/${{ parameters.project }}/test ${{ parameters.resource_id }}

Note that since the option --output-dir is not detected before in your case, you probably don't need the --force after you swap the order, if the output directory you've specified is guaranteed to exist and empty. Use --force with caution.

magodo avatar Mar 05 '25 22:03 magodo

Hi Magdo,

I tried your pasted commands but still hit the same problem. There is no automation way for aztfexport?

chrischeung1126 avatar Mar 19 '25 01:03 chrischeung1126

Could you please share the exact command you've been running, and the corresponding error message?

magodo avatar Mar 19 '25 02:03 magodo

Before running aztfexport command you need to disable telemetry using below command

aztfexport config set telemetry_enabled false

Also use -n option in aztfexport command to run it non-intractive.

bkainth1 avatar Apr 03 '25 16:04 bkainth1

choose windows agent in the Azure Devops pipeline along with above commands

bkainth1 avatar Apr 03 '25 16:04 bkainth1