Skip to content

azurermDevTestLinuxVirtualMachine

Manages a Linux Virtual Machine within a Dev Test Lab.

Example Usage

/*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 azurermResourceGroupExample = new azurerm.resourceGroup.ResourceGroup(
  this,
  "example",
  {
    location: "West Europe",
    name: "example-resources",
  }
);
const azurermDevTestLabExample = new azurerm.devTestLab.DevTestLab(
  this,
  "example_1",
  {
    location: azurermResourceGroupExample.location,
    name: "example-devtestlab",
    resource_group_name: azurermResourceGroupExample.name,
    tags: {
      Sydney: "Australia",
    },
  }
);
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
azurermDevTestLabExample.overrideLogicalId("example");
const azurermDevTestVirtualNetworkExample =
  new azurerm.devTestVirtualNetwork.DevTestVirtualNetwork(this, "example_2", {
    lab_name: azurermDevTestLabExample.name,
    name: "example-network",
    resource_group_name: azurermResourceGroupExample.name,
    subnet: [
      {
        use_in_virtual_machine_creation: "Allow",
        use_public_ip_address: "Allow",
      },
    ],
  });
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
azurermDevTestVirtualNetworkExample.overrideLogicalId("example");
const azurermDevTestLinuxVirtualMachineExample =
  new azurerm.devTestLinuxVirtualMachine.DevTestLinuxVirtualMachine(
    this,
    "example_3",
    {
      gallery_image_reference: [
        {
          offer: "UbuntuServer",
          publisher: "Canonical",
          sku: "18.04-LTS",
          version: "latest",
        },
      ],
      lab_name: azurermDevTestLabExample.name,
      lab_subnet_name: `\${${azurermDevTestVirtualNetworkExample.subnet.fqn}[0].name}`,
      lab_virtual_network_id: azurermDevTestVirtualNetworkExample.id,
      location: azurermResourceGroupExample.location,
      name: "example-vm03",
      notes: "Some notes about this Virtual Machine.",
      resource_group_name: azurermResourceGroupExample.name,
      size: "Standard_DS2",
      ssh_key: '${file("~/.ssh/id_rsa.pub")}',
      storage_type: "Premium",
      username: "exampleuser99",
    }
  );
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
azurermDevTestLinuxVirtualMachineExample.overrideLogicalId("example");

Argument Reference

The following arguments are supported:

  • name - (Required) Specifies the name of the Dev Test Machine. Changing this forces a new resource to be created.

-> NOTE: The validation requirements for the Name change based on the osType used in this Virtual Machine. For a Linux VM the name must be between 1-62 characters, and for a Windows VM the name must be between 1-15 characters. It must begin and end with a letter or number, and cannot be all numbers.

  • labName - (Required) Specifies the name of the Dev Test Lab in which the Virtual Machine should be created. Changing this forces a new resource to be created.

  • resourceGroupName - (Required) The name of the resource group in which the Dev Test Lab resource exists. Changing this forces a new resource to be created.

  • location - (Required) Specifies the supported Azure location where the Dev Test Lab exists. Changing this forces a new resource to be created.

  • galleryImageReference - (Required) A galleryImageReference block as defined below.

  • labSubnetName - (Required) The name of a Subnet within the Dev Test Virtual Network where this machine should exist. Changing this forces a new resource to be created.

  • labVirtualNetworkId - (Required) The ID of the Dev Test Virtual Network where this Virtual Machine should be created. Changing this forces a new resource to be created.

  • size - (Required) The Machine Size to use for this Virtual Machine, such as standardF2. Changing this forces a new resource to be created.

  • storageType - (Required) The type of Storage to use on this Virtual Machine. Possible values are standard and premium.

  • username - (Required) The Username associated with the local administrator on this Virtual Machine. Changing this forces a new resource to be created.


  • allowClaim - (Optional) Can this Virtual Machine be claimed by users? Defaults to true.

  • disallowPublicIpAddress - (Optional) Should the Virtual Machine be created without a Public IP Address? Changing this forces a new resource to be created.

  • inboundNatRule - (Optional) One or more inboundNatRule blocks as defined below. Changing this forces a new resource to be created.

-> NOTE: If any inboundNatRule blocks are specified then disallowPublicIpAddress must be set to true.

  • notes - (Optional) Any notes about the Virtual Machine.

  • password - (Optional) The Password associated with the username used to login to this Virtual Machine. Changing this forces a new resource to be created.

  • sshKey - (Optional) The SSH Key associated with the username used to login to this Virtual Machine. Changing this forces a new resource to be created.

-> NOTE: One or either password or sshKey must be specified.

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

A galleryImageReference block supports the following:

  • offer - (Required) The Offer of the Gallery Image. Changing this forces a new resource to be created.

  • publisher - (Required) The Publisher of the Gallery Image. Changing this forces a new resource to be created.

  • sku - (Required) The SKU of the Gallery Image. Changing this forces a new resource to be created.

  • version - (Required) The Version of the Gallery Image. Changing this forces a new resource to be created.


A inboundNatRule block supports the following:

  • protocol - (Required) The Protocol used for this NAT Rule. Possible values are tcp and udp.

  • backendPort - (Required) The Backend Port associated with this NAT Rule. Changing this forces a new resource to be created.

Attributes Reference

The following attributes are exported:

  • id - The ID of the Virtual Machine.

  • fqdn - The FQDN of the Virtual Machine.

  • inboundNatRule - One or more inboundNatRule blocks as defined below.

  • uniqueIdentifier - The unique immutable identifier of the Virtual Machine.


A inboundNatRule block exports the following:

  • frontendPort - The frontend port associated with this Inbound NAT Rule.

Timeouts

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

  • create - (Defaults to 30 minutes) Used when creating the DevTest Linux Virtual Machine.
  • update - (Defaults to 30 minutes) Used when updating the DevTest Linux Virtual Machine.
  • read - (Defaults to 5 minutes) Used when retrieving the DevTest Linux Virtual Machine.
  • delete - (Defaults to 30 minutes) Used when deleting the DevTest Linux Virtual Machine.

Import

Dev Test Linux Virtual Machines can be imported using the resourceId, e.g.

terraform import azurerm_dev_test_linux_virtual_machine.machine1 /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/group1/providers/Microsoft.DevTestLab/labs/lab1/virtualMachines/machine1