Azure / Azure/azure-rest-api-specs

[BUG] VirtualMachineRunCommands_Update PATCH method will update whole resource

Open
#28,173 2 comments 0 reactions 1 assignee Claimed by @grizzlytheodore View on GitHub
bug Mgmt
Dominant language
TypeSpec
Stars
3.1k
Forks
5.9k
Avg merge
2d 22h
Merged PRs (30d)
444

Description

### API Spec link

https://github.com/Azure/azure-rest-api-specs/blob/1a011ff0d72315ef3c530fe545c4fe82d0450201/specification/compute/resource-manager/Microsoft.Compute/ComputeRP/stable/2023-03-01/runCommand.json#L324

### API Spec version

2023-03-01

### Describe the bug

The REST API PATCH method is supposed to update part of the resource, in other words, if you send a PATCH request to update a resource, the server will only update the specified fields in the existing resource. However the `VirtualMachineRunCommands_Update` method will update the whole resource.
If omit `properties.source` in PATCH request payload, send payload like below one, the `properties.source` is updated to empty.
```json
{
"location": "westeurope",
"properties": {
"protectedParameters": [
{
"name": "a",
"value": "1"
}
],
"parameters": [
{
"name": "b",
"value": "1"
}
],
"timeoutInSeconds": 0,
"asyncExecution": false,
"treatFailureAsDeploymentFailure": true
}
}
```

### Expected behavior

if omit `properties.source` in PATCH request payload, the `properties.source` should be kept.

### Actual behavior

if omit `properties.source` in PATCH request payload, send payload like below one, the `properties.source` is updated to empty.
```
{
"location": "westeurope",
"properties": {
"protectedParameters": [
{
"name": "a",
"value": "1"
}
],
"parameters": [
{
"name": "b",
"value": "1"
}
],
"timeoutInSeconds": 0,
"asyncExecution": false,
"treatFailureAsDeploymentFailure": true
}
}
```

### Reproduction Steps

STEP 1 -- PUT https://management.azure.com/subscriptions/{{subscriptionId}}/resourceGroups/example-resources/providers/Microsoft.Compute/virtualMachines/example-VM/runCommands/example1-vmrc?api-version=2023-03-01&$expand=instanceView

x-ms-request-id: 30ae8dcc-b6d3-47fa-8190-1af1a787ebf8
x-ms-correlation-request-id: c5313ffc-2c9b-4b84-9285-ee6e3ed84646

request:
```json
{
"location": "westeurope",
"properties": {
"source": {
"script": "echo 'hello'"
},
"protectedParameters": [
{
"name": "a",
"value": "1"
}
],
"parameters": [
{
"name": "b",
"value": "1"
}
],
"timeoutInSeconds": 0,
"asyncExecution": false,
"treatFailureAsDeploymentFailure": true
}
}
```

STEP 2 -- GET https://management.azure.com/subscriptions/{{subscriptionId}}/resourceGroups/example-resources/providers/Microsoft.Compute/virtualMachines/example-VM/runCommands/example1-vmrc?api-version=2023-03-01&$expand=instanceView

x-ms-request-id: 576eb9e5-6dd6-4049-a882-9ed356b9e70e
x-ms-correlation-request-id: 5fb94928-3779-4f81-8e56-30a01836272b

note that `protectedParameters` is by design not returned.

response:
```json
{
"name": "example1-vmrc",
"id": "/subscriptions/xxx/resourceGroups/example-resources/providers/Microsoft.Compute/virtualMachines/example-VM/runCommands/example1-vmrc",
"type": "Microsoft.Compute/virtualMachines/runCommands",
"location": "westeurope",
"properties": {
"source": {
"script": "echo 'hello'"
},
"parameters": [
{
"name": "b",
"value": "1"
}
],
"timeoutInSeconds": 0,
"provisioningState": "Succeeded",
"asyncExecution": false,
"instanceView": {
"exitCode": 0,
"executionState": "Succeeded",
"executionMessage": "Execution completed",
"output": "hello\n",
"error": "",
"startTime": "2024-03-08T09:22:43+00:00",
"endTime": "2024-03-08T09:22:43+00:00"
},
"treatFailureAsDeploymentFailure": true
}
}
```

STEP 3 -- PATCH https://management.azure.com/subscriptions/{{subscriptionId}}/resourceGroups/example-resources/providers/Microsoft.Compute/virtualMachines/example-VM/runCommands/example1-vmrc?api-version=2023-03-01&$expand=instanceView

x-ms-request-id: ddd68723-7ca8-4748-b375-ce2d79c2908f
x-ms-correlation-request-id: fbf162da-e91f-4517-851e-a123d07a6b2e

request:
```json
{
"location": "westeurope",
"properties": {
"protectedParameters": [
{
"name": "a",
"value": "3"
}
],
"timeoutInSeconds": 0,
"asyncExecution": false,
"treatFailureAsDeploymentFailure": true
}
}
```

STEP 4 -- GET https://management.azure.com/subscriptions/{{subscriptionId}}/resourceGroups/example-resources/providers/Microsoft.Compute/virtualMachines/example-VM/runCommands/example1-vmrc?api-version=2023-03-01&$expand=instanceView

x-ms-request-id: f927a894-1ee3-4e3d-a26c-716b1f7f4c1e
x-ms-correlation-request-id: 46827455-b8e7-43aa-beab-3a11f3f9d60e

we can see the `source` and `parameters` are updated to empty

response:
```json
{
"name": "example1-vmrc",
"id": "/subscriptions/xxx/resourceGroups/example-resources/providers/Microsoft.Compute/virtualMachines/example-VM/runCommands/example1-vmrc",
"type": "Microsoft.Compute/virtualMachines/runCommands",
"location": "westeurope",
"properties": {
"source": {},
"timeoutInSeconds": 0,
"provisioningState": "Succeeded",
"asyncExecution": false,
"instanceView": {
"exitCode": -202,
"executionState": "Failed",
"executionMessage": "Execution failed: failed to get configuration: invalid configuration: Either 'source.script' or 'source.scriptUri' has to be specified",
"output": "",
"error": "",
"startTime": "2024-03-08T09:27:49+00:00",
"endTime": "2024-03-08T09:27:49+00:00"
},
"treatFailureAsDeploymentFailure": true
}
}
```

### Environment

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.