Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nil OS profile in response - Cannot export VMs (but able to export other resources types) #412

Closed
JavierCCC opened this issue Jun 7, 2023 · 11 comments · Fixed by #419 or #425
Closed
Labels
question Further information is requested

Comments

@JavierCCC
Copy link

JavierCCC commented Jun 7, 2023

When i run:

aztfexport query --log-path /tmp/tfy.log -r 'type == "microsoft.compute/virtualmachines" and resourceGroup == "my_rg"'

I get all vm listed as "skipped". There is one log entry per vm that look like this:

2023-06-07T11:16:57.883-0300 [WARN] aztfexport: Failed to query resource type for /subscriptions/my_subscrip_id/resourceGroups/my_rg/providers/Microsoft.Compute/virtualMachines/a_vm: /subscriptions/my_subscrip_id/resourceGroups/my_rg/providers/Microsoft.Compute/virtualMachines/a_vm: resolving "/subscriptions/my_subscrip_id/resourceGroups/my_rg/providers/Microsoft.Compute/virtualMachines/a_vm": unexpected nil OS profile in response

What am i doing wrong?

Edit: Using resource graph, i see i have some VMs with OSProfile property and some other with no OSProfile property. I was able to export with no issues VMs with OSProfile present.

@JavierCCC JavierCCC changed the title nil OS profile in response nil OS profile in response - Cannot export VMs (but able to export other resources types) Jun 7, 2023
@stemaMSFT
Copy link
Member

Hey @JavierCCC, could you try running aztfexport query --log-path /tmp/tfy.log -r 'type =~ "microsoft.compute/virtualmachines" and resourceGroup =~ "my_rg"'
I believe this is just a syntax issue here, where you need =~ instead of ==.

@stemaMSFT stemaMSFT added the question Further information is requested label Jun 7, 2023
@magodo
Copy link
Collaborator

magodo commented Jun 8, 2023

@JavierCCC This is an error raised by aztft that is trying to resolve whether the VM is a Linux or Windows one, by inspecting into the OSProfile property. I'm wondering in which case the VM will not have that one?

@JavierCCC
Copy link
Author

@JavierCCC This is an error raised by aztft that is trying to resolve whether the VM is a Linux or Windows one, by inspecting into the OSProfile property. I'm wondering in which case the VM will not have that one?

If run this query (search for VMs with null osProfile) using Resource Graph Explorer

resources
| where type == "microsoft.compute/virtualmachines"
| where isnotnull(properties['osProfile'])

i got 265 VMs.

If i run the opossite query (search for VMs with an osProfile)

| where type == "microsoft.compute/virtualmachines"
| where isnull(properties['osProfile'])

i got 189 VMs

So, a big portion of my VMs has osProfile = null. 70% of those VMs are Windows Server VMs. Almost all VMs (Windows and Linux) are running Azure images (not custom).

So, im not sure if this is something i must escalte to MS support or not.

@JavierCCC
Copy link
Author

Hey @JavierCCC, could you try running aztfexport query --log-path /tmp/tfy.log -r 'type =~ "microsoft.compute/virtualmachines" and resourceGroup =~ "my_rg"' I believe this is just a syntax issue here, where you need =~ instead of ==.

Just the same error. If the VMs doesn't have an osProfile, they are skipped by aztfexport. Its seems to be partially related to the product we use to manage spot instances. All the VMs with spot instances are VMs with nil osProfile, but there are more VMs with nil osProfile for wich i don't have an explanation yet.

@JavierCCC
Copy link
Author

JavierCCC commented Jun 29, 2023

@JavierCCC This is an error raised by aztft that is trying to resolve whether the VM is a Linux or Windows one, by inspecting into the OSProfile property. I'm wondering in which case the VM will not have that one?

The osProfile property does not seems to hold enough information to identify the OS of a VM, just the kind (windows or linux given the presence of a linuxConfiguration or a windowsConfiguration block):

Windows:

"osProfile": {
    "computerName": "name_of_vm",
    "windowsConfiguration": {
        "provisionVMAgent": true,
        "patchSettings": {
            "assessmentMode": "ImageDefault",
            "patchMode": "AutomaticByOS"
        },
        "enableAutomaticUpdates": true
    },
    "secrets": [],
    "adminUsername": "username"
},

Linux:

"osProfile": {
    "computerName": "The_Name_Of_The_VM",
    "requireGuestProvisionSignal": true,
    "allowExtensionOperations": true,
    "secrets": [],
    "adminUsername": "A_Username",
    **"linuxConfiguration": {**
        "provisionVMAgent": true,
        "disablePasswordAuthentication": false,
        "patchSettings": {
            "assessmentMode": "ImageDefault",
            "patchMode": "ImageDefault"
        }
    }
},

The property that holds more specific information regarding OS seems to be "imageReference"

Windows

"storageProfile": {
    "imageReference": {
        "publisher": "MicrosoftWindowsServer",
        "version": "latest",
        "exactVersion": "17763.2183.2109130127",
        "sku": "2019-Datacenter",
        "offer": "WindowsServer"
    },

Linux

 "storageProfile": {
    "imageReference": {
        "publisher": "RedHat",
        "version": "latest",
        "sku": "8.2",
        "exactVersion": "8.2.2020270811",
        "offer": "RHEL"
    },

@magodo
Copy link
Collaborator

magodo commented Jun 30, 2023

@JavierCCC Thanks for the additional info! Would you mind to query whether all these VMs have properties.storageProfile.osDisk.osType is properly specified, no matter the osProfile is null or not?

@JavierCCC
Copy link
Author

@JavierCCC Thanks for the additional info! Would you mind to query whether all these VMs have properties.storageProfile.osDisk.osType is properly specified, no matter the osProfile is null or not?
Hi magodo.

After running

resources
| where type == "microsoft.compute/virtualmachines"
| extend properties.storageProfile.osDisk.osType

I can see there is a "Windows" or "Linux" for each VM, and the data its ok for all VMs.

@JavierCCC
Copy link
Author

@magodo should i try with a local build from main branch?

@magodo
Copy link
Collaborator

magodo commented Jul 7, 2023

@JavierCCC Yes, by doing go install github.com/Azure/aztfexport@main, or waiting for our next release.

@JavierCCC
Copy link
Author

JavierCCC commented Jul 7, 2023

@JavierCCC Yes, by doing go install github.com/Azure/aztfexport@main, or waiting for our next release.
If i try to export a VM with nill osProfile it still fails (Linux or Windows):


XXXX@XXXXXXXXXXXXXXX:~/aztfexport$ ../go/bin/aztfexport query --continue --non-interactive --recursive 'type == "microsoft.compute/virtualmachines" and name == "XXXXXXXXX"'
Errors:
Failed to import /subscriptions/XXXXXXXXXXXXXXXXXXXX/resourceGroups/XXXXXXXXXXXXXXX/providers/Microsoft.Compute/virtualMachines/XXXXXXXXX as azurerm_windows_virtual_machine.res-0: exit status 1

Error: The "azurerm_windows_virtual_machine" resource doesn't support attaching OS Disks - please use the azurerm_virtual_machine resource instead


Running fine with VMs with no nil osProfile.

@magodo
Copy link
Collaborator

magodo commented Jul 10, 2023

@JavierCCC Thanks for the feedback, I'll make another fix for this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
3 participants