Azure / bicep

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

decompile failure - Sequence contains more than one element #14573

Open dkirrane opened 1 month ago

dkirrane commented 1 month ago

Bicep version run bicep --version via the Bicep CLI, az bicep version via the AZ CLI or via VS code by navigating to the extensions tab and searching for Bicep Bicep CLI version 0.28.1 (ba1e9f8c1e)

Describe the bug A clear and concise description of what the bug is vs what you expected to happen

I'm trying to convert the ARM template from Step 1 here to Bicep

az bicep decompile --file template.json

It fails with Decompilation failed with fatal error "Sequence contains more than one element"

alex-frankel commented 1 month ago

Template from Step 1:

{
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {

                 "customRdpPort": {
                    "type": "string",
                    "defaultValue": "3389",
                    "metadata": {
                        "description": "If you wish to use a different port to RDP into the VM (between 0 and 65535), change it here, otherwise, leave the default."
                    }
                 },

                "virtualMachineName": {
                    "type": "string",
                    "defaultValue": "AzSHCIHost001",
                    "metadata": {
                        "description": "Keep the VM name to less than 15 characters"
                    }
                },
                "virtualMachineSize": {
                    "type": "string",
                    "defaultValue": "Standard_E16s_v4",
                    "allowedValues": [
                        "Standard_D16s_v3",
                        "Standard_D32s_v3",
                        "Standard_D64s_v3",
                        "Standard_D16s_v4",
                        "Standard_D32s_v4",
                        "Standard_D64s_v4",
                        "Standard_D16d_v4",
                        "Standard_D32d_v4",
                        "Standard_D64d_v4",
                        "Standard_D16ds_v4",
                        "Standard_D32ds_v4",
                        "Standard_D64ds_v4",
                        "Standard_E8s_v3",
                        "Standard_E16s_v3",
                        "Standard_E16-4s_v3",
                        "Standard_E16-8s_v3",
                        "Standard_E20s_v3",
                        "Standard_E32s_v3",
                        "Standard_E32-8s_v3",
                        "Standard_E32-16s_v3",
                        "Standard_E48s_v3",
                        "Standard_E64s_v3",
                        "Standard_E64-16s_v3",
                        "Standard_E64-32s_v3",
                        "Standard_E8s_v4",
                        "Standard_E16s_v4",
                        "Standard_E16-8s_v4",
                        "Standard_E20s_v4",
                        "Standard_E32s_v4",
                        "Standard_E32-8s_v4",
                        "Standard_E32-16s_v4",
                        "Standard_E48s_v4",
                        "Standard_E64s_v4",
                        "Standard_E64-16s_v4",
                        "Standard_E64-32s_v4",
                        "Standard_E8d_v4",
                        "Standard_E16d_v4",
                        "Standard_E20d_v4",
                        "Standard_E32d_v4",
                        "Standard_E48d_v4",
                        "Standard_E64d_v4",
                        "Standard_E8ds_v4",
                        "Standard_E16ds_v4",
                        "Standard_E20ds_v4",
                        "Standard_E32ds_v4",
                        "Standard_E48ds_v4",
                        "Standard_E64ds_v4",
                        "Standard_E64-16ds_v4",
                        "Standard_E64-32ds_v4"
                    ]
                },
                "virtualMachineGeneration": {
                    "type": "string",
                    "defaultValue": "Generation 2",
                    "allowedValues": [
                        "Generation 1",
                        "Generation 2"
                    ],
                    "metadata": {
                        "description": "Select your VM generation, ideally Gen 2. Not all Azure regions support Gen 2 VMs."
                    }
                },

                "dataDiskType": {
                    "type": "string",
                    "defaultValue": "StandardSSD_LRS",
                    "allowedValues": [
                        "StandardSSD_LRS",
                        "Premium_LRS"
                    ],
                    "metadata": {
                        "description": "The Storage type of the VM data disk. If your VM contains an 's' in the VM size, you can select Premium_LRS storage for increased performance, but at a higher cost."
                    }
                },
                "dataDiskSize": {
                    "type": "int",
                    "defaultValue": 256,
                    "allowedValues": [
                        256,
                        512,
                        1024
                    ],
                    "metadata": {
                        "description": "The size of the individual data disks in GiB. 8 of these will be provisioned therefore 256GiB is the recommended default."
                    }
                },
                "adminUsername": {
                    "type": "string",
                    "defaultValue": "AzureUser"
                },
                "adminPassword": {
                    "type": "securestring"
                },

                "autoShutdownStatus": {
                    "type": "string",
                    "defaultValue": "Enabled",
                    "allowedValues": [
                        "Enabled",
                        "Disabled"
                    ]
                },
                "autoShutdownTime": {
                    "type": "string",
                    "defaultValue": "22:00"
                },
                "autoShutdownTimeZone": {
                    "type": "string",
                    "defaultValue": "UTC",
                    "allowedValues": [
                        "Afghanistan Standard Time",
                        "Alaskan Standard Time",
                        "Aleutian Standard Time",
                        "Altai Standard Time",
                        "Arab Standard Time",
                        "Arabian Standard Time",
                        "Arabic Standard Time",
                        "Argentina Standard Time",
                        "Astrakhan Standard Time",
                        "Atlantic Standard Time",
                        "AUS Central Standard Time",
                        "Aus Central W. Standard Time",
                        "AUS Eastern Standard Time",
                        "Azerbaijan Standard Time",
                        "Azores Standard Time",
                        "Bahia Standard Time",
                        "Bangladesh Standard Time",
                        "Belarus Standard Time",
                        "Bougainville Standard Time",
                        "Canada Central Standard Time",
                        "Cape Verde Standard Time",
                        "Caucasus Standard Time",
                        "Cen. Australia Standard Time",
                        "Central America Standard Time",
                        "Central Asia Standard Time",
                        "Central Brazilian Standard Time",
                        "Central Europe Standard Time",
                        "Central European Standard Time",
                        "Central Pacific Standard Time",
                        "Central Standard Time",
                        "Central Standard Time (Mexico)",
                        "Chatham Islands Standard Time",
                        "China Standard Time",
                        "Cuba Standard Time",
                        "Dateline Standard Time",
                        "E. Africa Standard Time",
                        "E. Australia Standard Time",
                        "E. Europe Standard Time",
                        "E. South America Standard Time",
                        "Easter Island Standard Time",
                        "Eastern Standard Time",
                        "Eastern Standard Time (Mexico)",
                        "Egypt Standard Time",
                        "Ekaterinburg Standard Time",
                        "Fiji Standard Time",
                        "FLE Standard Time",
                        "Georgian Standard Time",
                        "GMT Standard Time",
                        "Greenland Standard Time",
                        "Greenwich Standard Time",
                        "GTB Standard Time",
                        "Haiti Standard Time",
                        "Hawaiian Standard Time",
                        "India Standard Time",
                        "Iran Standard Time",
                        "Israel Standard Time",
                        "Jordan Standard Time",
                        "Kaliningrad Standard Time",
                        "Korea Standard Time",
                        "Libya Standard Time",
                        "Line Islands Standard Time",
                        "Lord Howe Standard Time",
                        "Magadan Standard Time",
                        "Magallanes Standard Time",
                        "Marquesas Standard Time",
                        "Mauritius Standard Time",
                        "Middle East Standard Time",
                        "Montevideo Standard Time",
                        "Morocco Standard Time",
                        "Mountain Standard Time",
                        "Mountain Standard Time (Mexico)",
                        "Myanmar Standard Time",
                        "N. Central Asia Standard Time",
                        "Namibia Standard Time",
                        "Nepal Standard Time",
                        "New Zealand Standard Time",
                        "Newfoundland Standard Time",
                        "Norfolk Standard Time",
                        "North Asia East Standard Time",
                        "North Asia Standard Time",
                        "North Korea Standard Time",
                        "Omsk Standard Time",
                        "Pacific SA Standard Time",
                        "Pacific Standard Time",
                        "Pacific Standard Time (Mexico)",
                        "Pakistan Standard Time",
                        "Paraguay Standard Time",
                        "Romance Standard Time",
                        "Russia Time Zone 10",
                        "Russia Time Zone 11",
                        "Russia Time Zone 3",
                        "Russian Standard Time",
                        "SA Eastern Standard Time",
                        "SA Pacific Standard Time",
                        "SA Western Standard Time",
                        "Saint Pierre Standard Time",
                        "Sakhalin Standard Time",
                        "Samoa Standard Time",
                        "Sao Tome Standard Time",
                        "Saratov Standard Time",
                        "SE Asia Standard Time",
                        "Singapore Standard Time",
                        "South Africa Standard Time",
                        "Sri Lanka Standard Time",
                        "Sudan Standard Time",
                        "Syria Standard Time",
                        "Taipei Standard Time",
                        "Tasmania Standard Time",
                        "Tocantins Standard Time",
                        "Tokyo Standard Time",
                        "Tomsk Standard Time",
                        "Tonga Standard Time",
                        "Transbaikal Standard Time",
                        "Turkey Standard Time",
                        "Turks And Caicos Standard Time",
                        "Ulaanbaatar Standard Time",
                        "US Eastern Standard Time",
                        "US Mountain Standard Time",
                        "UTC",
                        "UTC-02",
                        "UTC-08",
                        "UTC-09",
                        "UTC-11",
                        "UTC+12",
                        "UTC+13",
                        "Venezuela Standard Time",
                        "Vladivostok Standard Time",
                        "W. Australia Standard Time",
                        "W. Central Africa Standard Time",
                        "W. Europe Standard Time",
                        "W. Mongolia Standard Time",
                        "West Asia Standard Time",
                        "West Bank Standard Time",
                        "West Pacific Standard Time",
                        "Yakutsk Standard Time"
                    ]
                },
                "alreadyHaveAWindowsServerLicense": {
                    "type": "string",
                    "defaultValue": "No",
                    "allowedValues": [
                        "Yes",
                        "No"
                    ],
                    "metadata": {
                        "description": "By selecting Yes, you confirm you have an eligible Windows Server license with Software Assurance or Windows Server subscription to apply this Azure Hybrid Benefit. You can read more about compliance here: http://go.microsoft.com/fwlink/?LinkId=859786"
                    }
                }
        },
    "functions": [],
    "variables": {
                "dataDisksCount": 8,
                "dscUri": "https://github.com/microsoft/AzStackHCISandbox/blob/main/DSC/ashcihost.zip?raw=true",
                "artifactsLocation": "https://raw.githubusercontent.com/microsoft/AzStackHCISandbox/evalguide-Redesign-Work-Godfrey/",
                "randomGUID": "[substring(uniqueString(subscription().subscriptionId, resourceGroup().id, parameters('virtualMachineName')),0,6)]",
                "dnsNameForPublicIP": "[toLower(concat(parameters('virtualMachineName'), variables('randomGUID')))]",
                "virtualNetworkName": "AzSHCILabvNet",
                "networkInterfaceName": "AzSHCILabNIC1",
                "networkSecurityGroupName": "AzSHCILabNSG",
                "addressPrefix": "10.0.0.0/16",
                "privateIPAddress": "10.0.0.4",
                "subnetName": "AzSHCILabSubnet",
                "subnetPrefix": "10.0.0.0/24",
                "publicIpAddressName": "AzSHCILabPubIP",
                "publicIpAddressType": "Dynamic",
                "publicIpAddressSku": "Basic",
               // "nsgId": "[resourceId(resourceGroup().name, 'Microsoft.Network/networkSecurityGroups', variables('networkSecurityGroupName'))]",
                "vnetId": "[resourceId(resourceGroup().name,'Microsoft.Network/virtualNetworks', variables('virtualNetworkName'))]",
                "subnetRef": "[concat(variables('vnetId'), '/subnets/', variables('subnetName'))]"

            },
    "resources": [

            {
            "name": "[variables('publicIpAddressName')]",
            "type": "Microsoft.Network/publicIpAddresses",
            "apiVersion": "2020-11-01",
            "location": "[resourceGroup().location]",
            "sku": {
                "name": "[variables('publicIpAddressSku')]"
            },
            "properties": {
                "publicIpAllocationMethod": "[variables('publicIpAddressType')]",
                "dnsSettings": {
                    "domainNameLabel": "[variables('dnsNameForPublicIP')]"
                }
            }
        },
        {
            "type": "Microsoft.Resources/deployments",
            "apiVersion": "2021-04-01",
            "name": "[variables('virtualNetworkName')]",
            "properties": {
                "mode": "Incremental",
                "templateLink": {
                    "uri": "[uri(variables('artifactsLocation'),'json/vnet.json')]",
                    "contentVersion": "1.0.0.0"
                },
                "parameters": {
                    "virtualNetworkName": {
                        "value": "[variables('virtualNetworkName')]"
                    },
                    "virtualNetworkAddressRange": {
                        "value": "[variables('addressPrefix')]"
                    },
                    "subnetName": {
                        "value": "[variables('subnetName')]"
                    },
                    "subnetRange": {
                        "value": "[variables('subnetPrefix')]"
                    },
                    "location": {
                        "value": "[resourceGroup().location]"
                    }
                }
            }
        },
        {
            "name": "[variables('networkInterfaceName')]",
            "type": "Microsoft.Network/networkInterfaces",
            "apiVersion": "2020-11-01",
            "location": "[resourceGroup().location]",
            "dependsOn": [
                "[variables('virtualNetworkName')]",
                "[concat('Microsoft.Network/publicIpAddresses/', variables('publicIpAddressName'))]",
                "[concat('Microsoft.Network/networkSecurityGroups/', variables('networkSecurityGroupName'))]"
            ],
            "properties": {
                "ipConfigurations": [
                    {
                        "name": "ipconfig1",
                        "properties": {
                            "subnet": {
                                "id": "[variables('subnetRef')]"
                            },
                            "privateIPAllocationMethod": "Static",
                            "privateIPAddress": "[variables('privateIPAddress')]",
                            "publicIpAddress": {
                                "id": "[resourceId('Microsoft.Network/publicIpAddresses', variables('publicIpAddressName'))]"
                            }
                        }
                    }
                ],
                "networkSecurityGroup": {
                    "id": "[resourceId('Microsoft.Network/networkSecurityGroups', variables('networkSecurityGroupName'))]"
                }
            }
        },
        {
            "name": "[variables('networkSecurityGroupName')]",
            "type": "Microsoft.Network/networkSecurityGroups",
            "apiVersion": "2020-11-01",
            "location": "[resourceGroup().location]",
            "properties": {
                "securityRules": [
                    {
                        "name": "rdp",
                        "properties": {
                            "priority": 1000,
                            "protocol": "Tcp",
                            "access": "Deny",
                            "direction": "Inbound",
                            "sourceAddressPrefix": "*",
                            "sourcePortRange": "*",
                            "destinationAddressPrefix": "*",
                            "destinationPortRange": "[parameters('customRdpPort')]"
                        }
                    }
                ]
            }
        },

    {
            "name": "[parameters('virtualMachineName')]",
            "type": "Microsoft.Compute/virtualMachines",
            "apiVersion": "2020-12-01",
            "location": "[resourceGroup().location]",
            "dependsOn": [
                "[concat('Microsoft.Network/networkInterfaces/', variables('networkInterfaceName'))]"
            ],
            "properties": {
                "hardwareProfile": {
                    "vmSize": "[parameters('virtualMachineSize')]"
                },
                "storageProfile": {
                    "imageReference": {
                        "publisher": "MicrosoftWindowsServer",
                        "offer": "WindowsServer",
                        "sku": "[if(equals(parameters('virtualMachineGeneration'), 'Generation 2'), '2022-datacenter-azure-edition', '2022-datacenter-g2')]",
                        "version": "latest"
                    },
                    "osDisk": {
                        "createOption": "FromImage",
                        "managedDisk": {
                            "storageAccountType": "Standard_LRS"
                        }
                    },
                    "copy": [
                        {
                            "name": "dataDisks",
                            "count": "[variables('dataDisksCount')]",
                            "input": {
                                "name": "[concat(parameters('virtualMachineName'),'DataDisk',copyIndex('dataDisks'))]",
                                "diskSizeGB": "[parameters('dataDiskSize')]",
                                "lun": "[copyIndex('dataDisks')]",
                                "createOption": "Empty",
                                "caching": "None",
                                "managedDisk": {
                                    "storageAccountType": "[parameters('dataDiskType')]"
                                }
                            }
                        }
                    ]
                },
               "networkProfile": {
                    "networkInterfaces": [
                        {
                            "id": "[resourceId('Microsoft.Network/networkInterfaces', variables('networkInterfaceName'))]"
                        }
                    ]
                },
                "osProfile": {
                    "computerName": "[parameters('virtualMachineName')]",
                    "adminUsername": "[parameters('adminUsername')]",
                    "adminPassword": "[parameters('adminPassword')]",
                    "windowsConfiguration": {
                        "provisionVmAgent": true
                    }
                },
               "diagnosticsProfile": {
                    "bootDiagnostics": {
                        "enabled": true
                    }
                },
                "licenseType": "[if(equals(parameters('alreadyHaveAWindowsServerLicense'), 'Yes'), 'Windows_Server', 'None')]"
            },
            "resources":[
                    {
                    "type": "extensions",
                    "name": "ConfigureAsHciHost",
                    "apiVersion": "2018-06-01",
                    "location": "[resourceGroup().location]",
                    "dependsOn": [
                        "[parameters('virtualMachineName')]" ],
                    "properties": {
                        "publisher": "Microsoft.Powershell",
                        "type": "DSC",
                        "typeHandlerVersion": "2.77",
                        "autoUpgradeMinorVersion": true,
                        "settings": {
                            "wmfVersion": "latest",
                            "configuration": {
                                "url": "[variables('dscUri')]",
                                "script": "ashcihost.ps1",
                                "function": "ASHCIHost"
                            },
                            "configurationArguments": {
                                "customRdpPort": "[parameters('customRdpPort')]"
                            }
                        },
                        "protectedSettings": {
                            "configurationArguments": {
                                "adminCreds": {
                                    "UserName": "[parameters('adminUsername')]",
                                    "Password": "[parameters('adminPassword')]"
                                }
                            }
                        }
                    }
                }
            ]

        },

        {
            "name": "[concat('shutdown-computevm-', parameters('virtualMachineName'))]",
            "type": "Microsoft.DevTestLab/schedules",
            "apiVersion": "2018-09-15",
            "location": "[resourceGroup().location]",
            "properties": {
                "status": "[parameters('autoShutdownStatus')]",
                "taskType": "ComputeVmShutdownTask",
                "dailyRecurrence": {
                    "time": "[parameters('autoShutdownTime')]"
                },
                "timeZoneId": "[parameters('autoShutdownTimeZone')]",
                "targetResourceId": "[resourceId('Microsoft.Compute/virtualMachines', parameters('virtualMachineName'))]"
            },
            "dependsOn": [
                "[concat('Microsoft.Compute/virtualMachines/', parameters('virtualMachineName'))]"
            ]
        }
    ],
    "outputs": {
        "adminUsername": {
            "type": "string",
            "value": "[parameters('adminUsername')]"
        },
        "rdpPort": {
            "type": "string",
            "value": "[parameters('customRdpPort')]"
        },
        "fqdn": {
            "value": "[reference(resourceId('Microsoft.Network/publicIPAddresses',variables('publicIPAddressName'))).dnsSettings.fqdn]",
            "type": "string"
        }
    }
}