Repository: microsoft/onefuzz
File: src/ApiService/ApiService/onefuzzlib/VmOperations.cs (C#)

Code before:
        try {
            var vm = await _context.Creds.GetResourceGroupResource().GetVirtualMachineAsync(
                vmName
            );

            return (await vm.Value.GetVirtualMachineExtensionAsync(extensionName)).Value.Data;
        } catch (RequestFailedException ex) {
            _logTracer.Info($"extension does not exist {ex}");
            return null;
        }
    }

    public async Async.Task CreateExtension(string vmName, string extensionName, VirtualMachineExtensionData extension) {
        _logTracer.Info($"creating extension: {_context.Creds.GetBaseResourceGroup()}:{vmName}:{extensionName}");
        var vm = await _context.Creds.GetResourceGroupResource().GetVirtualMachineAsync(vmName);

        try {
            await vm.Value.GetVirtualMachineExtensions().CreateOrUpdateAsync(
                WaitUntil.Started,
                extensionName,
                extension
            );
        } catch (RequestFailedException ex) when
            (ex.Status == 409 &&
                (ex.Message.Contains("VM is marked for deletion") || ex.Message.Contains("The request failed due to conflict with a concurrent request."))) {
            _logTracer.Info(ex.Message);
        }
        return;
    }

    async Task<OneFuzzResultVoid> CreateVm(
        string name,
        Region location,
        string vmSku,
        string image,
        string password,
        string sshPublicKey,
        Nsg? nsg,
        IDictionary<string, string>? tags
    ) {
        var resourceGroup = _context.Creds.GetBaseResourceGroup();
        _logTracer.Info($"creating vm {resourceGroup}:{location}:{name}");

        var nic = await _context.IpOperations.GetPublicNic(resourceGroup, name);
        if (nic == null) {
            var result = await _context.IpOperations.CreatePublicNic(resourceGroup, name, location, nsg);
            if (!result.IsOk) {
                return result;
            }

            _logTracer.Info("waiting on nic creation");

Review comment (bug):
```suggestion
            _logTracer.Info($"Tried to create extension but failed due to {ex.Message}");
```

So we know what the message is about

Code after:
        try {
            var vm = await _context.Creds.GetResourceGroupResource().GetVirtualMachineAsync(
                vmName
            );

            return (await vm.Value.GetVirtualMachineExtensionAsync(extensionName)).Value.Data;
        } catch (RequestFailedException ex) {
            _logTracer.Info($"extension does not exist {ex}");
            return null;
        }
    }

    public async Async.Task CreateExtension(string vmName, string extensionName, VirtualMachineExtensionData extension) {
        _logTracer.Info($"creating extension: {_context.Creds.GetBaseResourceGroup()}:{vmName}:{extensionName}");
        var vm = await _context.Creds.GetResourceGroupResource().GetVirtualMachineAsync(vmName);

        try {
            await vm.Value.GetVirtualMachineExtensions().CreateOrUpdateAsync(
                WaitUntil.Started,
                extensionName,
                extension
            );
        } catch (RequestFailedException ex) when
            (ex.Status == 409 &&
                (ex.Message.Contains("VM is marked for deletion") || ex.Message.Contains("The request failed due to conflict with a concurrent request."))) {
            _logTracer.Info($"Tried to create extension but failed due to {ex.Message}");
        }
        return;
    }

    async Task<OneFuzzResultVoid> CreateVm(
        string name,
        Region location,
        string vmSku,
        string image,
        string password,
        string sshPublicKey,
        Nsg? nsg,
        IDictionary<string, string>? tags
    ) {
        var resourceGroup = _context.Creds.GetBaseResourceGroup();
        _logTracer.Info($"creating vm {resourceGroup}:{location}:{name}");

        var nic = await _context.IpOperations.GetPublicNic(resourceGroup, name);
        if (nic == null) {
            var result = await _context.IpOperations.CreatePublicNic(resourceGroup, name, location, nsg);
            if (!result.IsOk) {
                return result;
            }

            _logTracer.Info("waiting on nic creation");