Azure / aztfexport

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

can we use resourcechanges query with aztfexport? #514

Closed harshitjain5june closed 2 months ago

harshitjain5june commented 2 months ago

I was looking for a way for importing resources that are created in last 7days using aztfexport, I worked with aztfexport , to import resources whose type is not Microsoft.Insights and it worked fine using queries.

But when I try to use resourcechanges query, it gives an error or no item found, because by default it uses resources query only.

i was trying to integrate this type of query with aztfexport: resourcechanges  |extend targetResourceId = tostring(properties.targetResourceId), changeType = tostring(properties.changeType), createTime = todatetime(properties.changeAttributes.timestamp)  | where createTime > ago(7d) and changeType == "Create" or changeType == "Update" or changeType == "Delete" | project  targetResourceId, changeType, createTime  | join ( resources | extend targetResourceId=id) on targetResourceId | where tags ['Environment'] =~ 'prod'  | order by createTime desc  | project createTime, id, resourceGroup, type

is there a way I can use this query with aztfexport?

magodo commented 2 months ago

This query is a comlicated enough for the CLI.. Instead, you can run the query and retrieve a list of resource ids, then we can consider extend the tool to accept a list of resources in the resource mode to support your use case. I'm openning a new issue for tracking the above feature: https://github.com/Azure/aztfexport/issues/515