azure - 来自 SIG 的 Microsoft Azure 托管应用程序 ARM 模板

标签 azure azure-devops azure-resource-manager azure-cli

我在使用我创建的共享镜像作为基础时,无法从 ARM 模板创建托管应用程序。 该图像存储在我的 SIG 中。 下面的代码来 self 的 mainTemplate.json:

"storageProfile": {
      "imageReference": {
        "offer": "TESTOFFER ",
        "publisher": "TESTPUB ",
        "sku": "1.0.0",
        "id ": "/subscriptions/<subid>/resourceGroups/managed_gallery/providers/Microsoft.Compute/galleries/managed_gallery_instance/images/gallery_image/versions/1.0.0"
      },
      "osDisk": {
        "createOption": "fromImage"
      }

在我的目标资源组中,创建了 nsg、ip、nic、nsg 和 vnet,只有虚拟机失败。 这是我在 azure 门户中得到的错误输出:

{
  "code": "DeploymentFailed",
  "message": "At least one resource deployment operation failed. Please list deployment operations for details. Please see https://aka.ms/DeployOperations for usage details.",
  "details": [
    {
      "code": "BadRequest",
      "message": "Could not find member 'id ' on object of type 'ImageReference'. Path 'properties.storageProfile.imageReference['id ']', line 1, position 1101."
    }
  ]
}

我找到了this article在没有说明任何用法的文档中。 我做了很多谷歌搜索,但没有找到任何适合我的案例的好例子。

这是否就是将自定义图像传递给妈妈的预期方式? 我很感激任何建议。

提前致谢!

编辑
这是整个 ARM 模板:

{
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "projectName": {
            "type": "string",
            "defaultValue": "managedApp",
            "metadata": {
                "description": "Specifies a name for generating resource names."
            }
        },
        "location": {
            "type": "string",
            "defaultValue": "[resourceGroup().location]",
            "metadata": {
                "description": "Specifies the location for all resources."
            }
        },
        "adminUsername": {
            "type": "string",
            "defaultValue": "azureAdmin",
            "metadata": {
                "description": "Specifies a username for the Virtual Machine."
            }
        },
        "adminPublicKey": {
            "type": "string",
            "defaultValue": "KEY",
            "metadata": {
                "description": "Specifies the SSH rsa public key file as a string. Use \"ssh-keygen -t rsa -b 2048\" to generate your SSH key pairs."
            }
        }
    },
    "variables": {
        "vNetName": "[concat(parameters('projectName'), '-vnet')]",
        "vNetAddressPrefixes": "10.0.0.0/16",
        "vNetSubnetName": "default",
        "vNetSubnetAddressPrefix": "10.0.0.0/24",
        "vmName": "[concat(parameters('projectName'), '-vm')]",
        "publicIPAddressName": "[concat(parameters('projectName'), '-ip')]",
        "networkInterfaceName": "[concat(parameters('projectName'), '-nic')]",
        "networkSecurityGroupName": "[concat(parameters('projectName'), '-nsg')]",
        "networkSecurityGroupName2": "[concat(variables('vNetSubnetName'), '-nsg')]"
    },
    "resources": [
        {
            "type": "Microsoft.Network/networkSecurityGroups",
            "apiVersion": "2020-05-01",
            "name": "[variables('networkSecurityGroupName')]",
            "location": "[parameters('location')]",
            "properties": {
                "securityRules": [
                    {
                        "name": "ssh_rule",
                        "properties": {
                            "description": "Locks inbound down to ssh default port 22.",
                            "protocol": "Tcp",
                            "sourcePortRange": "*",
                            "destinationPortRange": "22",
                            "sourceAddressPrefix": "*",
                            "destinationAddressPrefix": "*",
                            "access": "Allow",
                            "priority": 123,
                            "direction": "Inbound"
                        }
                    }
                ]
            }
        },
        {
            "type": "Microsoft.Network/publicIPAddresses",
            "apiVersion": "2020-05-01",
            "name": "[variables('publicIPAddressName')]",
            "location": "[parameters('location')]",
            "properties": {
                "publicIPAllocationMethod": "Dynamic"
            },
            "sku": {
                "name": "Basic"
            }
        },
        {
            "comments": "Simple Network Security Group for subnet [variables('vNetSubnetName')]",
            "type": "Microsoft.Network/networkSecurityGroups",
            "apiVersion": "2020-05-01",
            "name": "[variables('networkSecurityGroupName2')]",
            "location": "[parameters('location')]",
            "properties": {
                "securityRules": [
                    {
                        "name": "default-allow-22",
                        "properties": {
                            "priority": 1000,
                            "access": "Allow",
                            "direction": "Inbound",
                            "destinationPortRange": "22",
                            "protocol": "Tcp",
                            "sourceAddressPrefix": "*",
                            "sourcePortRange": "*",
                            "destinationAddressPrefix": "*"
                        }
                    }
                ]
            }
        },
        {
            "type": "Microsoft.Network/virtualNetworks",
            "apiVersion": "2020-05-01",
            "name": "[variables('vNetName')]",
            "location": "[parameters('location')]",
            "dependsOn": [
                "[resourceId('Microsoft.Network/networkSecurityGroups', variables('networkSecurityGroupName2'))]"
            ],
            "properties": {
                "addressSpace": {
                    "addressPrefixes": [
                        "[variables('vNetAddressPrefixes')]"
                    ]
                },
                "subnets": [
                    {
                        "name": "[variables('vNetSubnetName')]",
                        "properties": {
                            "addressPrefix": "[variables('vNetSubnetAddressPrefix')]",
                            "networkSecurityGroup": {
                                "id": "[resourceId('Microsoft.Network/networkSecurityGroups', variables('networkSecurityGroupName2'))]"
                            }
                        }
                    }
                ]
            }
        },
        {
            "type": "Microsoft.Network/networkInterfaces",
            "apiVersion": "2020-05-01",
            "name": "[variables('networkInterfaceName')]",
            "location": "[parameters('location')]",
            "dependsOn": [
                "[resourceId('Microsoft.Network/publicIPAddresses', variables('publicIPAddressName'))]",
                "[resourceId('Microsoft.Network/virtualNetworks', variables('vNetName'))]",
                "[resourceId('Microsoft.Network/networkSecurityGroups', variables('networkSecurityGroupName'))]"
            ],
            "properties": {
                "ipConfigurations": [
                    {
                        "name": "ipconfig1",
                        "properties": {
                            "privateIPAllocationMethod": "Dynamic",
                            "publicIPAddress": {
                                "id": "[resourceId('Microsoft.Network/publicIPAddresses', variables('publicIPAddressName'))]"
                            },
                            "subnet": {
                                "id": "[resourceId('Microsoft.Network/virtualNetworks/subnets', variables('vNetName'), variables('vNetSubnetName'))]"
                            }
                        }
                    }
                ]
            }
        },
        {
            "type": "Microsoft.Compute/virtualMachines",
            "apiVersion": "2019-12-01",
            "name": "[variables('vmName')]",
            "location": "[parameters('location')]",
            "dependsOn": [
                "[resourceId('Microsoft.Network/networkInterfaces', variables('networkInterfaceName'))]"
            ],
            "properties": {
                "osProfile": {
                    "computerName": "[variables('vmName')]",
                    "adminUsername": "[parameters('adminUsername')]",
                    "linuxConfiguration": {
                        "disablePasswordAuthentication": true,
                        "ssh": {
                            "publicKeys": [
                                {
                                    "path": "[concat('/home/', parameters('adminUsername'), '/.ssh/authorized_keys')]",
                                    "keyData": "[parameters('adminPublicKey')]"
                                }
                            ]
                        }
                    }
                },
                "storageProfile": {
                    "imageReference": {
                        "id ": "id"
                    },
                    "osDisk": {
                        "createOption": "fromImage"
                    }
                },
                "networkProfile": {
                    "networkInterfaces": [
                        {
                            "id": "[resourceId('Microsoft.Network/networkInterfaces', variables('networkInterfaceName'))]"
                        }
                    ]
                }
            }
        }
    ]
}

最佳答案

可能需要查看模板的其余部分,但如果您想使用磁盘的托管镜像,“id”属性是您提供的唯一属性(删除发布商、报价、sku)。

该错误听起来好像您可能遇到多个问题,但这只是一个开始。

更新

对虚拟机上的属性节点尝试此操作:

"properties": {
    "hardwareProfile": {
        "vmSize": "Standard_D2ds_v4"
    },
    "osProfile": {
        "computerName": "[variables('vmName')]",
        "adminUsername": "[parameters('adminUsername')]",
        "linuxConfiguration": {
            "disablePasswordAuthentication": true,
            "ssh": {
                "publicKeys": [
                    {
                        "path": "[concat('/home/', parameters('adminUsername'), '/.ssh/authorized_keys')]",
                        "keyData": "[parameters('adminPublicKey')]"
                    }
                ]
            }
        }
    },
    "storageProfile": {
        "imageReference": {
            "id": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/galleries/{galleryName}/images/{imageName}/versions/{version}"
        }
    },
    "networkProfile": {
        "networkInterfaces": [
            {
                "id": "[resourceId('Microsoft.Network/networkInterfaces', variables('networkInterfaceName'))]"
            }
        ]
    }
}

我所做的更改:

  • 您需要具有 vmSize 的硬件配置文件
  • 删除 osDisk 属性
  • 删除 imageReferenceid 属性名称中的空格

关于azure - 来自 SIG 的 Microsoft Azure 托管应用程序 ARM 模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68482715/

相关文章:

ruby-on-rails - 如何在 Azure 应用服务上安排 Rails rake 任务

azure - 通过ARM模板在存储帐户中部署多个容器

c# - 代码契约(Contract) - Visual Studio Team Service 脚本生成服务器单元测试失败

Docker 更新旧的 pem 文件

javascript - Azure Devops 本地授权错误 401

azure - 如何使用 ARM 模板创建 CosmosDB SQL API 无服务器帐户?

azure - 应如何使 Azure 资源管理器 JSON 与 Azure 门户保持一致?

Azure 存储模拟器无法安装

azure - 使用 Azure 存储资源管理器查询将实体数据更新到 Azure 存储表

Azure 搜索 - 分区不足响应错误