Skip to content

azurermDevTestGlobalVmShutdownSchedule

Manages automated shutdown schedules for Azure VMs that are not within an Azure DevTest Lab. While this is part of the DevTest Labs service in Azure, this resource applies only to standard VMs, not DevTest Lab VMs. To manage automated shutdown schedules for DevTest Lab VMs, reference the azurermDevTestSchedule resource

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: "sample-rg",
  }
);
const azurermVirtualNetworkExample = new azurerm.virtualNetwork.VirtualNetwork(
  this,
  "example_1",
  {
    address_space: ["10.0.0.0/16"],
    location: azurermResourceGroupExample.location,
    name: "sample-vnet",
    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 azurermSubnetExample = new azurerm.subnet.Subnet(this, "example_2", {
  address_prefixes: ["10.0.2.0/24"],
  name: "sample-subnet",
  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_3", {
    ip_configuration: [
      {
        name: "testconfiguration1",
        private_ip_address_allocation: "Dynamic",
        subnet_id: azurermSubnetExample.id,
      },
    ],
    location: azurermResourceGroupExample.location,
    name: "sample-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_4", {
    admin_password: "Password1234!",
    admin_username: "testadmin",
    disable_password_authentication: false,
    location: azurermResourceGroupExample.location,
    name: "SampleVM",
    network_interface_ids: [azurermNetworkInterfaceExample.id],
    os_disk: [
      {
        caching: "ReadWrite",
        name: "myosdisk-example",
        storage_account_type: "Standard_LRS",
      },
    ],
    resource_group_name: azurermResourceGroupExample.name,
    size: "Standard_B2s",
    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 azurermDevTestGlobalVmShutdownScheduleExample =
  new azurerm.devTestGlobalVmShutdownSchedule.DevTestGlobalVmShutdownSchedule(
    this,
    "example_5",
    {
      daily_recurrence_time: "1100",
      enabled: true,
      location: azurermResourceGroupExample.location,
      notification_settings: [
        {
          enabled: true,
          time_in_minutes: "60",
          webhook_url: "https://sample-webhook-url.example.com",
        },
      ],
      timezone: "Pacific Standard Time",
      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.*/
azurermDevTestGlobalVmShutdownScheduleExample.overrideLogicalId("example");

Argument Reference

The following arguments are supported:

  • location - (Required) The location where the schedule is created. Changing this forces a new resource to be created.

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

  • enabled - (Optional) Whether to enable the schedule. Possible values are true and false. Defaults to true.

  • timezone - (Required) The time zone ID (e.g. Pacific Standard time). Refer to this guide for a full list of accepted time zone names.

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

  • dailyRecurrenceTime - (Required) The time each day when the schedule takes effect. Must match the format HHmm where HH is 00-23 and mm is 00-59 (e.g. 0930, 2300, etc.)

  • notificationSettings - (Required) The notification setting of a schedule. A notificationSettings as defined below.


A notificationSettings block supports the following:

  • enabled - (Required) Whether to enable pre-shutdown notifications. Possible values are true and false.

  • email - (Optional) E-mail address to which the notification will be sent.

  • timeInMinutes - (Optional) Time in minutes between 15 and 120 before a shutdown event at which a notification will be sent. Defaults to 30.

  • webhookUrl - (Optional) The webhook URL to which the notification will be sent.

Attributes Reference

The following additional attributes are exported:

  • id - The Dev Test Global Schedule ID.

Timeouts

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

  • read - (Defaults to 5 minutes) Used when retrieving the Dev Test Global Vm Shutdown Schedule.
  • create - (Defaults to 30 minutes) Used when creating the Dev Test Global Vm Shutdown Schedule.
  • update - (Defaults to 30 minutes) Used when updating the Dev Test Global Vm Shutdown Schedule.
  • delete - (Defaults to 30 minutes) Used when deleting the Dev Test Global Vm Shutdown Schedule.

Import

An existing Dev Test Global Shutdown Schedule can be imported using the resourceId, e.g.

terraform import azurerm_dev_test_global_vm_shutdown_schedule.example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/sample-rg/providers/Microsoft.DevTestLab/schedules/shutdown-computevm-SampleVM

The name of the resource within the resourceId will always follow the format shutdownComputevm-<vmName> where <vmName> is replaced by the name of the target Virtual Machine