为VM分配公共IP的ARM模板错误

时间:2019-02-07 15:42:16

标签: templates arm

您好,已为VM部署编写了JSON代码,但是在IPconfiguration中分配公共IP地址时遇到错误。 错误信息 部署模板验证失败:行'123'和列'9'处的模板资源'[Parameters('envPrefixName')]-NetworkInterface'无效:无法解析语言表达式'resourceId('Microsoft.Network/publicIPAddresses' ,'[[Parameters('envPrefixName')]-PublicIP')':预期标记'RightParenthesis'和实际的'Identifier'。请参见https://aka.ms/arm-template-expressions了解用法详细信息。 (代码:InvalidTemplate)

{     “ $ schema”:“ https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#”,     “ contentVersion”:“ 1.0.0.0”,     “参数”:{

    "scriptURL": {
        "type":"string"

    },
    "adminUsername": {
        "type":"string"
    },
    "adminPassword": {
        "type":"string"
    },

    "envPrefixName": {
        "type": "string",
        "metadata": {
            "description": "Prefix for the environment (2-5 characters)"
        },
        "defaultValue": "cust1",
        "minLength": 2,
        "maxLength": 5
    }
},
"variables": {
   "scriptURL":" https://raw.githubusercontent.com/rt7055/simpledevbox1/master/simpledevbox.ps1 "
},
"resources": [
    {
        "type": "Microsoft.Storage/storageAccounts",
        "name": "[Parameters('envPrefixName')]-storagekata",
        "apiVersion": "2015-06-15",
        "location": "[resourceGroup().location]",
        "tags": {
            "displayName": "[Parameters('envPrefixName')] Storage Account"
        },
        "properties": {
            "accountType":"Standard_LRS"
        }
    },
    {
        "apiVersion": "2017-06-01",
        "type": "Microsoft.Network/publicIPAddresses",
        "name": "[Parameters('envPrefixName')]-PublicIP",
        "location": "[resourceGroup().location]",
        "properties":{
            "publicIPAllocationMethod":"Dynamic"
        },
        "tags": {
            "displayName": "PublicIPAddress"
        }
    },
         {
        "apiVersion": "2017-06-01",
        "type": "Microsoft.Network/virtualNetworks",
        "name": "[Parameters('envPrefixName')]-VirtualNetwork",
        "location": "[resourceGroup().location]",
        "tags": {
            "displayName": "VirtualNetwork"
        },
        "properties": {
            "addressSpace": {
                "addressPrefixes": [
                    "10.0.0.0/16"
                ]
            },
            "subnets": [
                {
                    "name": "[Parameters('envPrefixName')]-VirtualNetwork-Subnet",
                    "properties": {
                        "addressPrefix": "10.0.0.0/24"
                    }
                }
            ]
        }
    },
    {
        "apiVersion": "2017-06-01",
        "type": "Microsoft.Network/networkSecurityGroups",
        "name": "[Parameters('envPrefixName')]-securitygroup",
        "location": "[resourceGroup().location]",
        "tags": {
            "displayName": "FrontEndNSG"
        },
        "properties": {
            "securityRules": [
                {
                    "name": "rdp_rule",
                    "properties": {
                        "description": "Allow RDP",
                        "protocol": "Tcp",
                        "sourcePortRange": "*",
                        "destinationPortRange": "3389",
                        "sourceAddressPrefix": "Internet",
                        "destinationAddressPrefix": "*",
                        "access": "Allow",
                        "priority": 100,
                        "direction": "Inbound"
                    }
                }
              ]
            }
        },


    {
        "apiVersion": "2015-06-15",
        "type": "Microsoft.Network/networkInterfaces",
        "name": "[Parameters('envPrefixName')]-NetworkInterface",
        "location": "[resourceGroup().location]",
        "dependsOn": [
            "Microsoft.Network/publicIPAddresses/[Parameters('envPrefixName')]-PublicIP",
            "Microsoft.Network/virtualNetworks/[Parameters('envPrefixName')]-VirtualNetwork"
        ],
        "tags": {
            "displayName": "[Parameters('envPrefixName')] Network Interface"
        },
        "properties": {
            "ipConfigurations": [
                {
                    "name": "ipconfig1",
                    "properties": {
                        "privateIPAllocationMethod": "Dynamic",
                        "publicIPAddress": {
                            "id": "[resourceId('Microsoft.Network/publicIPAddresses', '[Parameters('envPrefixName')]-PublicIP')]"
                        },
                        "subnet": {
                            "id": "[concat(resourceId('Microsoft.Network/virtualNetworks', '[Parameters('envPrefixName')]-VirtualNetwork'), '/subnets/[Parameters('envPrefixName')]-VirtualNetwork-Subnet')]"
                        }
                    }
                }
            ]
        }
    },
                       {
        "apiVersion": "2017-03-30",
        "type": "Microsoft.Compute/virtualMachines",
        "name": "[Parameters('envPrefixName')]",
        "location": "[resourceGroup().location]",
        "dependsOn": [
            "[concat('Microsoft.Storage/storageAccounts/', toLower('[Parameters('envPrefixName')]storagekata'))]",
            "Microsoft.Network/networkInterfaces/[Parameters('envPrefixName')]-NetworkInterface"
        ],
        "tags": {
            "displayName": "[Parameters('envPrefixName')]"
        },
        "properties": {
            "hardwareProfile": {
                "vmSize":"Standard_A1"
            },
            "osProfile": {
                "computerName": "[Parameters('envPrefixName')]",
                "adminUsername": "[parameters('adminUsername')]",
                "adminPassword": "[parameters('adminPassword')]"
            },
            "storageProfile": {
                "imageReference": {
                    "publisher": "MicrosoftWindowsServer",
                    "offer": "WindowsServer",
                    "sku": "2012-R2-Datacenter",
                    "version": "latest"
                },
                "osDisk": {
                    "name": "[Parameters('envPrefixName')]OSDisk",
                    "createOption": "FromImage",
                    "caching": "ReadWrite"

                                    }                 
            },
            "networkProfile": {
                "networkInterfaces": [
                    {
                        "id": "[resourceId('Microsoft.Network/networkInterfaces', '[Parameters('envPrefixName')]-NetworkInterface')]"
                    }
                ]
            },
            "diagnosticsProfile": {
                "bootDiagnostics": {
                    "enabled": true,
                    "storageUri": "[concat('http://', toLower('[Parameters('envPrefixName')]storagekata'), '.blob.core.windows.net')]"
                }
            }
        },
        "resources": [
            {
                "apiVersion": "2017-03-30",
                "type": "extensions",
                "name": "config-app",
                "location": "[resourceGroup().location]",
                "dependsOn": [
                    "[concat('Microsoft.Compute/virtualMachines/', '[Parameters('envPrefixName')]vm1')]"
                ],
                "tags": {
                    "displayName": "config-app"
                },
                "properties": {
                    "publisher": "Microsoft.Compute",
                    "type": "CustomScriptExtension",
                    "typeHandlerVersion": "1.9",
                    "autoUpgradeMinorVersion": true,
                    "settings": {
                        "fileUris": [
                           "[variables('scriptURL')]"
                        ]
                    },
                    "protectedSettings": {
                        "commandToExecute": "[concat('powershell -ExecutionPolicy Unrestricted -File ', './simpledevbox.ps1')]"
                    }
                }
            }
        ]
    }
],
"outputs": {}

}

应该使用公共IP。

有人可以帮助我解决这个问题

0 个答案:

没有答案