首页 > 解决方案 > ARM 模板创建存储帐户和应用服务时出错

问题描述

是否可以使用 ARM 模板在同一资源组中创建服务计划、应用服务和存储帐户?,当我尝试此操作时,我收到下一个错误:

Azure 错误:InvalidTemplateDeployment 消息:根据验证过程,模板部署“XXXX”无效。跟踪 ID 为“XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXX”。有关详细信息,请参阅内部错误。异常详细信息:错误代码:PreflightValidationCheckFailed 消息:预检验证失败。具体错误请参考详细信息。

但是如果我使用不同的资源组和不同的模板,这个效果很好。

完整的 ARM 模板是:

    {
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "webAppName": {
            "type": "String",
            "metadata": {
                "description": "The App Service name."
            }
        },
        "sku": {
            "type": "string",
            "defaultValue": "F1",
            "metadata": {
                "description": "The SKU of App Service Plan."
            }
        },
        "storageAccountName": {
            "type": "string",
            "metadata": {
                "description": "The Storage Account name."
            }
        }
    },
    "variables": {
        "appServicePlanName": "[concat('AppServicePlan-', parameters('webAppName'))]",
        "location": "[resourceGroup().location]"
    },
    "resources": [
        //App services plan
        {
            "apiVersion": "2020-06-01",
            "type": "Microsoft.Web/serverfarms",
            "name": "[variables('appServicePlanName')]",
            "location": "[variables('location')]",
            "sku": {
                "name": "[parameters('sku')]"
            },
            "properties": {
                    "name": "[variables('appServicePlanName')]"
            }
        },
        //App Service
        {
            "type": "Microsoft.Web/sites",
            "apiVersion": "2018-11-01",
            "name": "[parameters('webAppName')]",
            "location": "[variables('location')]",
            "kind": "app",
            "dependsOn": [
                "[resourceId('Microsoft.Web/serverfarms', variables('appServicePlanName'))]"
            ],
            "properties": {
                "enabled": true,
                "hostNameSslStates": [
                    {
                        "name": "[concat(parameters('webAppName'),'.azurewebsites.net')]",
                        "sslState": "Disabled",
                        "hostType": "Standard"
                    },
                    {
                        "name": "[concat(parameters('webAppName'),'.scm.azurewebsites.net')]",
                        "sslState": "Disabled",
                        "hostType": "Repository"
                    }
                ],
                "reserved": false,
                "isXenon": false,
                "hyperV": false,
                "siteConfig": {},
                "scmSiteAlsoStopped": false,
                "clientAffinityEnabled": true,
                "clientCertEnabled": false,
                "hostNamesDisabled": false,
                "containerSize": 0,
                "dailyMemoryTimeQuota": 0,
                "httpsOnly": false,
                "redundancyMode": "None"
            }
        },
        {
            "type": "Microsoft.Web/sites/config",
            "apiVersion": "2018-11-01",
            "name": "[concat(parameters('webAppName'), '/web')]",
            "location": "[variables('location')]",
            "dependsOn": [
                "[resourceId('Microsoft.Web/sites', parameters('webAppName'))]"
            ],
            "properties": {
                "numberOfWorkers": 1,
                "defaultDocuments": [
                    "Default.htm",
                    "Default.html",
                    "Default.asp",
                    "index.htm",
                    "index.html",
                    "iisstart.htm",
                    "default.aspx",
                    "index.php",
                    "hostingstart.html"
                ],
                "netFrameworkVersion": "v2.0",
                "requestTracingEnabled": false,
                "remoteDebuggingEnabled": false,
                "httpLoggingEnabled": false,
                "logsDirectorySizeLimit": 35,
                "detailedErrorLoggingEnabled": false,
                "publishingUsername": "$AdAstraflexSurveyWebAppTest",
                "azureStorageAccounts": {},
                "scmType": "None",
                "use32BitWorkerProcess": true,
                "webSocketsEnabled": false,
                "alwaysOn": false,
                "managedPipelineMode": "Integrated",
                "virtualApplications": [
                    {
                        "virtualPath": "/",
                        "physicalPath": "site\\wwwroot",
                        "preloadEnabled": false
                    }
                ],
                "loadBalancing": "LeastRequests",
                "experiments": {
                    "rampUpRules": []
                },
                "autoHealEnabled": false,
                "localMySqlEnabled": false,
                "ipSecurityRestrictions": [
                    {
                        "ipAddress": "Any",
                        "action": "Allow",
                        "priority": 1,
                        "name": "Allow all",
                        "description": "Allow all access"
                    }
                ],
                "scmIpSecurityRestrictions": [
                    {
                        "ipAddress": "Any",
                        "action": "Allow",
                        "priority": 1,
                        "name": "Allow all",
                        "description": "Allow all access"
                    }
                ],
                "scmIpSecurityRestrictionsUseMain": false,
                "http20Enabled": false,
                "minTlsVersion": "1.2",
                "ftpsState": "AllAllowed",
                "reservedInstanceCount": 0
            }
        },
        {
            "type": "Microsoft.Web/sites/hostNameBindings",
            "apiVersion": "2018-11-01",
            "name": "[concat(parameters('webAppName'), '/', parameters('webAppName'), '.azurewebsites.net')]",
            "location": "[variables('location')]",
            "dependsOn": [
                "[resourceId('Microsoft.Web/sites', parameters('webAppName'))]"
            ],
            "properties": {
                "siteName": "AdAstraflexSurveyWebAppTest",
                "hostNameType": "Verified"
            }
        },
        //Storage Accounts
        {
            "name": "[parameters('storageAccountName')]",
            "type": "Microsoft.Storage/storageAccounts",
            "apiVersion": "2020-08-01-preview",
            "sku": 
            {
                "name": "Standard_RAGRS",
                "tier": "Standard"
            },
            "kind": "StorageV2",
            "location": "[variables('location')]",
            
            "properties": 
            {
                "minimumTlsVersion": "TLS1_2",
                "allowBlobPublicAccess": true,
                "networkAcls": 
                {
                    "bypass": "AzureServices",
                    "virtualNetworkRules": [],
                    "ipRules": [],
                    "defaultAction": "Allow"
                },
                "supportsHttpsTrafficOnly": true,
                "encryption": 
                {
                    "services": 
                    {
                        "file": 
                        {
                            "keyType": "Account",
                            "enabled": true
                        },
                        "blob": 
                        {
                            "keyType": "Account",
                            "enabled": true
                        }
                    },
                    "keySource": "Microsoft.Storage"
                },
                "accessTier": "Hot"
            }
        }
    ]
}

标签: azureazure-resource-managerarm-templateazure-appserviceazure-storage-account

解决方案


我试过你的模板,对我来说效果很好。您可以稍后使用新资源组或以下模板尝试。

{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
    "webAppName": {
        "type": "String",
        "metadata": {
            "description": "The App Service name."
        }
    },
    "sku": {
        "type": "string",
        "defaultValue": "F1",
        "metadata": {
            "description": "The SKU of App Service Plan."
        }
    },
    "storageAccountName": {
        "type": "string",
        "metadata": {
            "description": "The Storage Account name."
        }
    }
},
"variables": {
    "appServicePlanName": "[concat('AppServicePlan-', parameters('webAppName'))]",
    "location": "[resourceGroup().location]"
},
"resources": [
    //App services plan
    {
        "apiVersion": "2020-06-01",
        "type": "Microsoft.Web/serverfarms",
        "name": "[variables('appServicePlanName')]",
        "location": "[variables('location')]",
        "sku": {
            "name": "[parameters('sku')]"
        },
        "properties": {
                "name": "[variables('appServicePlanName')]"
        }
    },
    //App Service
    {
        "type": "Microsoft.Web/sites",
        "apiVersion": "2018-11-01",
        "name": "[parameters('webAppName')]",
        "location": "[variables('location')]",
        "kind": "app",
        "dependsOn": [
            "[resourceId('Microsoft.Web/serverfarms', variables('appServicePlanName'))]"
        ],
        "properties": {
            "enabled": true,
            "hostNameSslStates": [
                {
                    "name": "[concat(parameters('webAppName'),'.azurewebsites.net')]",
                    "sslState": "Disabled",
                    "hostType": "Standard"
                },
                {
                    "name": "[concat(parameters('webAppName'),'.scm.azurewebsites.net')]",
                    "sslState": "Disabled",
                    "hostType": "Repository"
                }
            ],
            "reserved": false,
            "isXenon": false,
            "hyperV": false,
            "siteConfig": {},
            "scmSiteAlsoStopped": false,
            "clientAffinityEnabled": true,
            "clientCertEnabled": false,
            "hostNamesDisabled": false,
            "containerSize": 0,
            "dailyMemoryTimeQuota": 0,
            "httpsOnly": false,
            "redundancyMode": "None"
        }
    },
    {
        "type": "Microsoft.Web/sites/config",
        "apiVersion": "2018-11-01",
        "name": "[concat(parameters('webAppName'), '/web')]",
        "location": "[variables('location')]",
        "dependsOn": [
            "[resourceId('Microsoft.Web/sites', parameters('webAppName'))]"
        ],
        "properties": {
            "numberOfWorkers": 1,
            "defaultDocuments": [
                "Default.htm",
                "Default.html",
                "Default.asp",
                "index.htm",
                "index.html",
                "iisstart.htm",
                "default.aspx",
                "index.php",
                "hostingstart.html"
            ],
            "netFrameworkVersion": "v2.0",
            "requestTracingEnabled": false,
            "remoteDebuggingEnabled": false,
            "httpLoggingEnabled": false,
            "logsDirectorySizeLimit": 35,
            "detailedErrorLoggingEnabled": false,
            "publishingUsername": "$AdAstraflexSurveyWebAppTest",
            "azureStorageAccounts": {},
            "scmType": "None",
            "use32BitWorkerProcess": true,
            "webSocketsEnabled": false,
            "alwaysOn": false,
            "managedPipelineMode": "Integrated",
            "virtualApplications": [
                {
                    "virtualPath": "/",
                    "physicalPath": "site\\wwwroot",
                    "preloadEnabled": false
                }
            ],
            "loadBalancing": "LeastRequests",
            "experiments": {
                "rampUpRules": []
            },
            "autoHealEnabled": false,
            "localMySqlEnabled": false,
            "ipSecurityRestrictions": [
                {
                    "ipAddress": "Any",
                    "action": "Allow",
                    "priority": 1,
                    "name": "Allow all",
                    "description": "Allow all access"
                }
            ],
            "scmIpSecurityRestrictions": [
                {
                    "ipAddress": "Any",
                    "action": "Allow",
                    "priority": 1,
                    "name": "Allow all",
                    "description": "Allow all access"
                }
            ],
            "scmIpSecurityRestrictionsUseMain": false,
            "http20Enabled": false,
            "minTlsVersion": "1.2",
            "ftpsState": "AllAllowed",
            "reservedInstanceCount": 0
        }
    },
    {
        "type": "Microsoft.Web/sites/hostNameBindings",
        "apiVersion": "2018-11-01",
        "name": "[concat(parameters('webAppName'), '/', parameters('webAppName'), '.azurewebsites.net')]",
        "location": "[variables('location')]",
        "dependsOn": [
            "[resourceId('Microsoft.Web/sites', parameters('webAppName'))]"
        ],
        "properties": {
            "siteName": "AdAstraflexSurveyWebAppTest",
            "hostNameType": "Verified"
        }
    },
    //Storage Accounts
    {
        "name": "[parameters('storageAccountName')]",
        "type": "Microsoft.Storage/storageAccounts",
        "apiVersion": "2020-08-01-preview",
        "sku": 
        {
            "name": "Standard_RAGRS",
            "tier": "Standard"
        },
        "kind": "StorageV2",
        "location": "[variables('location')]",
        
        "properties": 
        {
            "minimumTlsVersion": "TLS1_2",
            "allowBlobPublicAccess": true,
            "networkAcls": 
            {
                "bypass": "AzureServices",
                "virtualNetworkRules": [],
                "ipRules": [],
                "defaultAction": "Allow"
            },
            "supportsHttpsTrafficOnly": true,
            "encryption": 
            {
                "services": 
                {
                    "file": 
                    {
                        "keyType": "Account",
                        "enabled": true
                    },
                    "blob": 
                    {
                        "keyType": "Account",
                        "enabled": true
                    }
                },
                "keySource": "Microsoft.Storage"
            },
            "accessTier": "Hot"
        }
    }
]
}

在此处输入图像描述


推荐阅读