Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: DevTest Lab Schedules support for ComputeVmShutdownTask task type #5863

Open
mikebranstein opened this issue Feb 24, 2020 · 1 comment

Comments

@mikebranstein
Copy link

Community Note

  • Please vote on this issue by adding a 馃憤 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Description

As of the 1.33.0 release of DevTest Labs Schedules, a schedule can only be applied to a DevTest Lab via the lab_name property. Azure also uses these schedules to perform automated VM shutdowns for VMs outside of DevTest Labs.

For example, the ARM JSON for such a shutdown schedule is:

{
  "type": "microsoft.devtestlab/schedules",
  "apiVersion": "2016-05-15",
  "name": "<dev-test-lab-schedule-name>",
  "location": "<location>",
  "properties": {
    "status": "Enabled",
    "taskType": "ComputeVmShutdownTask",
    "dailyRecurrence": {
      "time": "1900"
    },
    "timeZoneId": "Eastern Standard Time",
    "notificationSettings": {
      "status": "Disabled",
      "timeInMinutes": 30
    },
    "targetResourceId": "<vm-external-id>",
    "provisioningState": "Succeeded",
    "uniqueIdentifier": "<resource-uuid>"
  }
}

As you can see, the targetResourceId points to a VM's external id instead of a DevTest Lab. The task type is also different from what is supported by the v1.33.0 resource currently.

The external id is formatted as: /subscriptions/<subscription_id>/resourceGroups/<resource-group-name>/providers/Microsoft.Compute/virtualMachines/<virtual-machine-name>

New or Affected Resource(s)

  • azurerm_dev_test_schedule

Potential Terraform Configuration

This could mean lab_name becomes an optional parameter, and require the name or id of the virtual machine to be optional. The ComputeVmShutdownTask would need added as a valid task type.

References

NOTE: this was previously submitted as issue #4135, and closed. citing that it was a duplicate of #2234 and resolved by #3554. This is not correct. This is not a duplicate. #3554 does not resolve the issue.

See notes attached to #4135 for additional context and history.

@philthynz
Copy link
Contributor

Highly agree that is a requirement for DevTest Lab Schedules. I've seen a pull request to add azurerm_dev_test_global_shutdown_schedule which looks promising.

As a work around, for anyone looking to do the same. You can do it via AzueRM templates in Terraform. Not ideal as you can't manage the resource, but it can create and modify it.

resource "azurerm_template_deployment" "shutdown_schedule_template" {
  count               = var.instance_numbers
  name                = "${var.team_name}_${var.release}_shutdown_schedule_template_${count.index}"
  resource_group_name = "${var.team_name}_${var.release}_${var.owner}_${var.intention}"
  deployment_mode = "Incremental"

  parameters = {
   "location" = var.loc
   "virtualMachineName" = element(azurerm_windows_virtual_machine.win_vm.*.name, count.index)
   "autoShutdownStatus" = "Enabled"
   "autoShutdownTime"   = "18:00"
   "autoShutdownTimeZone" = "New Zealand Standard Time"
   "autoShutdownNotificationStatus" = "Disabled"
   "autoShutdownNotificationLocale" = "en"
  }

  template_body = <<DEPLOY
{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
      "parameters": {
          "location": {
              "type": "string"
          },
          "virtualMachineName": {
              "type": "string"
          },
          "autoShutdownStatus": {
              "type": "string"
          },
          "autoShutdownTime": {
              "type": "string"
          },
          "autoShutdownTimeZone": {
              "type": "string"
          },
          "autoShutdownNotificationStatus": {
              "type": "string"
          },
          "autoShutdownNotificationLocale": {
              "type": "string"
          }
      },
      "resources": [
        {
            "name": "[concat('shutdown-computevm-', parameters('virtualMachineName'))]",
            "type": "Microsoft.DevTestLab/schedules",
            "apiVersion": "2018-09-15",
            "location": "[parameters('location')]",
            "properties": {
                "status": "[parameters('autoShutdownStatus')]",
                "taskType": "ComputeVmShutdownTask",
                "dailyRecurrence": {
                    "time": "[parameters('autoShutdownTime')]"
                },
                "timeZoneId": "[parameters('autoShutdownTimeZone')]",
                "targetResourceId": "[resourceId('Microsoft.Compute/virtualMachines', parameters('virtualMachineName'))]",
                "notificationSettings": {
                    "status": "[parameters('autoShutdownNotificationStatus')]",
                    "notificationLocale": "[parameters('autoShutdownNotificationLocale')]",
                    "timeInMinutes": "30"
                }
            }
        }
    ]
  }
  DEPLOY
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants