Skip to content

azurermMssqlVirtualMachine

Manages a Microsoft SQL Virtual Machine

Example Usage

This example provisions a brief Managed Microsoft SQL Virtual Machine. The detailed example of the azurermMssqlVirtualMachine resource can be found in the /examples/mssql/mssqlvm directory within the GitHub Repository

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as azurerm from "./.gen/providers/azurerm";
/*The following providers are missing schema information and might need manual adjustments to synthesize correctly: azurerm.
For a more precise conversion please use the --provider flag in convert.*/
const dataAzurermVirtualMachineExample =
  new azurerm.dataAzurermVirtualMachine.DataAzurermVirtualMachine(
    this,
    "example",
    {
      name: "example-vm",
      resource_group_name: "example-resources",
    }
  );
const azurermMssqlVirtualMachineExample =
  new azurerm.mssqlVirtualMachine.MssqlVirtualMachine(this, "example_1", {
    auto_patching: [
      {
        day_of_week: "Sunday",
        maintenance_window_duration_in_minutes: 60,
        maintenance_window_starting_hour: 2,
      },
    ],
    r_services_enabled: true,
    sql_connectivity_port: 1433,
    sql_connectivity_type: "PRIVATE",
    sql_connectivity_update_password: "Password1234!",
    sql_connectivity_update_username: "sqllogin",
    sql_license_type: "PAYG",
    virtual_machine_id: dataAzurermVirtualMachineExample.id,
  });
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
azurermMssqlVirtualMachineExample.overrideLogicalId("example");

Argument Reference

The following arguments are supported:

  • virtualMachineId - (Required) The ID of the Virtual Machine. Changing this forces a new resource to be created.

  • sqlLicenseType - (Required) The SQL Server license type. Possible values are ahub (Azure Hybrid Benefit), dr (Disaster Recovery), and payg (Pay-As-You-Go). Changing this forces a new resource to be created.

  • autoBackup - (Optional) An autoBackup block as defined below. This block can be added to an existing resource, but removing this block forces a new resource to be created.

  • autoPatching - (Optional) An autoPatching block as defined below.

  • keyVaultCredential - (Optional) (Optional) An keyVaultCredential block as defined below.

  • rServicesEnabled - (Optional) Should R Services be enabled?

  • sqlConnectivityPort - (Optional) The SQL Server port. Defaults to 1433.

  • sqlConnectivityType - (Optional) The connectivity type used for this SQL Server. Possible values are local, private and public. Defaults to private.

  • sqlConnectivityUpdatePassword - (Optional) The SQL Server sysadmin login password.

  • sqlConnectivityUpdateUsername - (Optional) The SQL Server sysadmin login to create.

  • sqlInstance - (Optional) A sqlInstance block as defined below.

  • storageConfiguration - (Optional) An storageConfiguration block as defined below.

  • assessment - (Optional) An assessment block as defined below.

  • tags - (Optional) A mapping of tags to assign to the resource.


The autoBackup block supports the following:

  • encryptionEnabled - (Optional) Enable or disable encryption for backups. Defaults to false.

  • encryptionPassword - (Optional) Encryption password to use. Must be specified when encryption is enabled.

  • manualSchedule - (Optional) A manualSchedule block as documented below. When this block is present, the schedule type is set to manual. Without this block, the schedule type is set to automated.

  • retentionPeriodInDays - (Required) Retention period of backups, in days. Valid values are from 1 to 30.

  • storageBlobEndpoint - (Required) Blob endpoint for the storage account where backups will be kept.

  • storageAccountAccessKey - (Required) Access key for the storage account where backups will be kept.

  • systemDatabasesBackupEnabled - (Optional) Include or exclude system databases from auto backup.


The manualSchedule block supports the following:

  • fullBackupFrequency - (Required) Frequency of full backups. Valid values include daily or weekly.

  • fullBackupStartHour - (Required) Start hour of a given day during which full backups can take place. Valid values are from 0 to 23.

  • fullBackupWindowInHours - (Required) Duration of the time window of a given day during which full backups can take place, in hours. Valid values are between 1 and 23.

  • logBackupFrequencyInMinutes - (Required) Frequency of log backups, in minutes. Valid values are from 5 to 60.

  • daysOfWeek - (Optional) A list of days on which backup can take place. Possible values are monday, tuesday, wednesday, thursday, friday, saturday and sunday

\~> NOTE: daysOfWeek can only be specified when manualSchedule is set to weekly


The autoPatching block supports the following:

  • dayOfWeek - (Required) The day of week to apply the patch on. Possible values are monday, tuesday, wednesday, thursday, friday, saturday and sunday.

  • maintenanceWindowStartingHour - (Required) The Hour, in the Virtual Machine Time-Zone when the patching maintenance window should begin.

  • maintenanceWindowDurationInMinutes - (Required) The size of the Maintenance Window in minutes.


The keyVaultCredential block supports the following:

  • name - (Required) The credential name.

  • keyVaultUrl - (Required) The Azure Key Vault url. Changing this forces a new resource to be created.

  • servicePrincipalName - (Required) The service principal name to access key vault. Changing this forces a new resource to be created.

  • servicePrincipalSecret - (Required) The service principal name secret to access key vault. Changing this forces a new resource to be created.


The sqlInstance block supports the following:

  • adhocWorkloadsOptimizationEnabled - (Optional) Specifies if the SQL Server is optimized for adhoc workloads. Possible values are true and false. Defaults to false.

  • collation - (Optional) Collation of the SQL Server. Defaults to sqlLatin1GeneralCp1CiAs. Changing this forces a new resource to be created.

  • instantFileInitializationEnabled - (Optional) Specifies if Instant File Initialization is enabled for the SQL Server. Possible values are true and false. Defaults to false. Changing this forces a new resource to be created.

  • lockPagesInMemoryEnabled - (Optional) Specifies if Lock Pages in Memory is enabled for the SQL Server. Possible values are true and false. Defaults to false. Changing this forces a new resource to be created.

  • maxDop - (Optional) Maximum Degree of Parallelism of the SQL Server. Possible values are between 0 and 32767. Defaults to 0.

  • maxServerMemoryMb - (Optional) Maximum amount memory that SQL Server Memory Manager can allocate to the SQL Server process. Possible values are between 128 and 2147483647 Defaults to 2147483647.

  • minServerMemoryMb - (Optional) Minimum amount memory that SQL Server Memory Manager can allocate to the SQL Server process. Possible values are between 0 and 2147483647 Defaults to 0.

\~> NOTE: maxServerMemoryMb must be greater than or equal to minServerMemoryMb


The storageConfiguration block supports the following:

  • diskType - (Required) The type of disk configuration to apply to the SQL Server. Valid values include new, extend, or add.

  • storageWorkloadType - (Required) The type of storage workload. Valid values include general, oltp, or dw.

  • dataSettings - (Optional) A storageSettings block as defined below.

  • logSettings - (Optional) A storageSettings block as defined below.

  • systemDbOnDataDiskEnabled - (Optional) Specifies whether to set system databases (except tempDb) location to newly created data storage. Possible values are true and false. Defaults to false.

  • tempDbSettings - (Optional) An tempDbSettings as defined below.


The storageSettings block supports the following:

  • defaultFilePath - (Required) The SQL Server default path

  • luns - (Required) A list of Logical Unit Numbers for the disks.


The tempDbSettings block supports the following:

  • defaultFilePath - (Required) The SQL Server default path

  • luns - (Required) A list of Logical Unit Numbers for the disks.

  • dataFileCount - (Optional) The SQL Server default file count. This value defaults to 8

  • dataFileSizeMb - (Optional) The SQL Server default file size - This value defaults to 256

  • dataFileGrowthInMb - (Optional) The SQL Server default file size - This value defaults to 512

  • logFileSizeMb - (Optional) The SQL Server default file size - This value defaults to 256

  • logFileGrowthMb - (Optional) The SQL Server default file size - This value defaults to 512


The assessment block supports the following:

  • enabled - (Optional) Should Assessment be enabled? Defaults to true.

  • runImmediately - (Optional) Should Assessment be run immediately? Defaults to false.

  • schedule - (Optional) An schedule block as defined below.


The schedule block supports the following:

  • weeklyInterval - (Optional) How many weeks between assessment runs. Valid values are between 1 and 6.

  • monthlyOccurrence - (Optional) How many months between assessment runs. Valid values are between 1 and 5.

\~> NOTE: Either one of weeklyInterval or monthlyOccurrence must be specified.

  • dayOfWeek - (Required) What day of the week the assessment will be run. Default value is monday. Possible values are friday, monday, saturday, sunday, thursday, tuesday and wednesday.

  • startTime - (Required) What time the assessment will be run. Must be in the format hh:mm.

Attributes Reference

The following attributes are exported:

  • id - The ID of the SQL Virtual Machine.

Timeouts

The timeouts block allows you to specify timeouts for certain actions:

  • create - (Defaults to 60 minutes) Used when creating the Microsoft SQL Virtual Machine.
  • update - (Defaults to 60 minutes) Used when updating the Microsoft SQL Virtual Machine.
  • read - (Defaults to 5 minutes) Used when retrieving the Microsoft SQL Virtual Machine.
  • delete - (Defaults to 60 minutes) Used when deleting the Microsoft SQL Virtual Machine.

Import

Microsoft SQL Virtual Machines can be imported using the resourceId, e.g.

terraform import azurerm_mssql_virtual_machine.example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/group1/providers/Microsoft.SqlVirtualMachine/sqlVirtualMachines/example1