|
| 1 | +--- |
| 2 | +title: How to create a machine configuration assignment using the Azure Rest API |
| 3 | +description: >- |
| 4 | + Learn how to deploy configurations to machines with the Azure Rest API. |
| 5 | +ms.date: 03/11/2025 |
| 6 | +ms.topic: how-to |
| 7 | +ms.custom: devx-track-arm-rest-api |
| 8 | +--- |
| 9 | + |
| 10 | +# How to create a Machine Configuration Assignment using the Azure Rest API |
| 11 | + |
| 12 | +Any configuration you can perform in the Azure Portal can be performed directly via the Azure Rest API and using any HttpClient. |
| 13 | + |
| 14 | +This article shows examples for deploying built-in configurations and retrieving status reports. |
| 15 | + |
| 16 | +In each of the following sections, the example includes a **type** property where the name starts |
| 17 | +with `Microsoft.Compute/virtualMachines`. The guest configuration resource provider |
| 18 | +`Microsoft.GuestConfiguration` is an [extension resource][01] that must reference a parent type. |
| 19 | + |
| 20 | +To modify the example for other resource types such as [Arc-enabled servers][02], change the parent |
| 21 | +type to the name of the resource provider. For Arc-enabled servers, the resource provider is |
| 22 | +`Microsoft.HybridCompute/machines`. |
| 23 | + |
| 24 | +Replace the following "<>" fields with values specific to your environment: |
| 25 | + |
| 26 | +- `<base_url>` : The same for all requests, but be certain to update the provider to specify between `Microsoft.Compute/virtualMachines` or `Microsoft.HybridCompute/machines` as appropriate: |
| 27 | +```https://management.azure.com/subscriptions/<vm_Subscription>/resourceGroups/<vm_ResourceGroup>/providers/<providerType>``` |
| 28 | +- `<vm_name>`: Specify the name of the machine resource to apply the configuration on. |
| 29 | +- `<configuration_name>`: Specify the name of the configuration to apply. |
| 30 | +- `<api_version>` : Select the appropriate API-version, the newest version is `2022-01-25` |
| 31 | +## Assign a built-in configuration |
| 32 | + |
| 33 | +The following example assigns the `AuditSecureServer` built-in configuration. |
| 34 | + |
| 35 | +``` |
| 36 | +HTTP PUT https://<baseUrl>/<vm_name>/providers/Microsoft.GuestConfiguration/guestConfigurationAssignments/<configuration_Name>?api-version=2022-01-25 |
| 37 | +``` |
| 38 | + |
| 39 | +This request requires Authentication, in the format of an Authorization header. You can follow these steps to [retrieve an Azure Access Token][03]. |
| 40 | + |
| 41 | +```json |
| 42 | +Authorization Bearer <yourTokenHere> |
| 43 | +``` |
| 44 | + |
| 45 | +A request is composed of the following properties, which together make up a Machine Configuration Assignment. |
| 46 | + |
| 47 | + |
| 48 | +### Azure Resource Properties |
| 49 | + |
| 50 | +The comprise the top level of properties depicted in the sample above. |
| 51 | + |
| 52 | + |
| 53 | +```yaml |
| 54 | +Name: Name of the Built-In Machine Configuration Package |
| 55 | +Location: Location of the Hybrid Compute or Virtual Machine Resource |
| 56 | +Guest Configuration Parameters: Contains a JSON Object of additional parameters specific to Guest Configuration. |
| 57 | +``` |
| 58 | +
|
| 59 | +### Guest Configuration parameters |
| 60 | +These parameters represent the majority of a Machine Configuration Assignment and are defined as follows. |
| 61 | +
|
| 62 | +```yaml |
| 63 | +Name: Name of the Built-In Machine Configuration Package |
| 64 | +Version: Version of the Package to use. (You can use `"1.*"` to always deploy the newest version of a package) |
| 65 | +ContentUri: Required when assigning a custom Package, contains the URI of an accessible location containing the package content |
| 66 | +ContentHash: Required when assigning a custom Package |
| 67 | +ContentType: BuiltIn or Custom, automatically set by the service |
| 68 | +AssignmentType: Assigns one of the AssignmentTypes defined below |
| 69 | +ConfigurationParameters: Contains an array of parameters to pass in to the assignment. These differ per package |
| 70 | +ConfigurationSettings: Contains additional configuration options for the assignment. |
| 71 | +``` |
| 72 | +
|
| 73 | +### Assignment Type |
| 74 | +Instructions to the Guest Configuration agent as to how it should process the assignment. |
| 75 | +
|
| 76 | +```yaml |
| 77 | +Audit: Will only assess compliance with an assignment, will not attempt to make any changes |
| 78 | +ApplyAndAutoCorrect: Will continuously audit and auto-correct for compliance |
| 79 | +ApplyAndMonitor: Will apply the settings once and monitor for compliance but will not attempt to correct settings a second time |
| 80 | +ApplyOnce: Will apply the settings once but will not monitor or check for compliance thereafter |
| 81 | +``` |
| 82 | +
|
| 83 | +### Configuration Parameter |
| 84 | +An array of key-value pairs to pass into the Machine Configuration Assignment. |
| 85 | +
|
| 86 | +```yaml |
| 87 | +Name: The name of the parameter to configure |
| 88 | +Value: The desired value to set or audit for the assignment. |
| 89 | +``` |
| 90 | +
|
| 91 | +### Configuration Setting |
| 92 | +Configurable additional settings presented by Machine Configuration. |
| 93 | +```yaml |
| 94 | +ConfigurationMode: See "AssignmentType" above, supports same parameters. Must match. |
| 95 | +ActionAfterReboot: Controls the action of the Machine Configuration Agent after applying a reboot. |
| 96 | +RebootIfNeeded: If supported by the module, allows for suppressing of Restarts if a Reboot is determined to be needed |
| 97 | +``` |
| 98 | +
|
| 99 | +### Example Request |
| 100 | +
|
| 101 | +``` |
| 102 | +let baseUrl = https://management.azure.com |
| 103 | +let subscription = /subscriptions/<yourSubscription> |
| 104 | +let resourceGroup = resourceGroups/<yourResourceGroup> |
| 105 | +let provider = providers/Microsoft.Compute |
| 106 | +let vm = <yourVm> |
| 107 | + |
| 108 | +curl --request PUT \ |
| 109 | + --url '$baseUrl/$subscription/$resourceGroup$/$providers/$vm/providers/Microsoft.GuestConfiguration/guestConfigurationAssignments/AuditSecureProtocol?api-version=2022-01-25' \ |
| 110 | + --header 'authorization: Bearer yourKeyHere \ |
| 111 | + --header 'content-type: application/json' \ |
| 112 | + --data '{ |
| 113 | + "properties": { |
| 114 | + "guestConfiguration": { |
| 115 | + "kind": "Machine Configuration", |
| 116 | + "name": "AuditSecureProtocol", |
| 117 | + "version": "1.*", |
| 118 | + "contentType": "Builtin", |
| 119 | + "assignmentType": "Audit", |
| 120 | + "configurationParameter": [ |
| 121 | + { |
| 122 | + "name": "[SecureWebServer]s1;MinimumTLSVersion", |
| 123 | + "value": "1.2" |
| 124 | + } |
| 125 | + ], |
| 126 | + "configurationProtectedParameter": [], |
| 127 | + "configurationSetting": { |
| 128 | + "configurationMode": "Audit", |
| 129 | + "allowModuleOverwrite": false, |
| 130 | + "actionAfterReboot": "", |
| 131 | + "refreshFrequencyMins": 5, |
| 132 | + "rebootIfNeeded": true, |
| 133 | + "configurationModeFrequencyMins": 15 |
| 134 | + } |
| 135 | + }, |
| 136 | + "complianceStatus": "Compliant", |
| 137 | + "assignmentHash": null, |
| 138 | + "provisioningState": "Succeeded", |
| 139 | + "resourceType": null, |
| 140 | + "vmssVMList": null |
| 141 | + }, |
| 142 | + "name": "AuditSecureProtocol", |
| 143 | + "location": "westus2" |
| 144 | +}' |
| 145 | +``` |
| 146 | + |
| 147 | +### Response |
| 148 | + |
| 149 | +You will recieve a response with the created assignment, and any additional needed parameters will be automatically filled in for you. |
| 150 | + |
| 151 | +```json |
| 152 | +{ |
| 153 | + "properties": { |
| 154 | + "name": "AuditSecureProtocol", |
| 155 | + "location": "<vmLocation", |
| 156 | + "guestConfiguration": { |
| 157 | + "name": "AuditSecureProtocol", |
| 158 | + "version": "1.*", |
| 159 | + "contentType": "Builtin", |
| 160 | + "assignmentType": null, |
| 161 | + "configurationParameter": [ |
| 162 | + { |
| 163 | + "name": "[SecureWebServer]s1;MinimumTLSVersion", |
| 164 | + "value": "1.2" |
| 165 | + } |
| 166 | + ], |
| 167 | + "configurationSetting": { |
| 168 | + "configurationMode": "MonitorOnly", |
| 169 | + "allowModuleOverwrite": false, |
| 170 | + "actionAfterReboot": "", |
| 171 | + "refreshFrequencyMins": 5, |
| 172 | + "rebootIfNeeded": true, |
| 173 | + "configurationModeFrequencyMins": 15 |
| 174 | + } |
| 175 | + } |
| 176 | + }, |
| 177 | + "name": "AuditSecureProtocol", |
| 178 | + "location": "westus2" |
| 179 | +} |
| 180 | +``` |
| 181 | + |
| 182 | +<!-- Link reference definitions --> |
| 183 | +articles/app-service/configure-authentication-oauth-tokens.md |
| 184 | +[01]: /azure/azure-resource-manager/management/extension-resource-types |
| 185 | +[02]: /azure/azure-arc/servers/overview |
| 186 | +[03]: /powershell/module/az.accounts/get-azaccesstoken |
0 commit comments