Azure / aztfexport

A tool to bring existing Azure resources under Terraform's management
https://azure.github.io/aztfexport/
Mozilla Public License 2.0
1.59k stars 184 forks source link

Aztfexport documentation #531

Closed paramonovnik closed 4 months ago

paramonovnik commented 4 months ago

Hello,

Is there a decent documentation somewhere? One that would describe all possible commands, different export options, all flags? It's very uncomfortable to search through the internet, stumble across error after error only to find out that there's a dedicated flag for my use case.

magodo commented 4 months ago

@paramonovnik We have all the documents hosted at https://learn.microsoft.com/en-us/azure/developer/terraform/azure-export-for-terraform/export-terraform-overview. Unfortunately, it doesn't contain descriptions for all the commands/options. Whilst we try to make all these commands/options self-explained as much as possible.

Do you mind tell us which option/command you find confusing, so that we can improve the help message, or even consider adding another page for it.

paramonovnik commented 4 months ago

Thanks for quick response @magodo . We're having a few issues. First, the doc says "Finally, you can export an entire subscription." but it doesn't explain how. I need subscription resource to be imported to my existing tfstate. Secondly, there's no clear explanation of how to use query command, because according to the official article something like this should work

aztfexport query -n "resourcecontainers | where type == 'microsoft.resources/subscriptions' | where name == 'subname'"

But it doesn't:

`RESPONSE 400: 400 Bad Request ERROR CODE: BadRequest

{ "error": { "code": "BadRequest", "message": "Please provide below info when asking for support: timestamp = 2024-05-27T08:37:02.1649172Z, correlationId = 6645b3aa-4539-4f7c-8c1d-45722374a96e.", "details": [ { "code": "InvalidQuery", "message": "Query is invalid. Please refer to the documentation for the Azure Resource Graph service and fix the error before retrying." }, { "code": "Operator_FailedToResolveEntity", "message": "'where' operator: Failed to resolve scalar expression named 'resourcecontainers'" }, { "code": "Default", "message": "Filter expression should be Boolean" } ] } }`

paramonovnik commented 4 months ago

I also tried to import subscription as individual resource, but it's autoskipped and cannot be added

image
magodo commented 4 months ago

@paramonovnik This tool (and also the azurerm provider) works in a single-subscription scope. Importing a subscription has some nitty gritty details, which can be found at: https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/subscription#import, which basically requires you to send a subscription alias resource id.

While I suspect importing a single subscription (without any resources included) is not your goal. In order to export all resources within a subscription, you can do aztfexport query True.