Skip to content

azurermMaintenanceAssignmentVirtualMachine

Manages a maintenance assignment to virtual machine.

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.*/
new azurerm.provider.AzurermProvider(this, "azurerm", {
  features: [{}],
});
const azurermResourceGroupExample = new azurerm.resourceGroup.ResourceGroup(
  this,
  "example",
  {
    location: "West Europe",
    name: "example-resources",
  }
);
const azurermVirtualNetworkExample = new azurerm.virtualNetwork.VirtualNetwork(
  this,
  "example_2",
  {
    address_space: ["10.0.0.0/16"],
    location: azurermResourceGroupExample.location,
    name: "example-network",
    resource_group_name: azurermResourceGroupExample.name,
  }
);
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
azurermVirtualNetworkExample.overrideLogicalId("example");
const azurermMaintenanceConfigurationExample =
  new azurerm.maintenanceConfiguration.MaintenanceConfiguration(
    this,
    "example_3",
    {
      location: azurermResourceGroupExample.location,
      name: "example-mc",
      resource_group_name: azurermResourceGroupExample.name,
      scope: "All",
    }
  );
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
azurermMaintenanceConfigurationExample.overrideLogicalId("example");
const azurermSubnetExample = new azurerm.subnet.Subnet(this, "example_4", {
  address_prefixes: ["10.0.2.0/24"],
  name: "internal",
  resource_group_name: azurermResourceGroupExample.name,
  virtual_network_name: azurermVirtualNetworkExample.name,
});
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
azurermSubnetExample.overrideLogicalId("example");
const azurermNetworkInterfaceExample =
  new azurerm.networkInterface.NetworkInterface(this, "example_5", {
    ip_configuration: [
      {
        name: "internal",
        private_ip_address_allocation: "Dynamic",
        subnet_id: azurermSubnetExample.id,
      },
    ],
    location: azurermResourceGroupExample.location,
    name: "example-nic",
    resource_group_name: azurermResourceGroupExample.name,
  });
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
azurermNetworkInterfaceExample.overrideLogicalId("example");
const azurermLinuxVirtualMachineExample =
  new azurerm.linuxVirtualMachine.LinuxVirtualMachine(this, "example_6", {
    admin_ssh_key: [
      {
        public_key: '${file("~/.ssh/id_rsa.pub")}',
        username: "adminuser",
      },
    ],
    admin_username: "adminuser",
    location: azurermResourceGroupExample.location,
    name: "example-machine",
    network_interface_ids: [azurermNetworkInterfaceExample.id],
    os_disk: [
      {
        caching: "ReadWrite",
        storage_account_type: "Standard_LRS",
      },
    ],
    resource_group_name: azurermResourceGroupExample.name,
    size: "Standard_F2",
    source_image_reference: [
      {
        offer: "UbuntuServer",
        publisher: "Canonical",
        sku: "16.04-LTS",
        version: "latest",
      },
    ],
  });
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
azurermLinuxVirtualMachineExample.overrideLogicalId("example");
const azurermMaintenanceAssignmentVirtualMachineExample =
  new azurerm.maintenanceAssignmentVirtualMachine.MaintenanceAssignmentVirtualMachine(
    this,
    "example_7",
    {
      location: azurermResourceGroupExample.location,
      maintenance_configuration_id: azurermMaintenanceConfigurationExample.id,
      virtual_machine_id: azurermLinuxVirtualMachineExample.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.*/
azurermMaintenanceAssignmentVirtualMachineExample.overrideLogicalId("example");

Argument Reference

The following arguments are supported:

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

  • maintenanceConfigurationId - (Required) Specifies the ID of the Maintenance Configuration Resource. Changing this forces a new resource to be created.

  • virtualMachineId - (Required) Specifies the Virtual Machine ID to which the Maintenance Configuration will be assigned. Changing this forces a new resource to be created.

Attributes Reference

The following attributes are exported:

  • id - The ID of the Maintenance Assignment.

Timeouts

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

  • create - (Defaults to 30 minutes) Used when creating the Maintenance Assignment.
  • read - (Defaults to 5 minutes) Used when retrieving the Maintenance Assignment.
  • delete - (Defaults to 30 minutes) Used when deleting the Maintenance Assignment.

Import

Maintenance Assignment can be imported using the resourceId, e.g.

terraform import azurerm_maintenance_assignment_virtual_machine.example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.Compute/virtualMachines/vm1/providers/Microsoft.Maintenance/configurationAssignments/assign1