简体   繁体   English

ARM 模板,用于与现有 VNET 子网集成的 Appservice

[英]ARM template for Appservice integrating with existing VNET Subnets

i have an ARM template that creates a new App Service in an existing AppPlan and a new KeyVault that allows access to the App Service's Identity.我有一个 ARM 模板,它在现有 AppPlan 中创建一个新的应用服务,以及一个允许访问应用服务标识的新 KeyVault。 I would also like to add an existing VNET/Subnet to the App Service but I am not having any luck.我还想将现有的 VNET/子网添加到应用服务,但我没有任何运气。 My script runs but the VNET/Subnet does not get tied to the App Service.我的脚本运行,但 VNET/子网未绑定到应用服务。 Thanks for any help.谢谢你的帮助。

{
  "$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')]"
    }

  }
}

It looks like the template above does work.看起来上面的模板确实有效。 I ran it again and check the site and the VNET/Subnet were configured correctly.我再次运行它并检查站点和 VNET/子网是否配置正确。 I don't know if I was looking at a cached version or the wrong instance before but this is ok.我不知道我之前查看的是缓存版本还是错误的实例,但这没关系。 Thanks for the help!谢谢您的帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM