【问题标题】:How to reference an existing storage account created in Azure portal in an ARM template如何在 ARM 模板中引用在 Azure 门户中创建的现有存储帐户
【发布时间】:2020-10-01 02:03:27
【问题描述】:

`

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "InputstorageAccount": {
            "defaultValue": "inputstgdev",
            "type": "String"
        },
        "GitrepoBranch": {
           "type": "string",
           "defaultValue": "master",
           "metadata": {
                "description": "Name of the branch to use when deploying (Default = master)."
            }
        },
        "GitrepoURL": {
           "type": "string",
           "defaultValue": "https://github.com/FBoucher/AzUnzipEverything.git",
           "metadata": {
                "description": "URL to repo (Default = master)."
            }
        },
        "InputcontainerName": {
          "type": "string",
          "defaultValue": "inputcontainer",
          "metadata": {
            "description": "Specifies the name of the blob container."
          }
        },
        "OutputstorageAccount": {
            "defaultValue": "outputstgdev",
            "type": "String"
        },
        "OutputcontainerName": {
          "type": "string",
          "defaultValue": "outputcontainer",
          "metadata": {
            "description": "Specifies the name of the blob container."
          }
        }
    },
    "variables": {},
    "resources": [
        {
            "type": "Microsoft.Storage/storageAccounts/blobServices/containers",
            "apiVersion": "2019-06-01",
            "name": "[concat(parameters('InputstorageAccount'), '/default/', parameters('InputcontainerName'))]",
            "properties": {
                "publicAccess": "None"
            }
        },
        {
            "type": "Microsoft.Storage/storageAccounts/blobServices/containers",
            "apiVersion": "2019-06-01",
            "name": "[concat(parameters('OutputstorageAccount'), '/default/', parameters('OutputcontainerName'))]",
            "properties": {
                "publicAccess": "None"
            }
        },
        {
            "name": "serviceplan",
            "type": "Microsoft.Web/serverfarms",
            "apiVersion": "2018-02-01",
            "location": "[resourceGroup().location]",
            "sku": {
                "name": "F1",
                "capacity": 1
            },
            "tags": {
                "displayName": "serviceplan"
            },
            "properties": {
                "name": "serviceplan"
            }
        },
        {
            "name": "functionapp",
            "type": "Microsoft.Web/sites",
            "apiVersion": "2018-11-01",
            "location": "[resourceGroup().location]",
            "kind": "functionapp",
            "dependsOn": [
                "[resourceId('Microsoft.Web/serverfarms', 'serviceplan')]",
                "[resourceId('Microsoft.Storage/storageAccounts', parameters('InputstorageAccount'))]"
            ],
            "properties": {
                "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', 'serviceplan')]",
                "siteConfig": {
                    "appSettings": [
                        {
                            "name": "AzureWebJobsDashboard",
                            "value": "[concat('DefaultEndpointsProtocol=https;AccountName=', parameters('InputstorageAccount'), ';AccountKey=', listKeys(parameters('InputcontainerName'),'2015-05-01-preview').key1)]"
                        },
                        {
                            "name": "AzureWebJobsStorage",
                            "value": "[concat('DefaultEndpointsProtocol=https;AccountName=', parameters('InputstorageAccount'), ';AccountKey=', listKeys(parameters('InputcontainerName'),'2015-05-01-preview').key1)]"
                        },
                        {
                            "name": "WEBSITE_CONTENTAZUREFILECONNECTIONSTRING",
                            "value": "[concat('DefaultEndpointsProtocol=https;AccountName=', parameters('InputstorageAccount'), ';AccountKey=', listKeys(parameters('InputcontainerName'),'2015-05-01-preview').key1)]"
                        },
                        {
                            "name": "WEBSITE_CONTENTSHARE",
                            "value": "[toLower('functionapp')]"
                        },
                        {
                            "name": "FUNCTIONS_EXTENSION_VERSION",
                            "value": "~2"
                        },
                        {
                            "name": "APPINSIGHTS_INSTRUMENTATIONKEY",
                            "value": "[reference(resourceId('microsoft.insights/components/', 'applicationInsightsName'), '2015-05-01').InstrumentationKey]"
                        },
                        {
                            "name": "FUNCTIONS_WORKER_RUNTIME",
                            "value": "dotnet"
                        }
                    ]
                }
            },
            "resources":[
                {
                    "apiVersion": "2015-08-01",
                    "name": "web",
                    "type": "sourcecontrols",
                    "dependsOn": [
                      "[resourceId('Microsoft.Web/sites/', parameters('InputstorageAccount'))]"
                    ],
                    "properties": {
                        "RepoUrl": "[parameters('GitrepoURL')]",
                        "branch": "[parameters('GitrepoBranch')]",
                        "publishRunbook": true,
                        "IsManualIntegration": true
                    }
                }
            ]

        }
    ]
}

`我有一个名为 STGaccount 的存储帐户,我使用 Azure 门户创建了该帐户,并希望使用 ARM 模板在此 中创建一个名为 inputcontainer 的容器STG 帐户。每次我尝试这样做时,我都会收到一条错误消息,指出我正在尝试使用 ARM 模板创建的存储帐户 STGaccount 已存在于资源组中......所以我想我正在写我的 ARM 模板仍然会创建一个新的存储帐户,其名称与我在资源组中已有的名称相似。我真正想做的是在我的 ARM 模板中引用已经存在的存储帐户,这样我就不必创建一个新的了。 提前致谢,期待您的回复

【问题讨论】:

  • 请编辑您的问题并包含您的 ARM 模板。

标签: azure arm-template azure-storage-account


【解决方案1】:

试试这个 ARM 模板,它将帮助您在现有的存储帐户中创建一个容器。

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "storageAccountName": {
            "defaultValue": "STGaccount",
            "type": "String"
        },
        "containerName": {
          "type": "string",
          "defaultValue": "inputcontainer",
          "metadata": {
            "description": "Specifies the name of the blob container."
          }
        }
    },
    "variables": {},
    "resources": [
        {
            "type": "Microsoft.Storage/storageAccounts/blobServices/containers",
            "apiVersion": "2019-06-01",
            "name": "[concat(parameters('storageAccountName'), '/default/', parameters('containerName'))]",
            "properties": {
                "publicAccess": "None"
            }
        }
    ]
}

【讨论】:

  • 非常感谢@Jagrati。有效。我实际面临的问题是我想使用 ARM 创建一个函数应用程序,以便 ARM 模板引用我已经参数化的现有存储帐户(inputstgdev 和 outputstgdev)。我希望 ARM 模板使用 inputtgdev 存储帐户作为其附加的存储帐户,这样它就不必创建新的存储帐户。函数应用的源代码控制引用到 Gitrepo。这是我的 ARM 模板。每次我在 devops 管道中运行它时,它都会说......
  • 2020-06-11T22:31:03.1194796Z ##[错误]部署模板验证失败:'资源'/subscriptions/bea8ac84-24a4-4e53-9198-e3b0107547d4/resourceGroups/dev-rgp /providers/Microsoft.Web/sites/functionapp/sourcecontrols/web' 在第 '1' 行和第 '3069' 列不依赖于父资源 '/subscriptions/bea8ac84-24a4-4e53-9198-e3b0107547d4/resourceGroups/dev- rgp/providers/Microsoft.Web/sites/functionapp'。请使用“dependsOn”语法显式添加依赖项。请参阅aka.ms/arm-template/#resources 了解使用详情。'.
  • 我认为您可以将此作为单独的问题提出,并在那里提及您的情况和错误!
  • 感谢 Jagrati Modi-AIS。我已经在这里完成了......如何在 ARM 模板中引用已经存在的 Azure 门户创建的存储帐户
猜你喜欢
  • 2020-10-02
  • 2021-09-18
  • 2021-01-31
  • 2015-12-25
  • 2019-11-30
  • 2020-09-15
  • 2018-01-19
  • 2017-01-02
  • 2020-09-04
相关资源
最近更新 更多