I want to try to enable vm encryption from a policy in azure.
I am currently getting this error below, I have a problem with my policy rule. I'm not sure how to change the "details" to set the vm encryption... any ideas??
│ RESPONSE 400: 400 Bad Request │ ERROR CODE: InvalidPolicyRule │ -------------------------------------------------------------------------------- │ { │ "error": { │ "code": "InvalidPolicyRule", │ "message": "Failed to parse policy rule: 'Could not find member 'Microsoft.Compute/virtualMachines/securityProfile.encryptionAtHost' on object of type 'ModifyEffectDetailsDefinition'. Path '['Microsoft.Compute/virtualMachines/securityProfile.encryptionAtHost']'.'." │ } │ } │ -----
This is my policy here :
{
"type": "Microsoft.Authorization/policyDefinitions",
"apiVersion": "2021-06-01",
"name": "Enable VM Encryption at host",
"properties": {
"displayName": "Enable VM encryption at host",
"mode": "Indexed",
"description": "This policy enables VM encryption at host.",
"metadata": {
"category": "Compute"
},
"parameters": {},
"policyRule": {
"if": {
"allOf": [
{
"field": "type",
"equals": "Microsoft.Compute/virtualMachines"
},
{
"field": "Microsoft.Compute/virtualMachines/securityProfile.encryptionAtHost",
"notEquals": "true"
}
]
},
"then": {
"effect": "[parameters('effect')]",
"details": {
"Microsoft.Compute/virtualMachines/securityProfile.encryptionAtHost": "true"
}
}
},
"policyType": "Custom"
}
}
For enabling securityProfile on VM using Policy the above parameter is not accepted
Here is the Azure Policy to enable VM encryption at the host for all VMs in a stopped state, using the effect: append.
Azure Policy:
Response:
Alternatively, you can use a
PowerShell
script to update theencryptionAtHost
setting on allVMs
that have not been updated.Response:
Reference: Modify operations
Update a VM to enable encryption at host.