用于与现有 VNET 子网集成的应用服务的 ARM 模板



我有一个 ARM 模板,用于在现有应用计划中创建新的应用服务,以及允许访问应用服务标识的新密钥保管库。我还想将现有的 VNET/子网添加到应用服务,但我没有任何运气。脚本运行,但 VNET/子网未绑定到应用服务。感谢您的任何帮助。

{
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"subscriptionId": {
"type": "string"
},
"name": {
"type": "string"
},
"keyVaultUserObjectId": {
"type": "string",
"defaultValue": "XXXXXXXXXXXXXXXXXXXXXX",
"metadata": {
"description": "ObjectID for user to get full rights to keyvault. Default is Henry's I account"
}
},
"hostingEnvironment": {
"type": "string"
},
"Division": {
"type": "string"
},
"OwnerName": {
"type": "string",
"defaultValue": "aValue",
"metadata": {
"description": "Used to distinquish who in is responsible for the resource"
}
},
"hostingPlanName": {
"type": "string",
"defaultValue": "hostingPlanName",
"metadata": {
"description": "Appservice Plan. Default = . Must supply one for Prod"
}
},
"environmentName": {
"type": "string",
"defaultValue": "uat",
"allowedValues": [ "uat", "qa", "prod" ],
"metadata": {
"description": "What environment will this run in"
}
},
//try to collapse this based on environment name
"environmentType": {
"type": "string",
"defaultValue": "nonProd",
"allowedValues": [ "nonProd", "prod" ],
"metadata": {
"description": "What type environment will this run in"
}
}
},
"variables": {
"suffix": "[uniqueString(resourceGroup().id,resourceGroup().location)]",
"environmentBasedValues": {
"nonProd": {
"fullDeployedName": "[tolower(substring(concat(parameters('name'),'-',substring(parameters('environmentName'),0,1),'-',variables('suffix')),0,24))]",
"keyVaultDeployedName": "[tolower(substring(concat(parameters('name'),'-',substring(parameters('environmentName'),0,1),'-',variables('suffix')),0,24))]",
"hostingPlanDeployedName": "[parameters('hostingPlanName')]", 
"serverFarmResourceGroupDeployedName": "[resourceGroup().name]" 
},
"prod": {
"fullDeployedName": "[tolower(substring(concat(parameters('name'),'-',variables('suffix')),0,24))]",
"keyVaultDeployedName": "[tolower(substring(concat(parameters('name'),'-',variables('suffix')),0,24))]",
"hostingPlanDeployedName": "[parameters('hostingPlanName')]", 
"serverFarmResourceGroupDeployedName": "[resourceGroup().name]"
}
},
"Agency": "AGENCY",
"OwnerName": "[parameters('OwnerName')]",
"alwaysOn": true,
"currentStack": "dotnetcore",
"phpVersion": "OFF",
"errorLink": "[concat('https://',variables('environmentBasedValues')[parameters('environmentType')].fullDeployedName,'.scm.azurewebsites.net/detectors?type=tools&name=eventviewer')]"
},
"resources": [
{
"apiVersion": "2016-08-01",
"name": "[variables('environmentBasedValues')[parameters('environmentType')].fullDeployedName]",
"type": "Microsoft.Web/sites",
//"location": "[parameters('location')]",
"location": "[resourceGroup().location]",
"tags": {
"Agency": "[variables('agency')]",
"OwnerName": "[variables('OwnerName')]",
"Application": "[parameters('name')]",
"Division": "[parameters('Division')]",
"Environment": "[parameters('environmentName')]"
},
"identity": {
"type": "SystemAssigned"
},
"dependsOn": [],
"properties": {
"name": "[variables('environmentBasedValues')[parameters('environmentType')].fullDeployedName]",
"siteConfig": {
"appSettings": [
{
"name": "ANCM_ADDITIONAL_ERROR_PAGE_LINK",
"value": "[variables('errorLink')]"
},
{
"name": "ASPNETCORE_ENVIRONMENT",
"value": "[parameters('environmentName')]"
}
],
"metadata": [
{
"name": "CURRENT_STACK",
"value": "[variables('currentStack')]"
}
],
"phpVersion": "[variables('phpVersion')]",
"alwaysOn": "[variables('alwaysOn')]"
},
"serverFarmId": "[concat('/subscriptions/', parameters('subscriptionId'),'/resourcegroups/', variables('environmentBasedValues')[parameters('environmentType')].serverFarmResourceGroupDeployedName, '/providers/Microsoft.Web/serverfarms/', variables('environmentBasedValues')[parameters('environmentType')].hostingPlanDeployedName)]",
"hostingEnvironment": "[parameters('hostingEnvironment')]",
"clientAffinityEnabled": true
},
"resources": [
{
"apiVersion": "2018-02-01",
"location": "[resourceGroup().location]",
"name": "virtualNetwork",
"properties": {
"subnetResourceId": "[resourceId('NetworkRG','Microsoft.Network/virtualNetworks/Subnets/','VNETNAME' ,'SUBNETNAME')]",
"swiftSupported": true
},
"type": "config",
"dependsOn": [
"[concat('Microsoft.Web/sites/', variables('environmentBasedValues')[parameters('environmentType')].fullDeployedName)]"
// "[concat(resourceId('NetworkRG','Microsoft.Network/virtualNetworks','PrimaryVNet'))]"
]
}
]
},
{
"apiVersion": "2016-10-01",
"location": "[resourceGroup().location]",
"name": "[variables('environmentBasedValues')[parameters('environmentType')].keyVaultDeployedName]",
"type": "Microsoft.KeyVault/vaults",
"tags": {
"Agency": "[variables('agency')]",
"OwnerName": "[variables('OwnerName')]",
"Application": "[parameters('name')]",
"Division": "[parameters('Division')]",
"Environment": "[parameters('environmentName')]"
},
"properties": {
"sku": {
"family": "A",
"name": "Standard"
},
"tenantId": "[subscription().tenantId]",
"accessPolicies": [
{
"tenantId": "[subscription().tenantId]",
"objectId": "[reference(resourceId('Microsoft.Web/sites', variables('environmentBasedValues')[parameters('environmentType')].fullDeployedName),'2018-11-01','Full').identity.principalId]",
"permissions": {
"keys": [],
"secrets": [ "get","list" ],
"certificates": []
}
},
{
"tenantId": "[subscription().tenantId]",
"objectId": "[parameters('keyVaultUserObjectId')]", 
"permissions": {
"keys": [ "all" ],
"secrets": [ "all" ],
"certificates": [ "all" ]
}
}
]
}
}
],
"outputs": {
"resourceGroupName": {
"type": "string",
"value": "[resourceGroup().name]"
},
"mykeyVaultUserObjectId": {
"type": "string",
"value": "[parameters('keyVaultUserObjectId')]"
},
"myAppIdentity": {
"type": "string",
"value": "[reference(resourceId('Microsoft.Web/sites', variables('environmentBasedValues')[parameters('environmentType')].fullDeployedName),'2018-11-01','Full').identity.principalId]"
},
"myFullDeployedName": {
"type": "string",
"value": "[variables('environmentBasedValues')[parameters('environmentType')].fullDeployedName]"
},
"myEnvironmentType": {
"type": "string",
"value": "[parameters('environmentType')]"
},
"myVnetID": {
"type": "string",
"value": "[concat(resourceId('NetworkRG','Microsoft.Network/virtualNetworks','VNETNAME'))]"
},
"mySubnetID": {
"type": "string",
"value": "[concat(resourceId('NetworkRG','Microsoft.Network/virtualNetworks', 'VNETNAME'), '/subnets/SUBNETNAME')]"
}
}
}

看起来上面的模板确实有效。我再次运行它并检查站点和 VNET/子网配置是否正确。我不知道我之前是否在查看缓存版本或错误的实例,但这没关系。感谢您的帮助!

最新更新