pulumi / pulumi-azure-native

Azure Native Provider
Apache License 2.0
125 stars 33 forks source link

Import of SqlVirtualMachine missing properties #3581

Open automagic opened 1 week ago

automagic commented 1 week ago

What happened?

When importing a SqlVirutalMachine with Pulumi, the import code generation appears to be missing many properties of the existing instance.

Example

Currently when you import a sql virtual machine you will get the following code generated:

import * as pulumi from "@pulumi/pulumi";
import * as azure_native from "@pulumi/azure-native";

const testvm = new azure_native.sqlvirtualmachine.SqlVirtualMachine("testvm", {
  location: "westeurope",
  resourceGroupName: "RG-TEST",
  sqlImageOffer: "SQL2016-WS2019",
  sqlImageSku: azure_native.sqlvirtualmachine.SqlImageSku.Standard,
  sqlManagement: azure_native.sqlvirtualmachine.SqlManagementMode.Full,
  sqlServerLicenseType: azure_native.sqlvirtualmachine.SqlServerLicenseType.PAYG,
  sqlVirtualMachineName: "SQLTEST",
  virtualMachineResourceId: "/subscriptions/1111-111-111-111/resourceGroups/RG-TEST/providers/Microsoft.Compute/virtualMachines/SQLTEST",
}, {
  protect: true,
});

However, if we call the rest api:

curl --location --request GET 'https://management.azure.com/subscriptions/1111-1111-1111-1111/resourceGroups/RG-TEST/providers/Microsoft.SqlVirtualMachine/SqlVirtualMachines/SQLTEST?$expand=*&api-version=2023-10-01' \ --header 'Authorization: Bearer YourAzureToken'

We get the following result:

{
    "properties": {
        "virtualMachineResourceId": "/subscriptions/1111-1111-1111-1111/resourceGroups/RG-TEST/providers/Microsoft.Compute/virtualMachines/SQLTEST",
        "provisioningState": "Succeeded",
        "sqlImageOffer": "SQL2016-WS2019",
        "sqlServerLicenseType": "PAYG",
        "sqlManagement": "Full",
        "leastPrivilegeMode": "Enabled",
        "sqlImageSku": "Standard",
        "autoPatchingSettings": {
            "enable": false,
            "additionalVmPatch": "WUMU"
        },
        "autoBackupSettings": {
            "enable": false
        },
        "keyVaultCredentialSettings": {
            "enable": false
        },
        "serverConfigurationsManagementSettings": {
            "sqlConnectivityUpdateSettings": {
                "connectivityType": "PRIVATE",
                "port": 1433
            },
            "sqlWorkloadTypeUpdateSettings": {
                "sqlWorkloadType": "OLTP"
            },
            "sqlStorageUpdateSettings": {},
            "additionalFeaturesServerConfigurations": {
                "isRServicesEnabled": false
            },
            "sqlInstanceSettings": {
                "collation": "SQL_Latin1_General_CP1_CI_AS",
                "maxDop": 0,
                "isOptimizeForAdHocWorkloadsEnabled": false,
                "minServerMemoryMB": 0,
                "maxServerMemoryMB": 2147483647,
                "isLpimEnabled": false,
                "isIfiEnabled": false
            }
        },
        "storageConfigurationSettings": {
            "sqlDataSettings": {
                "luns": [
                    0
                ],
                "defaultFilePath": "F:\\data"
            },
            "sqlLogSettings": {
                "luns": [
                    1
                ],
                "defaultFilePath": "G:\\log"
            },
            "sqlTempDbSettings": {
                "dataFileSize": 8,
                "dataGrowth": 64,
                "logFileSize": 8,
                "logGrowth": 64,
                "dataFileCount": 4,
                "luns": [],
                "defaultFilePath": "D:\\tempDb"
            },
            "sqlSystemDbOnDataDisk": false,
            "diskConfigurationType": "NEW"
        },
        "assessmentSettings": {
            "enable": false,
            "runImmediately": false,
            "schedule": {}
        },
        "enableAutomaticUpgrade": true,
        "additionalVmPatch": "WUMU",
        "osType": "Windows"
    },
    "location": "westeurope",
    "id": "/subscriptions/1111-1111-1111-1111/resourceGroups/RG-TEST/providers/Microsoft.SqlVirtualMachine/sqlVirtualMachines/SQLTEST",
    "name": "SQLTEST",
    "type": "Microsoft.SqlVirtualMachine/sqlVirtualMachines"
}

We see there are many missing properties, which are available on the Azure RM API and also documented in Pulumi:

Output of pulumi about

latest

Additional context

No response

Contributing

Vote on this issue by adding a 👍 reaction. To contribute a fix for this issue, leave a comment (and link to your pull request, if you've opened one already).

thomas11 commented 1 week ago

Hi @automagic, sorry you're seeing an incomplete import. The import is decided by what the provider reads from Azure. To further investigate this, would you be able to capture verbose logs? They won't contain secrets but you might want to sanitize your subscription id.

ciprianglg commented 1 week ago

@thomas11 For azure sql virtual machine there are two rest api's for which you are getting the properties: https://learn.microsoft.com/en-us/rest/api/sqlvm/sql-virtual-machines/get?view=rest-sqlvm-2023-10-01&tabs=HTTP. I didn't look at the pulumi call to see which api is using but for sure is using the one which returns some basic props. In order to fix it, you should call the one with optional parameter.

thomas11 commented 5 days ago

That makes sense. The expand parameter is also used in the request URL @automagic posted above. We haven't encountered such a case yet and will look into how to support it best in a maintainable way.