Bylaw

Gallery › ChangeTrackingAndInventory › Azure built-in policies

Enable ChangeTracking and Inventory for virtual machine scale sets

Converted Initiative Version 1.2.0

Enable ChangeTracking and Inventory for virtual machine scale sets. Takes Data Collection Rule ID as parameter and asks for an option to input applicable locations and user-assigned identity for Azure Monitor Agent.

ConvertTo-Bylaw converted this initiative, and proved that the file compiles back to the same definition.

Azure Policy JSONVMSS.json · 302 lines
{
  "properties": {
    "displayName": "Enable ChangeTracking and Inventory for virtual machine scale sets",
    "policyType": "BuiltIn",
    "description": "Enable ChangeTracking and Inventory for virtual machine scale sets. Takes Data Collection Rule ID as parameter and asks for an option to input applicable locations and user-assigned identity for Azure Monitor Agent.",
    "metadata": {
      "version": "1.2.0",
      "category": "ChangeTrackingAndInventory"
    },
    "version": "1.2.0",
    "parameters": {
      "bringYourOwnUserAssignedManagedIdentity": {
        "type": "Boolean",
        "metadata": {
          "displayName": "Bring Your Own User-Assigned Managed Identity",
          "description": "If set to true, Azure Monitor Agent will use the user-assigned managed identity specified via the 'User-Assigned Managed Identity ...' parameters for authentication. Otherwise, Azure Monitor Agent will use the user-assigned managed identity /subscriptions/<subscription-id>/resourceGroups/built-in-identity-rg/providers/Microsoft.ManagedIdentity/userAssignedIdentities/built-in-identity-<location> for authentication."
        },
        "allowedValues": [
          false,
          true
        ]
      },
      "restrictBringYourOwnUserAssignedIdentityToSubscription": {
        "type": "Boolean",
        "metadata": {
          "displayName": "Restrict Bring Your Own User-Assigned Identity to Subscription",
          "description": "Enable this to enforce the user assigned identity must exist in the same subscription as the virtual machine. When true, must provide User-Assigned Managed Identity Name and User-Assigned Managed Identity Resource Group Name parameters. When false, the parameter User Assigned Managed Identity Resource Id will be used instead."
        },
        "allowedValues": [
          true,
          false
        ],
        "defaultValue": true
      },
      "userAssignedIdentityResourceId": {
        "type": "String",
        "metadata": {
          "displayName": "User-Assigned Managed Identity Resource ID",
          "description": "The resource ID of the pre-created user-assigned managed identity. This parameter is only used when the restrict Bring Your Own User-Assigned Identity To Subscription parameter is false."
        },
        "defaultValue": ""
      },
      "userAssignedManagedIdentityName": {
        "type": "String",
        "metadata": {
          "displayName": "User-Assigned Managed Identity Name",
          "description": "The name of the user-assigned managed identity which Azure Monitor Agent will use for authentication when 'Bring Your Own User-Assigned Managed Identity' is set to true."
        },
        "defaultValue": ""
      },
      "userAssignedManagedIdentityResourceGroup": {
        "type": "String",
        "metadata": {
          "displayName": "User-Assigned Managed Identity Resource Group",
          "description": "The resource group of the user-assigned managed identity which Azure Monitor Agent will use for authentication when 'Bring Your Own User-Assigned Managed Identity' is set to true."
        },
        "defaultValue": ""
      },
      "builtInIdentityResourceGroupLocation": {
        "type": "String",
        "metadata": {
          "displayName": "Built-In-Identity-RG Location",
          "description": "The location of the resource group 'Built-In-Identity-RG' created by the initiative. This parameter is only used when 'Bring Your Own User-Assigned Managed Identity' parameter is false."
        },
        "defaultValue": "eastus"
      },
      "effect": {
        "type": "String",
        "metadata": {
          "displayName": "Effect for all constituent policies",
          "description": "Enable or disable the execution of each of the constituent policies in the initiative."
        },
        "allowedValues": [
          "DeployIfNotExists",
          "Disabled"
        ],
        "defaultValue": "DeployIfNotExists"
      },
      "dcrResourceId": {
        "type": "String",
        "metadata": {
          "displayName": "Data Collection Rule Resource Id",
          "description": "Resource Id of the Data Collection Rule to be applied on the virtual machines in scope."
        }
      },
      "listOfApplicableLocations": {
        "type": "Array",
        "metadata": {
          "displayName": "Applicable Locations",
          "description": "The list of locations where the policy should be applied.",
          "strongType": "location"
        },
        "allowedValues": [
          "australiasoutheast",
          "australiaeast",
          "brazilsouth",
          "canadacentral",
          "centralindia",
          "centralus",
          "eastasia",
          "eastus2euap",
          "eastus",
          "eastus2",
          "francecentral",
          "japaneast",
          "koreacentral",
          "northcentralus",
          "northeurope",
          "norwayeast",
          "southcentralus",
          "southeastasia",
          "switzerlandnorth",
          "uaenorth",
          "uksouth",
          "westcentralus",
          "westeurope",
          "westus",
          "westus2"
        ],
        "defaultValue": [
          "australiasoutheast",
          "australiaeast",
          "brazilsouth",
          "canadacentral",
          "centralindia",
          "centralus",
          "eastasia",
          "eastus2euap",
          "eastus",
          "eastus2",
          "francecentral",
          "japaneast",
          "koreacentral",
          "northcentralus",
          "northeurope",
          "norwayeast",
          "southcentralus",
          "southeastasia",
          "switzerlandnorth",
          "uaenorth",
          "uksouth",
          "westcentralus",
          "westeurope",
          "westus",
          "westus2"
        ]
      }
    },
    "policyDefinitions": [
      {
        "policyDefinitionReferenceId": "AddUserAssignedManagedIdentity_VMSS",
        "policyDefinitionId": "/providers/Microsoft.Authorization/policyDefinitions/516187d4-ef64-4a1b-ad6b-a7348502976c",
        "definitionVersion": "1.*.*-preview",
        "parameters": {
          "effect": {
            "value": "[parameters('effect')]"
          },
          "bringYourOwnUserAssignedManagedIdentity": {
            "value": "[parameters('bringYourOwnUserAssignedManagedIdentity')]"
          },
          "restrictBringYourOwnUserAssignedIdentityToSubscription": {
            "value": "[parameters('restrictBringYourOwnUserAssignedIdentityToSubscription')]"
          },
          "userAssignedIdentityResourceId": {
            "value": "[parameters('userAssignedIdentityResourceId')]"
          },
          "userAssignedIdentityName": {
            "value": "[parameters('userAssignedManagedIdentityName')]"
          },
          "identityResourceGroup": {
            "value": "[parameters('userAssignedManagedIdentityResourceGroup')]"
          },
          "builtInIdentityResourceGroupLocation": {
            "value": "[parameters('builtInIdentityResourceGroupLocation')]"
          }
        }
      },
      {
        "policyDefinitionId": "/providers/Microsoft.Authorization/policyDefinitions/4485d24b-a9d3-4206-b691-1fad83bc5007",
        "definitionVersion": "1.*.*",
        "policyDefinitionReferenceId": "DeployAMAWindowsVMSSWithUAIChangeTrackingAndInventory",
        "parameters": {
          "effect": {
            "value": "[parameters('effect')]"
          },
          "bringYourOwnUserAssignedManagedIdentity": {
            "value": "[parameters('bringYourOwnUserAssignedManagedIdentity')]"
          },
          "restrictBringYourOwnUserAssignedIdentityToSubscription": {
            "value": "[parameters('restrictBringYourOwnUserAssignedIdentityToSubscription')]"
          },
          "userAssignedIdentityResourceId": {
            "value": "[parameters('userAssignedIdentityResourceId')]"
          },
          "userAssignedManagedIdentityName": {
            "value": "[parameters('userAssignedManagedIdentityName')]"
          },
          "userAssignedManagedIdentityResourceGroup": {
            "value": "[parameters('userAssignedManagedIdentityResourceGroup')]"
          },
          "listOfApplicableLocations": {
            "value": "[parameters('listOfApplicableLocations')]"
          }
        }
      },
      {
        "policyDefinitionId": "/providers/Microsoft.Authorization/policyDefinitions/b73e81f3-6303-48ad-9822-b69fc00c15ef",
        "definitionVersion": "1.*.*",
        "policyDefinitionReferenceId": "DeployAMALinuxVMSSWithUAIChangeTrackingAndInventory",
        "parameters": {
          "effect": {
            "value": "[parameters('effect')]"
          },
          "bringYourOwnUserAssignedManagedIdentity": {
            "value": "[parameters('bringYourOwnUserAssignedManagedIdentity')]"
          },
          "restrictBringYourOwnUserAssignedIdentityToSubscription": {
            "value": "[parameters('restrictBringYourOwnUserAssignedIdentityToSubscription')]"
          },
          "userAssignedIdentityResourceId": {
            "value": "[parameters('userAssignedIdentityResourceId')]"
          },
          "userAssignedManagedIdentityName": {
            "value": "[parameters('userAssignedManagedIdentityName')]"
          },
          "userAssignedManagedIdentityResourceGroup": {
            "value": "[parameters('userAssignedManagedIdentityResourceGroup')]"
          },
          "listOfApplicableLocations": {
            "value": "[parameters('listOfApplicableLocations')]"
          }
        }
      },
      {
        "policyDefinitionId": "/providers/Microsoft.Authorization/policyDefinitions/4bb303db-d051-4099-95d2-e3e1428a4d2c",
        "definitionVersion": "2.*.*",
        "policyDefinitionReferenceId": "DeployChangeTrackingExtensionWindowsVMSS",
        "parameters": {
          "effect": {
            "value": "[parameters('effect')]"
          },
          "listOfApplicableLocations": {
            "value": "[parameters('listOfApplicableLocations')]"
          }
        }
      },
      {
        "policyDefinitionId": "/providers/Microsoft.Authorization/policyDefinitions/1288c8d7-4b05-4e3a-bc88-9053caefc021",
        "definitionVersion": "2.*.*",
        "policyDefinitionReferenceId": "DeployChangeTrackingExtensionLinuxVMSS",
        "parameters": {
          "effect": {
            "value": "[parameters('effect')]"
          },
          "listOfApplicableLocations": {
            "value": "[parameters('listOfApplicableLocations')]"
          }
        }
      },
      {
        "policyDefinitionId": "/providers/Microsoft.Authorization/policyDefinitions/8fd85785-1547-4a4a-bf90-d5483c9571c5",
        "definitionVersion": "1.*.*",
        "policyDefinitionReferenceId": "DCRAWindowsVMSSChangeTrackingAndInventory",
        "parameters": {
          "effect": {
            "value": "[parameters('effect')]"
          },
          "dcrResourceId": {
            "value": "[parameters('dcrResourceId')]"
          },
          "listOfApplicableLocations": {
            "value": "[parameters('listOfApplicableLocations')]"
          }
        }
      },
      {
        "policyDefinitionId": "/providers/Microsoft.Authorization/policyDefinitions/1142b015-2bd7-41e0-8645-a531afe09a1e",
        "definitionVersion": "1.*.*",
        "policyDefinitionReferenceId": "DCRALinuxVMSSChangeTrackingAndInventory",
        "parameters": {
          "effect": {
            "value": "[parameters('effect')]"
          },
          "dcrResourceId": {
            "value": "[parameters('dcrResourceId')]"
          },
          "listOfApplicableLocations": {
            "value": "[parameters('listOfApplicableLocations')]"
          }
        }
      }
    ],
    "versions": [
      "1.2.0",
      "1.1.1",
      "1.1.0-PREVIEW",
      "1.0.0-PREVIEW"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policySetDefinitions/c4a70814-96be-461c-889f-2b27429120dc",
  "name": "c4a70814-96be-461c-889f-2b27429120dc"
}
Bylawc4a70814-96be-461c-889f-2b27429120dc.bylaw.ps1 · 151 lines
# Converted from VMSS.json by ConvertTo-Bylaw.
Initiative 'c4a70814-96be-461c-889f-2b27429120dc' {

    Properties @{
        DisplayName   = 'Enable ChangeTracking and Inventory for virtual machine scale sets'
        Description   = 'Enable ChangeTracking and Inventory for virtual machine scale sets. Takes Data Collection Rule ID as parameter and asks for an option to input applicable locations and user-assigned identity for Azure Monitor Agent.'
        Version       = '1.2.0'
        Category      = 'ChangeTrackingAndInventory'
        PolicyVersion = '1.2.0'
    }

    Parameter BringYourOwnUserAssignedManagedIdentity @{
        Type          = 'Boolean'
        AllowedValues = @($false, $true)
        DisplayName   = 'Bring Your Own User-Assigned Managed Identity'
        Description   = 'If set to true, Azure Monitor Agent will use the user-assigned managed identity specified via the ''User-Assigned Managed Identity ...'' parameters for authentication. Otherwise, Azure Monitor Agent will use the user-assigned managed identity /subscriptions/<subscription-id>/resourceGroups/built-in-identity-rg/providers/Microsoft.ManagedIdentity/userAssignedIdentities/built-in-identity-<location> for authentication.'
    }
    Parameter RestrictBringYourOwnUserAssignedIdentityToSubscription @{
        Type          = 'Boolean'
        AllowedValues = @($true, $false)
        Default       = $true
        DisplayName   = 'Restrict Bring Your Own User-Assigned Identity to Subscription'
        Description   = 'Enable this to enforce the user assigned identity must exist in the same subscription as the virtual machine. When true, must provide User-Assigned Managed Identity Name and User-Assigned Managed Identity Resource Group Name parameters. When false, the parameter User Assigned Managed Identity Resource Id will be used instead.'
    }
    Parameter UserAssignedIdentityResourceId @{
        Default     = ''
        DisplayName = 'User-Assigned Managed Identity Resource ID'
        Description = 'The resource ID of the pre-created user-assigned managed identity. This parameter is only used when the restrict Bring Your Own User-Assigned Identity To Subscription parameter is false.'
    }
    Parameter UserAssignedManagedIdentityName @{
        Default     = ''
        DisplayName = 'User-Assigned Managed Identity Name'
        Description = 'The name of the user-assigned managed identity which Azure Monitor Agent will use for authentication when ''Bring Your Own User-Assigned Managed Identity'' is set to true.'
    }
    Parameter UserAssignedManagedIdentityResourceGroup @{
        Default     = ''
        DisplayName = 'User-Assigned Managed Identity Resource Group'
        Description = 'The resource group of the user-assigned managed identity which Azure Monitor Agent will use for authentication when ''Bring Your Own User-Assigned Managed Identity'' is set to true.'
    }
    Parameter BuiltInIdentityResourceGroupLocation @{
        Default     = 'eastus'
        DisplayName = 'Built-In-Identity-RG Location'
        Description = 'The location of the resource group ''Built-In-Identity-RG'' created by the initiative. This parameter is only used when ''Bring Your Own User-Assigned Managed Identity'' parameter is false.'
    }
    Parameter Effect @{
        AllowedValues = @('DeployIfNotExists', 'Disabled')
        Default       = 'DeployIfNotExists'
        DisplayName   = 'Effect for all constituent policies'
        Description   = 'Enable or disable the execution of each of the constituent policies in the initiative.'
    }
    Parameter DcrResourceId @{
        Type        = 'String'
        DisplayName = 'Data Collection Rule Resource Id'
        Description = 'Resource Id of the Data Collection Rule to be applied on the virtual machines in scope.'
    }
    Parameter ListOfApplicableLocations @{
        Type          = 'Array'
        AllowedValues = @('australiasoutheast', 'australiaeast', 'brazilsouth', 'canadacentral', 'centralindia', 'centralus', 'eastasia', 'eastus2euap', 'eastus', 'eastus2', 'francecentral', 'japaneast', 'koreacentral', 'northcentralus', 'northeurope', 'norwayeast', 'southcentralus', 'southeastasia', 'switzerlandnorth', 'uaenorth', 'uksouth', 'westcentralus', 'westeurope', 'westus', 'westus2')
        Default       = @('australiasoutheast', 'australiaeast', 'brazilsouth', 'canadacentral', 'centralindia', 'centralus', 'eastasia', 'eastus2euap', 'eastus', 'eastus2', 'francecentral', 'japaneast', 'koreacentral', 'northcentralus', 'northeurope', 'norwayeast', 'southcentralus', 'southeastasia', 'switzerlandnorth', 'uaenorth', 'uksouth', 'westcentralus', 'westeurope', 'westus', 'westus2')
        DisplayName   = 'Applicable Locations'
        Description   = 'The list of locations where the policy should be applied.'
        Metadata      = [ordered]@{ strongType = 'location' }
    }

    PolicyDefinition @{
        Id          = '516187d4-ef64-4a1b-ad6b-a7348502976c'
        ReferenceId = 'AddUserAssignedManagedIdentity_VMSS'
        Version     = '1.*.*-preview'
        Parameters  = [ordered]@{
            effect                                                 = (Param Effect)
            bringYourOwnUserAssignedManagedIdentity                = (Param BringYourOwnUserAssignedManagedIdentity)
            restrictBringYourOwnUserAssignedIdentityToSubscription = (Param RestrictBringYourOwnUserAssignedIdentityToSubscription)
            userAssignedIdentityResourceId                         = (Param UserAssignedIdentityResourceId)
            userAssignedIdentityName                               = (Param UserAssignedManagedIdentityName)
            identityResourceGroup                                  = (Param UserAssignedManagedIdentityResourceGroup)
            builtInIdentityResourceGroupLocation                   = (Param BuiltInIdentityResourceGroupLocation)
        }
    }

    PolicyDefinition @{
        Id          = '4485d24b-a9d3-4206-b691-1fad83bc5007'
        ReferenceId = 'DeployAMAWindowsVMSSWithUAIChangeTrackingAndInventory'
        Version     = '1.*.*'
        Parameters  = [ordered]@{
            effect                                                 = (Param Effect)
            bringYourOwnUserAssignedManagedIdentity                = (Param BringYourOwnUserAssignedManagedIdentity)
            restrictBringYourOwnUserAssignedIdentityToSubscription = (Param RestrictBringYourOwnUserAssignedIdentityToSubscription)
            userAssignedIdentityResourceId                         = (Param UserAssignedIdentityResourceId)
            userAssignedManagedIdentityName                        = (Param UserAssignedManagedIdentityName)
            userAssignedManagedIdentityResourceGroup               = (Param UserAssignedManagedIdentityResourceGroup)
            listOfApplicableLocations                              = (Param ListOfApplicableLocations)
        }
    }

    PolicyDefinition @{
        Id          = 'b73e81f3-6303-48ad-9822-b69fc00c15ef'
        ReferenceId = 'DeployAMALinuxVMSSWithUAIChangeTrackingAndInventory'
        Version     = '1.*.*'
        Parameters  = [ordered]@{
            effect                                                 = (Param Effect)
            bringYourOwnUserAssignedManagedIdentity                = (Param BringYourOwnUserAssignedManagedIdentity)
            restrictBringYourOwnUserAssignedIdentityToSubscription = (Param RestrictBringYourOwnUserAssignedIdentityToSubscription)
            userAssignedIdentityResourceId                         = (Param UserAssignedIdentityResourceId)
            userAssignedManagedIdentityName                        = (Param UserAssignedManagedIdentityName)
            userAssignedManagedIdentityResourceGroup               = (Param UserAssignedManagedIdentityResourceGroup)
            listOfApplicableLocations                              = (Param ListOfApplicableLocations)
        }
    }

    PolicyDefinition @{
        Id          = '4bb303db-d051-4099-95d2-e3e1428a4d2c'
        ReferenceId = 'DeployChangeTrackingExtensionWindowsVMSS'
        Version     = '2.*.*'
        Parameters  = [ordered]@{
            effect                    = (Param Effect)
            listOfApplicableLocations = (Param ListOfApplicableLocations)
        }
    }

    PolicyDefinition @{
        Id          = '1288c8d7-4b05-4e3a-bc88-9053caefc021'
        ReferenceId = 'DeployChangeTrackingExtensionLinuxVMSS'
        Version     = '2.*.*'
        Parameters  = [ordered]@{
            effect                    = (Param Effect)
            listOfApplicableLocations = (Param ListOfApplicableLocations)
        }
    }

    PolicyDefinition @{
        Id          = '8fd85785-1547-4a4a-bf90-d5483c9571c5'
        ReferenceId = 'DCRAWindowsVMSSChangeTrackingAndInventory'
        Version     = '1.*.*'
        Parameters  = [ordered]@{
            effect                    = (Param Effect)
            dcrResourceId             = (Param DcrResourceId)
            listOfApplicableLocations = (Param ListOfApplicableLocations)
        }
    }

    PolicyDefinition @{
        Id          = '1142b015-2bd7-41e0-8645-a531afe09a1e'
        ReferenceId = 'DCRALinuxVMSSChangeTrackingAndInventory'
        Version     = '1.*.*'
        Parameters  = [ordered]@{
            effect                    = (Param Effect)
            dcrResourceId             = (Param DcrResourceId)
            listOfApplicableLocations = (Param ListOfApplicableLocations)
        }
    }
}

Members (7)

Source: built-in-policies/policySetDefinitions/ChangeTrackingAndInventory/VMSS.json in Azure/azure-policy, under the MIT licence.