pulumi-azure-native icon indicating copy to clipboard operation
pulumi-azure-native copied to clipboard

Import of SqlVirtualMachine missing properties

Open automagic opened this issue 1 year ago • 3 comments

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:

  • assessmentSettings -> https://www.pulumi.com/registry/packages/azure-native/api-docs/sqlvirtualmachine/sqlvirtualmachine/#assessmentsettings
  • autoBackupSettings -> https://www.pulumi.com/registry/packages/azure-native/api-docs/sqlvirtualmachine/sqlvirtualmachine/#autobackupsettings
  • serverConfigurationsManagementSettings -> https://www.pulumi.com/registry/packages/azure-native/api-docs/sqlvirtualmachine/sqlvirtualmachine/#serverconfigurationsmanagementsettings
  • storageConfigurationSettings -> https://www.pulumi.com/registry/packages/azure-native/api-docs/sqlvirtualmachine/sqlvirtualmachine/#storageconfigurationsettings

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).

automagic avatar Sep 18 '24 15:09 automagic

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.

thomas11 avatar Sep 19 '24 17:09 thomas11

@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.

ciprianglg avatar Sep 20 '24 09:09 ciprianglg

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.

thomas11 avatar Sep 24 '24 06:09 thomas11

This issue has been addressed in PR #3639 and shipped in release v2.67.0.

pulumi-bot avatar Oct 16 '24 12:10 pulumi-bot