Events
Mar 17, 11 PM - Mar 21, 11 PM
Join the meetup series to build scalable AI solutions based on real-world use cases with fellow developers and experts.
Register nowThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
In the article, Export your first resources using Azure Export for Terraform, you learn how to export Azure resources into local state files using Azure Export for Terraform. In this article, you learn how to generate the Terraform configuration files from your Azure resources.
Create a Linux VM.
Run az group create to create an Azure resource group.
az group create --name myResourceGroup --location eastus
Run az vm create to create the virtual machine.
az vm create \
--resource-group myResourceGroup \
--name myVM \
--image Debian11 \
--admin-username azureadmin \
--generate-ssh-keys \
--public-ip-sku Standard
Azure Export for Terraform supports a flag - --hcl-only
- that causes the generation of the following files from the exported resource(s):
.tf
HCL files.aztfexportResourceMapping.json
.aztfexportSkippedResources.txt
.The --hcl-only
flag is supported for all primary export commands used for exporting:
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.
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
.
aztfexport resource-group --non-interactive --hcl-only myResourceGroup
Note
Running Azure Export for Terraform can take several minutes to complete.
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.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.
Run terraform destroy.
terraform destroy
Events
Mar 17, 11 PM - Mar 21, 11 PM
Join the meetup series to build scalable AI solutions based on real-world use cases with fellow developers and experts.
Register nowTraining
Learning path
Fundamentals of Terraform on Azure - Training
Learn the fundamentals of how Terraform enables you to manage infrastructure deployments on Azure.
Certification
Microsoft Certified: Azure Fundamentals - Certifications
Demonstrate foundational knowledge of cloud concepts, core Azure services, plus Azure management and governance features and tools.
Documentation
Azure Export for Terraform concepts
Learn how Azure Export for Terraform works, best practices, and limitations around the tool.
Quickstart: Export your first resources using Azure Export for Terraform
Export your first resources using Azure Export for Terraform on a resource group, both interactively and non-interactively.
Using Azure Export for Terraform in advanced scenarios
Learn how to append resources and use remote backends