Azure / bicep

Bicep is a declarative language for describing and deploying Azure resources
MIT License
3.22k stars 747 forks source link

Creating maintenance Configuration: error Extension properties must contain Patch mode #8959

Closed LeonB87 closed 1 year ago

LeonB87 commented 1 year ago

Bicep version Bicep CLI version 0.12.40 (41892bd0fb)

Describe the bug I'm using a very simple bicep file to create a 'maintenance Configurations' using an example created manually. When deploying, the following error is returned:

New-AzResourceGroupDeployment: 13:18:01 - Error: Code=InvalidTemplateDeployment; Message=The template deployment 'patch' is not valid according to the validation procedure. The tracking id is '4319f427-c159-48fa-9885-7ac00f22a512'. See inner errors for details.
New-AzResourceGroupDeployment: 13:18:01 - Error: Code=MaintenanceRPTemplateValidationFailed; Message=The template failed MaintenanceRP validation
New-AzResourceGroupDeployment: 13:18:01 - Error: Code=InvalidRequestContent; Message=Extension properties must contain Patch mode. e.g. InGuestPatchMode = 'User' or InGuestPatchMode = 'Platform'
New-AzResourceGroupDeployment: The deployment validation failed

The property mentioned is present in the bicep template.

To Reproduce Deploy the following Bicep file.

param name string = 'azmc-develop'
param location string = 'westeurope'

@allowed([
  'Extension'
  'Host'
  'InGuestPatch'
  'OSImage'
  'Resource'
  'SQLDB'
  'SQLManagedInstance'
])
param maintenanceScope string = 'InGuestPatch'

@allowed([
  'Custom'
  'Public'
])
param visibility string = 'Custom'

@description('See https://learn.microsoft.com/en-us/azure/templates/microsoft.maintenance/maintenanceconfigurations?pivots=deployment-language-bicep#maintenancewindow for details')
param maintenanceWindows object = {
  startDateTime: '2022-11-08 00:00'
  duration: '02:00'
  timeZone: 'W. Europe Standard Time'
  recurEvery: '2Week Wednesday'
}

param installPatches object = {
  classificationsToInclude: [
    'Critical'
    'Security'
    'Updates'
  ]
  LinuxParameters: {
    classificationsToInclude: [
      'Critical'
      'Security'
    ]
  }
}

@allowed([
  'User'
  'Platform'
])
param inGuestPatchMode string = 'User'

resource patchConfiguration 'Microsoft.Maintenance/maintenanceConfigurations@2022-07-01-preview' = {
  name: name
  location: location
  properties: {
    extensionProperties: {
      inGuestPatchMode: inGuestPatchMode
    }
    installPatches: installPatches
    maintenanceScope: maintenanceScope
    maintenanceWindow: maintenanceWindows
    visibility: visibility
  }
}

Additional context Creating a maintenance configuration through the portal and capturing the data, does show that property there, with the same name.

{
    "requests": [
        {
            "content": {
                "properties": {
                    "mode": "incremental",
                    "debugSetting": {
                        "detailLevel": "none"
                    },
                    "parameters": {
                        "maintenanceConfigName": {
                            "value": "developtest2"
                        },
                        "maintenanceConfigLocation": {
                            "value": "westeurope"
                        },
                        "maintenanceSchedule": {
                            "value": {
                                "startDateTime": "2022-11-08 00:00",
                                "duration": "03:55",
                                "timeZone": "W. Europe Standard Time",
                                "expirationDateTime": null,
                                "recurEvery": "1Day"
                            }
                        },
                        "maintenanceScope": {
                            "value": "InGuestPatch"
                        }
                    },
                    "template": {
                        "$schema": "http://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
                        "contentVersion": "1.0.0.0",
                        "parameters": {
                            "maintenanceConfigName": {
                                "type": "String",
                                "metadata": {
                                    "description": "This is name of the maintenance config being created."
                                }
                            },
                            "maintenanceConfigLocation": {
                                "type": "String",
                                "metadata": {
                                    "description": "This is location of the maintenance config being created."
                                }
                            },
                            "maintenanceSchedule": {
                                "type": "Object",
                                "metadata": {
                                    "description": "This is schedule information associated with the Maintenance configuration."
                                }
                            },
                            "maintenanceScope": {
                                "type": "String",
                                "metadata": {
                                    "description": "Gets or sets maintenanceScope of the configuration."
                                }
                            }
                        },
                        "resources": [
                            {
                                "type": "Microsoft.Maintenance/maintenanceConfigurations",
                                "apiVersion": "2021-09-01-preview",
                                "name": "[parameters('maintenanceConfigName')]",
                                "location": "[parameters('maintenanceConfigLocation')]",
                                "tags": {},
                                "properties": {
                                    "maintenanceScope": "InGuestPatch",
                                    "installPatches": {
                                        "linuxParameters": {
                                            "classificationsToInclude": [
                                                "Critical",
                                                "Security"
                                            ],
                                            "packageNameMasksToExclude": null,
                                            "packageNameMasksToInclude": null
                                        },
                                        "windowsParameters": {
                                            "classificationsToInclude": [
                                                "Critical",
                                                "Security"
                                            ],
                                            "kbNumbersToExclude": null,
                                            "kbNumbersToInclude": null
                                        },
                                        "rebootSetting": "RebootIfRequired"
                                    },
                                    "extensionProperties": {
                                        "InGuestPatchMode": "User"
                                    },
                                    "maintenanceWindow": {
                                        "startDateTime": "2022-11-08 00:00",
                                        "duration": "03:55",
                                        "timeZone": "W. Europe Standard Time",
                                        "expirationDateTime": null,
                                        "recurEvery": "1Day"
                                    }
                                }
                            }
                        ]
                    }
                },
                "tags": {
                    "marketplaceItemId": "Microsoft.Template"
                }
            },
            "httpMethod": "POST",
            "name": "4eb4332b-2adf-4168-aacf-d6b200ce3034",
            "requestHeaderDetails": {
                "commandName": "Microsoft_Azure_CreateUIDef.Deploy.validate"
            },
            "url": "/subscriptions/..../resourceGroups/...../providers/Microsoft.Resources/deployments/Microsoft.Template-20221108132501/validate?api-version=2020-06-01"
        }
    ]
}
alex-frankel commented 1 year ago

This validation is coming from the Microsoft.Maintenance/maintenanceConfigurations resource provider, not from bicep. It looks like you're including the property they are claiming is not there, so I would open a support ticket to see what is happening. The ticket should be routed to the Microsoft.Maintenance resource provider. This may be a case of this RP incorrectly evaluating a template language expression.

ghost commented 1 year ago

Hi LeonB87, this issue has been marked as stale because it was labeled as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment. Thanks for contributing to bicep! :smile: :mechanical_arm: