Azure Export for Terraform supports a flag - --hcl-only - that causes the generation of the following files from the exported resource(s):
Generated .tf HCL files.
Mapping file aztfexportResourceMapping.json.
Skipped resources are listed in aztfexportSkippedResources.txt.
The --hcl-only flag is supported for all primary export commands used for exporting:
resource
resource-group
query
mapping-file
To view the available Azure Export for Terraform commands, run the following command:
aztfexport --help
The --hcl-only flag is useful in scenarios where you don't need the state or aren't sure if you need to generate the state. To export all the generated configuration to state, run aztfexport mapping-file.
Tip
When using the --hcl-only flag, target an empty directory to avoid making unwanted changes to any current state during the export stage.
Export an Azure resource
You can run the aztfexport tool in one of two modes: interactive and non-interactive. For this demo, you use the non-interactive mode.
Create a directory in which to test.
Open a command prompt and navigate to the new directory.
Run aztfexport resource-group to export the resource group named myResourceGroup.
Running Azure Export for Terraform can take several minutes to complete.
Verify the results
After the tool has finished exporting your Azure resources, verify the following files in the directory where you ran Azure Export for Terraform:
main.tf contains the HCL code that defines the exported resources.
aztfexportResourceMapping.json contains the Azure/Terraform mappings. The mapping file includes the following information for each exported Azure resource: Azure resource ID, Terraform resource type, and Terraform resource name. The contents of the mapping file mirror what Azure Export for Terraform displays during the export process.
aztfexportSkippedResources.txt contains the list of skipped resources. You shouldn't see this file for this example.
Clean up resources
When you no longer need the resources created in this article, do the following steps:
Navigate to the directory containing your Terraform files for this article.