How to add a tag to resource "shutdown-computevm" of DevTestLab

Oda, Yutaka 171 Reputation points
2023-01-25T08:03:40.3566667+00:00

Hi,

I want to ask how to add a tag to "shutdown-computevm-(optional computer name)" (VM's Auto-Shutdown).

I assigned the Azure Policy "Require a tag and its value on resources" to my subscription.

[https://portal.azure.com/#blade/Microsoft_Azure_Policy/PolicyDetailBlade/definitionId/%2Fproviders%2FMicrosoft.Authorization%2FpolicyDefinitions%2F1e30110a-5ceb-460c-a204-c1c3969c6d62

I created a VM with specified "Tags", and then I tried to activate "Auto-Shutdown".

But the error that show can't update the schedule was displayed. Because of policy deny to update the schedule without "Tags".

To solve this error, I think I have to add a specified tag to Auto-Shutdown's resource.

I'd like to ask someone's help to fix it.

Azure DevTest Labs
Azure DevTest Labs
An Azure service that is used for provisioning development and test environments.
258 questions
Azure Automation
Azure Automation
An Azure service that is used to automate, configure, and install updates across hybrid environments.
1,137 questions
Azure Policy
Azure Policy
An Azure service that is used to implement corporate governance and standards at scale for Azure resources.
802 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Oda, Yutaka 171 Reputation points
    2023-01-30T06:20:04.9633333+00:00

    I can solve this problem for myself.

    I create custom policy. bacause I try to obviate the need that adding tag to "shutdown-computevm".

    "policyRule": {
          "if": {
            "allOf": [
              {
                "not": {
                  "field": "[concat('tags[', parameters('tagName'), ']')]",
                  "exists": "false"
                }
              },
              {
                "field": "type",
                "notEquals": "Microsoft.Devtestlab/schedule"
              }
            ]
          },
          "then": {
            "effect": "deny"
          }
        }