AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 1015755
Accepted
Danslerr
Danslerr
Asked: 2020-05-06 06:54:35 +0800 CST2020-05-06 06:54:35 +0800 CST 2020-05-06 06:54:35 +0800 CST

在现有 vnet 中创建新 VM、子网和 NSG 时出错

  • 772

我正在尝试使用新 NSG 在新子网中部署新虚拟机,但在部署模板时出现错误。

我们是一家 MSP,为我们的客户构建名为“SoftWare”的自定义软件,我们希望将其托管在 Azure 中。

我目前的设置如下*:

  • 名为 Contoso.Cloud 的资源组
  • 一个虚拟网络也名为 Contoso.Cloud,地址空间为 10.2.0.0/16
  • 一个子网,它托管我们的后端服务,如 Active Directory 等,前缀为 10.2.10.0/24。
  • 所有资源都部署在同一个资源组中

我使用此模板的目标是在每次创建新客户端 VM 时在 Contoso.Cloud vnet 中部署新子网和 NSG。

*出于安全原因,对姓名进行了消毒

这是我的模板:

{
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "adminUsername": {
            "type": "String",
            "metadata": {
                "description": "Username for the Virtual Machine."
            }
        },
        "adminPassword": {
            "type": "SecureString",
            "metadata": {
                "description": "Password for the Virtual Machine."
            }
        },
        "vmSize": {
            "defaultValue": "Standard_F2s_v2",
            "allowedValues": [
                "Standard_F2s_v2",
                "Standard_F4s_v2"
            ],
            "type": "String",
            "metadata": {
                "description": "Size of the virtual machine."
            }
        },
        "clientCode": {
            "type": "String",
            "metadata": {
                "description": "Please enter the ID of the clinic."
            }
        },
        "clientName": {
            "type": "String",
            "metadata": {
                "description": "Please enter the code of the clinic."
            }
        },
        "addressPrefix": {
            "defaultValue": "10.2.0.0/16",
            "allowedValues": [
                "10.2.0.0/16"
            ],
            "type": "String",
            "metadata": {
                "description": "Please enter the vnet address prefix here."
            }
        },
        "subnetPrefix": {
            "type": "String",
            "metadata": {
                "description": "Please enter the subnet prefix here."
            }
        }
    },
    "variables": {
        "storageAccountName": "ContosoStorageTST",
        "nicName": "[concat(toLower(variables('vmName')), '-', uniqueString(resourceGroup().id))]",
        "addressPrefix": "[parameters('addressPrefix')]",
        "subnetName": "[concat(parameters('clientCode'), '_', parameters('clientName'))]",
        "subnetPrefix": "[parameters('subnetPrefix')]",
        "vmName": "[concat(parameters('clientCode'), '-SoftWare1')]",
        "virtualNetworkName": "Contoso.Cloud",
        "subnetRef": "[resourceId('Microsoft.Network/virtualNetworks/subnets', variables('virtualNetworkName'), variables('subnetName'))]",
        "networkSecurityGroupName": "[concat('SoftWare-NSG-', parameters('clientCode'))]",
        "backendSubnet": "10.2.10.0/24",
        "location": "West Europe"
    },
    "resources": [
        {
            "type": "Microsoft.Storage/storageAccounts",
            "apiVersion": "2018-11-01",
            "name": "[variables('storageAccountName')]",
            "location": "[variables('location')]",
            "sku": {
                "name": "Standard_LRS"
            },
            "kind": "Storage",
            "properties": {}
        },
        {
            "type": "Microsoft.Network/networkSecurityGroups",
            "apiVersion": "2019-08-01",
            "name": "[variables('networkSecurityGroupName')]",
            "location": "[variables('location')]",
            "properties": {
                "securityRules": [
                    {
                        "name": "allow_RDP_in",
                        "properties": {
                            "protocol": "tcp",
                            "sourcePortRange": "*",
                            "destinationPortRange": "3389",
                            "sourceAddressPrefix": "*",
                            "destinationAddressPrefix": "[parameters('subnetPrefix')]",
                            "access": "Allow",
                            "priority": 500,
                            "direction": "Inbound"
                        }
                    },
                    {
                        "name": "allow_core_to_client",
                        "properties": {
                            "protocol": "*",
                            "sourcePortRange": "*",
                            "destinationPortRange": "22",
                            "sourceAddressPrefix": "[variables('backendSubnet')]",
                            "destinationAddressPrefix": "*",
                            "access": "Allow",
                            "priority": 501,
                            "direction": "Inbound"
                        }
                    },
                    {
                        "name": "allow_client_to_core",
                        "properties": {
                            "protocol": "*",
                            "sourcePortRange": "*",
                            "destinationPortRange": "*",
                            "sourceAddressPrefix": "[parameters('subnetPrefix')]",
                            "destinationAddressPrefix": "[variables('backendSubnet')]",
                            "access": "Allow",
                            "priority": 502,
                            "direction": "Outbound"
                        }
                    },
                    {
                        "name": "deny_client_to_other_clients",
                        "properties": {
                            "protocol": "*",
                            "sourcePortRange": "*",
                            "destinationPortRange": "*",
                            "sourceAddressPrefix": "[variables('addressPrefix')]",
                            "destinationAddressPrefix": "[variables('addressPrefix')]",
                            "access": "Deny",
                            "priority": 4000,
                            "direction": "Outbound"
                        }
                    }
                ]
            }
        },
        {
            "type": "Microsoft.Network/virtualNetworks/subnets",
            "apiVersion": "2018-04-01",
            "name": "[concat(variables('virtualNetworkName'), '/', variables('subnetName'))]",
            "location": "[variables('location')]",
            "dependsOn": [
                "[resourceId('Microsoft.Network/networkSecurityGroups/', variables('networkSecurityGroupName'))]"
            ],
            "properties": {
                "addressPrefix": "[variables('subnetPrefix')]",
                "networkSecurityGroup": "[variables('networkSecurityGroupName')]"
            }
        },
        {
            "type": "Microsoft.Network/networkInterfaces",
            "apiVersion": "2018-11-01",
            "name": "[variables('nicName')]",
            "location": "[variables('location')]",
            "dependsOn": [
                "[concat('/subscriptions/<subscription-ID>/resourceGroups/SoftWare.Cloud/providers/Microsoft.Network/virtualNetworks/SoftWare.Cloud/subnets/', variables('subnetName'))]"

            ],
            "properties": {
                "ipConfigurations": [
                    {
                        "name": "ipconfig1",
                        "properties": {
                            "privateIPAllocationMethod": "Dynamic",
                            "subnet": {
                                "id": "[variables('subnetRef')]"
                            }
                        }
                    }
                ]
            }
        },
        {
            "type": "Microsoft.Compute/virtualMachines",
            "apiVersion": "2018-10-01",
            "name": "[variables('vmName')]",
            "location": "[variables('location')]",
            "dependsOn": [
                "[resourceId('Microsoft.Storage/storageAccounts/', variables('storageAccountName'))]",
                "[resourceId('Microsoft.Network/networkInterfaces/', variables('nicName'))]",
                "[concat('/subscriptions/<subscription-ID>/resourceGroups/SoftWare.Cloud/providers/Microsoft.Network/virtualNetworks/SoftWare.Cloud/subnets/', variables('subnetName'))]"
            ],
            "properties": {
                "hardwareProfile": {
                    "vmSize": "[parameters('vmSize')]"
                },
                "osProfile": {
                    "computerName": "[variables('vmName')]",
                    "adminUsername": "[parameters('adminUsername')]",
                    "adminPassword": "[parameters('adminPassword')]"
                },
                "storageProfile": {
                    "imageReference": {
                        "id": "[resourceId('Microsoft.Compute/images', 'SoftWare1-IMAGE-Roles ')]"
                    },
                    "osDisk": {
                        "createOption": "FromImage"
                    }
                },
                "networkProfile": {
                    "networkInterfaces": [
                        {
                            "id": "[resourceId('Microsoft.Network/networkInterfaces',variables('nicName'))]"
                        }
                    ]
                },
                "diagnosticsProfile": {
                    "bootDiagnostics": {
                        "enabled": false,
                        "storageUri": "[reference(resourceId('Microsoft.Storage/storageAccounts/', variables('storageAccountName'))).primaryEndpoints.blob]"
                    }
                }
            }
        }
    ]
}

这些是我的参数:

{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "adminUsername": {
      "value": "admin-local"
    },
    "adminPassword": {
      "value": "myPassword,"
    },
    "vmSize": {
      "value": "Standard_F2s_v2"
    },
    "clientCode": {
      "value": "TST01"
    },
    "clientName": {
      "value": "TST-Example"
    },
    "addressPrefix": {
      "value": "10.2.0.0/16"
    },
    "subnetPrefix": {
      "value": "10.2.20.0/28"
    }
  }
}

我得到的错误是:

 "Cannot parse the request. (Code: InvalidRequestFormat)
    - Value for reference id is missing. Path properties.networkSecurityGroup. (Code: MissingJasonReferenceId)

这使我相信我需要在部署子网时对 NSG 进行额外的引用,但在每个示例模板中我发现这不会发生。当我使用不同的模板仅部署子网而不使用 NSG 时,它会顺利进行。

另一个问题可能是在网络接口上没有指定 vnet,但是当我查看示例时,他们唯一做的就是使用“dependsOn”选项,该选项仅在 vnet 与网络接口。然而,情况并非如此。

azure azure-arm-template
  • 1 1 个回答
  • 313 Views

1 个回答

  • Voted
  1. Best Answer
    Sam Cogan
    2020-05-06T23:56:45+08:002020-05-06T23:56:45+08:00

    您的问题是子网配置中的这一行:

    "networkSecurityGroup": "[variables('networkSecurityGroupName')]"
    

    您需要 NSG 的完整资源 ID,而不是名称。

    将其更改为

    "networkSecurityGroup": "[resourceId('Microsoft.Network/networkSecurityGroups',variables('networkSecurityGroupName'))]"
    
    • 0

相关问题

  • 防火墙更改后失去对 VM azure 的 RDP 访问权限

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve