Search code examples
linuxazuredeploymentazure-policy

Azure policy error: CaseSensitiveDeploymentParameterNamesFound


I have the following policy definition to run a script for all the Linux Virtual machines in my subscription - resource group. I have 4 Linux virtual machines, OpenSuse, Ubuntu18.04, Ubuntu-server22.04, OracleLinux8.6. I partially copied what Microsoft did to deploy a script on Linux VMs, and I modified to install a script called bac.sh. For a test, I installed the script on a Linux VM and it works. I made sure that it doesn't prompt the user for any input values, except that the script will need to be run as "sudo bash bac.sh" on the Linux VM. Microsoft uses the following : "commandToExecute": "bash rac.sh"; to run the script on Linux VMs

{
  "mode": "All",
  "policyRule": {
    "if": {
      "allOf": [
        {
          "field": "type",
          "equals": "Microsoft.Compute/virtualMachines"
        },
        {
          "anyOf": [
            {
              "allOf": [
                {
                  "field": "Microsoft.Compute/imagePublisher",
                  "equals": "RedHat"
                },
                {
                  "field": "Microsoft.Compute/imageOffer",
                  "in": [
                    "RHEL",
                    "RHEL-SAP-HANA",
                    "RHEL-ARM64",
                    "RHEL-BYOS",
                    "RHEL-HA",
                    "RHEL-SAP",
                    "RHEL-SAP-APPS",
                    "RHEL-SAP-HA"
                  ]
                },
                {
                  "anyOf": [
                    {
                      "field": "Microsoft.Compute/imageSku",
                      "like": "7*"
                    },
                    {
                      "field": "Microsoft.Compute/imageSku",
                      "like": "8*"
                    },
                    {
                      "field": "Microsoft.Compute/imageSku",
                      "like": "rhel-lvm7*"
                    },
                    {
                      "field": "Microsoft.Compute/imageSku",
                      "like": "rhel-lvm8*"
                    }
                  ]
                }
              ]
            },
            {
              "allOf": [
                {
                  "field": "Microsoft.Compute/imagePublisher",
                  "equals": "SUSE"
                },
                {
                  "field": "Microsoft.Compute/imageOffer",
                  "in": [
                    "SLES",
                    "SLES-HPC",
                    "SLES-HPC-Priority",
                    "SLES-SAP",
                    "SLES-SAP-BYOS",
                    "SLES-Priority",
                    "SLES-BYOS",
                    "SLES-SAPCAL",
                    "SLES-Standard",
                    "SLES-12-SP5",
                    "SLES-15-SP2"
                  ]
                },
                {
                  "anyOf": [
                    {
                      "field": "Microsoft.Compute/imageSku",
                      "like": "12*"
                    },
                    {
                      "field": "Microsoft.Compute/imageSku",
                      "like": "15*"
                    },
                    {
                      "field": "Microsoft.Compute/imageSku",
                      "like": "gen*"
                    }
                  ]
                }
              ]
            },
            {
              "allOf": [
                {
                  "field": "Microsoft.Compute/imagePublisher",
                  "equals": "Canonical"
                },
                {
                  "anyOf": [
                    {
                      "field": "Microsoft.Compute/imageOffer",
                      "equals": "UbuntuServer"
                    },
                    {
                      "field": "Microsoft.Compute/imageOffer",
                      "like": "0001-com-ubuntu-server-*"
                    },
                    {
                      "field": "Microsoft.Compute/imageOffer",
                      "like": "0001-com-ubuntu-pro-*"
                    }
                  ]
                },
                {
                  "anyOf": [
                    {
                      "field": "Microsoft.Compute/imageSku",
                      "like": "18_04-lts*"
                    },
                    {
                      "field": "Microsoft.Compute/imageSku",
                      "like": "18.04-lts*"
                    },
                    {
                      "field": "Microsoft.Compute/imageSku",
                      "like": "20_04-lts*"
                    },
                    {
                      "field": "Microsoft.Compute/imageSku",
                      "like": "22_04-lts*"
                    },
                    {
                      "field": "Microsoft.Compute/imageSku",
                      "like": "pro-18_04-lts*"
                    },
                    {
                      "field": "Microsoft.Compute/imageSku",
                      "like": "pro-20_04-lts*"
                    },
                    {
                      "field": "Microsoft.Compute/imageSku",
                      "like": "pro-22_04-lts*"
                    }
                  ]
                }
              ]
            },
            {
              "allOf": [
                {
                  "field": "Microsoft.Compute/imagePublisher",
                  "equals": "Oracle"
                },
                {
                  "field": "Microsoft.Compute/imageOffer",
                  "equals": "Oracle-Linux"
                },
                {
                  "anyOf": [
                    {
                      "field": "Microsoft.Compute/imageSku",
                      "like": "7*"
                    },
                    {
                      "field": "Microsoft.Compute/imageSku",
                      "like": "8*"
                    }
                  ]
                }
              ]
            },
            {
              "allOf": [
                {
                  "field": "Microsoft.Compute/imagePublisher",
                  "equals": "OpenLogic"
                },
                {
                  "field": "Microsoft.Compute/imageOffer",
                  "in": [
                    "CentOS",
                    "Centos-LVM",
                    "CentOS-SRIOV"
                  ]
                },
                {
                  "anyOf": [
                    {
                      "field": "Microsoft.Compute/imageSku",
                      "like": "6.*"
                    },
                    {
                      "field": "Microsoft.Compute/imageSku",
                      "like": "7*"
                    },
                    {
                      "field": "Microsoft.Compute/imageSku",
                      "like": "8*"
                    }
                  ]
                }
              ]
            },
            {
              "allOf": [
                {
                  "field": "Microsoft.Compute/imagePublisher",
                  "equals": "cloudera"
                },
                {
                  "field": "Microsoft.Compute/imageOffer",
                  "equals": "cloudera-centos-os"
                },
                {
                  "field": "Microsoft.Compute/imageSku",
                  "like": "7*"
                }
              ]
            },
            {
              "allOf": [
                {
                  "field": "Microsoft.Compute/imagePublisher",
                  "equals": "almalinux"
                },
                {
                  "field": "Microsoft.Compute/imageOffer",
                  "like": "almalinux*"
                },
                {
                  "field": "Microsoft.Compute/imageSku",
                  "like": "8*"
                }
              ]
            },
            {
              "allOf": [
                {
                  "field": "Microsoft.Compute/imagePublisher",
                  "equals": "ctrliqinc1648673227698"
                },
                {
                  "field": "Microsoft.Compute/imageOffer",
                  "like": "rocky-8*"
                },
                {
                  "field": "Microsoft.Compute/imageSku",
                  "like": "rocky-8*"
                }
              ]
            },
            {
              "allOf": [
                {
                  "field": "Microsoft.Compute/imagePublisher",
                  "equals": "credativ"
                },
                {
                  "field": "Microsoft.Compute/imageOffer",
                  "in": [
                    "debian"
                  ]
                },
                {
                  "field": "Microsoft.Compute/imageSku",
                  "equals": "9"
                }
              ]
            },
            {
              "allOf": [
                {
                  "field": "Microsoft.Compute/imagePublisher",
                  "equals": "Debian"
                },
                {
                  "field": "Microsoft.Compute/imageOffer",
                  "in": [
                    "debian-10",
                    "debian-11"
                  ]
                },
                {
                  "anyOf": [
                    {
                      "field": "Microsoft.Compute/imageSku",
                      "like": "10*"
                    },
                    {
                      "field": "Microsoft.Compute/imageSku",
                      "like": "11*"
                    }
                  ]
                }
              ]
            },
            {
              "allOf": [
                {
                  "field": "Microsoft.Compute/imagePublisher",
                  "equals": "microsoftcblmariner"
                },
                {
                  "field": "Microsoft.Compute/imageOffer",
                  "equals": "cbl-mariner"
                }
              ]
            }
          ]
        }
      ]
    },
    "then": {
      "effect": "deployIfNotExists",
      "details": {
        "type": "Microsoft.Compute/virtualMachines/extensions",
        "name": "CBCSE",
        "deployment": {
          "properties": {
            "mode": "incremental",
            "template": {
              "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
              "contentVersion": "1.0.0.0",
              "parameters": {
                "location": {
                  "type": "string"
                },
                "vmname": {
                  "type": "string"
                },
>                 "vmName": {
>                   "type": "string"
>                 }
              },
              "resources": [
                {
                  "apiVersion": "2020-06-01",
                  "name": "[concat(parameters('vmName'), '/CBCSE')]",
                  "type": "Microsoft.Compute/virtualMachines/extensions",
                  "location": "[parameters('location')]",
                  "properties": {
                    "publisher": "Microsoft.Compute",
                    "type": "CustomScriptExtension",
                    "autoUpgradeMinorVersion": true,
                    "typeHandlerVersion": "1.0",
                    "settings": {
                      "timestamp": 123456789,
                      "commandToExecute": "bash bac.sh",
                      "fileUris": [
                        "https://mystorage.blob.core.windows.net/hbs/bac.sh"
                      ]
                    },
                    "protectedSettings": {}
                  }
                }
              ]
            },
            "parameters": {
              "location": {
                "value": "[field('location')]"
              },
              "vmname": {
                "value": "[field('name')]"
              },
>               "vmName": {
>                 "value": "[field('name')]"
>               }
            }
          }
        },
        "roleDefinitionIds": [
          "/providers/microsoft.authorization/roleDefinitions/b24988ac-6180-42a0-ab88-20f7382dd24c"
        ],
        "existenceCondition": {
          "allOf": [
            {
              "field": "Microsoft.Compute/virtualMachines/extensions/type",
              "equals": "CBCSE"
            },
            {
              "field": "Microsoft.Compute/virtualMachines/extensions/provisioningState",
              "equals": "Succeeded"
            }
          ]
        }
      }
    }
  },
  "parameters": {}
}

After checking the "deployment error" in the Remediation task, I found the following error message

Code CaseSensitiveDeploymentParameterNamesFound Message The deployment parameters are using case sensitive names. The error parameter name(s): vmName. Please see https://aka.ms/arm-keyvault for usage details.

Note: The "vname" appears twice, I removed it several times, but not why Azure keeps adding it.

Any comment/help will be appreciated!

I was expecting the script to run on all the Linux VMs, but I am seeing the deployment error as

Details Code CaseSensitiveDeploymentParameterNamesFound Message The deployment parameters are using case sensitive names. The error parameter name(s): vmName. Please see https://aka.ms/arm-keyvault for usage details.


Solution

  • I think Azure Resource Manager is actually running in to an issue removing the duplicate vmName/vmname property because of the case sensitivity issue in the original error. Thirst thing I would try is making sure you have a backup of the policy JSON as a file on your computer. Remove the duplicate vmname entry and save the file. Then delete the original Policy in Azure and recreate it from the edited local file.