首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Azure ARM模板DependentOn FileShare

Azure ARM模板DependentOn FileShare
EN

Stack Overflow用户
提问于 2020-09-23 23:52:49
回答 3查看 725关注 0票数 3

我需要创建通过ARM模板存储帐户->文件共享->容器与挂载文件共享。

依赖项是:

  1. 文件共享取决于存储帐户
  2. 容器依赖于文件共享

如何获得菲林的ReferenceId?

我有以下代码:

代码语言:javascript
复制
    {
        "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
        "contentVersion": "1.0.0.0",
        "parameters": {
            "storageAccountType": {
                "type": "string",
                "defaultValue": "Standard_LRS",
                "allowedValues": [
                    "Standard_LRS",
                    "Standard_GRS"
                ],
                "metadata": {
                    "description": "Storage account type (SKU)"
                }
            },
            "fileShareName": {
                "type": "string",
                "minLength": 3,
                "maxLength": 63,
                "defaultValue": "sftp",
                "metadata": {
                    "description": "Name of the File Share to be created. "
                }
            }
        },
        "variables": {
            "deploymentLocation": "[resourceGroup().location]",
            "storageAccountName": "[concat('sftpstr', uniqueString(resourceGroup().id))]"
        },
        "resources": [
            {
                "type": "Microsoft.Storage/storageAccounts",
                "name": "[variables('storageAccountName')]",
                "apiVersion": "2019-06-01",
                "location": "[variables('deploymentLocation')]",
                "sku": {
                    "name": "[parameters('storageAccountType')]"
                },
                "kind": "StorageV2",
                "properties": {
                    "accessTier": "Hot"
                }
            },
            {
                "type": "Microsoft.Storage/storageAccounts/fileServices/shares",
                "apiVersion": "2019-06-01",
                "properties": {
                    "accessTier": "Hot"
                },
                "name": "[concat(variables('storageAccountName'), '/default/', parameters('fileShareName'))]",
                "dependsOn": [
                    "[resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName'))]"
                ]
            }, 
            {
                "type": "Microsoft.ContainerInstance/containerGroups",
                "name": "sftp-container-group",
                "apiVersion": "2018-04-01",
                "dependsOn": [
                    "[resourceId('Microsoft.Storage/storageAccounts/fileServices/shares', ????? )]" //how to get reference to specific Fileshare??? I've tried >   [concat(variables('storageAccountName'), '/default/', parameters('fileShareName'))] but it didn't work
                ],
                "properties": {
                    .......
                }
            }
        ] 
    }

我不知道如何设置对Fileshare的依赖:

代码语言:javascript
复制
"dependsOn": [
    "[resourceId('Microsoft.Storage/storageAccounts/fileServices/shares', ????? )]" //how to get reference to specific Fileshare??? 
],

我试过[concat(variables('storageAccountName'), '/default/', parameters('fileShareName'))],但没成功。

有什么想法吗?

谢谢

EN

回答 3

Stack Overflow用户

发布于 2021-01-21 21:25:16

使用下列格式:

代码语言:javascript
复制
"dependsOn": [
    "[resourceId('Microsoft.Storage/storageAccounts/fileServices/shares', variables('storageAccountName') , 'default', parameters('fileShareName') )]"
],
票数 3
EN

Stack Overflow用户

发布于 2020-09-28 09:07:19

您可以创建两个独立的资源Microsoft.Storage/storageAccounts/fileServicesMicrosoft.Storage/storageAccounts/fileServices/shares,并尝试设置对Fileshare的依赖,如下所示:

代码语言:javascript
复制
        "dependsOn": [
            "[resourceId('Microsoft.Storage/storageAccounts/fileServices/shares', variables('storageAccountName'),  'default',  parameters('fileShareName') )]" 
        ],

或者,建议在容器实例中通过azure创建存储帐户和文件共享,并参考这个快速启动模板

代码语言:javascript
复制
 "variables": {
    "image": "microsoft/azure-cli",
    "cpuCores": "1.0",
    "memoryInGb": "1.5",
    "containerGroupName": "createshare-containerinstance",
    "containerName": "createshare"
  },
  "resources": [
    {
      "type": "Microsoft.Storage/storageAccounts",
      "name": "[parameters('storageAccountName')]",
      "apiVersion": "2019-06-01",
      "location": "[parameters('location')]",
      "sku": {
        "name": "[parameters('storageAccountType')]"
      },
      "kind": "StorageV2"
    },
    {
      "name": "[variables('containerGroupName')]",
      "type": "Microsoft.ContainerInstance/containerGroups",
      "apiVersion": "2019-12-01",
      "location": "[parameters('containerInstanceLocation')]",
      "dependsOn": [
        "[resourceId('Microsoft.Storage/storageAccounts/', parameters('storageAccountName'))]"
      ],
      "properties": {
        "containers": [
          {
            "name": "[variables('containerName')]",
            "properties": {
              "image": "[variables('image')]",
              "command": [
                "az",
                "storage",
                "share",
                "create",
                "--name",
                "[parameters('fileShareName')]"
              ],
              "environmentVariables": [
                {
                  "name": "AZURE_STORAGE_KEY",
                  "value": "[listKeys(parameters('storageAccountName'),'2019-06-01').keys[0].value]"
                },
                {
                  "name": "AZURE_STORAGE_ACCOUNT",
                  "value": "[parameters('storageAccountName')]"
                }
              ],
              "resources": {
                "requests": {
                  "cpu": "[variables('cpuCores')]",
                  "memoryInGb": "[variables('memoryInGb')]"
                }
              }
            }
          }
        ],
        "restartPolicy": "OnFailure",
        "osType": "Linux"
      }
    }
  ]
票数 0
EN

Stack Overflow用户

发布于 2021-09-27 09:24:32

我发现了几件让它对我有用的东西:

ACI必须依赖于共享,否则它有时会在卷之前创建。

代码语言:javascript
复制
"dependsOn": ["resourceId('Microsoft.Storage/storageAccounts/fileServices/shares',variables('storage-account-name'), 'default', variables('file-share-name'))]"]

由于某些原因,这个共享没有作为子资源运行,所以我不得不将它变成一个完整的资源。

代码语言:javascript
复制
{
    "type": "Microsoft.Storage/storageAccounts/fileServices/shares",
    "apiVersion": "2021-04-01",
    "name": "[concat(variables('storage-account-name'),'/default/',variables('nginx-share-name'))]",
    "properties":{
        "enabledProtocols": "SMB"
    },
    "dependsOn": [
        "[resourceId('Microsoft.Storage/storageAccounts', variables('storage-account-name'))]"
    ]
}

此外,我还必须注意资源ID的默认部分。

代码语言:javascript
复制
"name": "[concat(variables('storage-account-name'),'/default/',variables('nginx-share-name'))]"

最后,ACI没有正确地连接,除非我显式地启用了SMB作为协议。

代码语言:javascript
复制
"properties":{
    "enabledProtocols": "SMB"
}

这是一个模板,用于在Azure容器实例中使用Azure文件共享作为挂载卷来旋转NGINX。

代码语言:javascript
复制
{
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "containerGroups_name": {
            "defaultValue": "container-app",
            "type": "String"
        },
        "containerGroups_reverse_proxy_name": {
            "defaultValue": "app-proxy",
            "type": "String"
        },
        "acrPassword": {
            "type": "securestring"
        }
    },
    "variables": {
        "nginx-proxy-image": "nginx:stable",
        "storage-account-name": "[concat('storage', uniqueString(resourceGroup().name))]",
        "nginx-share-name": "nginx-share",
        "nginx-volume-name": "nginx-volume"
    },
    "resources": [
        {
            "type": "Microsoft.Storage/storageAccounts",
            "apiVersion": "2017-10-01",
            "name": "[variables('storage-account-name')]" ,
            "location": "[resourceGroup().location]",
            "kind": "StorageV2",
            "sku": {
                "name": "Standard_LRS",
                "tier": "Standard"
            }
        },
        {
            "type": "Microsoft.Storage/storageAccounts/fileServices/shares",
            "apiVersion": "2021-04-01",
            "name": "[concat(variables('storage-account-name'),'/default/',variables('nginx-share-name'))]",
            "properties":{
                "enabledProtocols": "SMB"
            },
            "dependsOn": [
                "[resourceId('Microsoft.Storage/storageAccounts', variables('storage-account-name'))]"
            ]
        },
        {
            "type": "Microsoft.ContainerInstance/containerGroups",
            "apiVersion": "2021-03-01",
            "name": "[parameters('containerGroups_name')]",
            "location": "[resourceGroup().location]",
            "properties": {
                "sku": "Standard",
                "containers": [
                    {
                        "name": "[parameters('containerGroups_reverse_proxy_name')]",
                        "properties" : {
                            "image": "[variables('nginx-proxy-image')]",
                            "ports": [
                                {
                                    "protocol": "TCP",
                                    "port": 80
                                },
                                {
                                    "protocol": "TCP",
                                    "port": 433
                                }
                            ],
                            "volumeMounts" : [
                                {
                                    "name": "[variables('nginx-volume-name')]",
                                    "mountPath": "/etc/nginx"
                                }
                            ],
                            "resources": {
                                "requests":{
                                    "cpu": 1,
                                    "memoryInGB": 1.5
                                }
                            }
                        }
                    }                    
                ],
                "initContainers": [],
                "restartPolicy": "OnFailure",
                "osType": "Linux",
                "volumes": [
                    {
                        "name": "[variables('nginx-volume-name')]",
                        "azureFile": {
                            "shareName": "[variables('nginx-share-name')]",
                            "storageAccountName": "[variables('storage-account-name')]",
                            "storageAccountKey": "[listKeys(resourceId('Microsoft.Storage/storageAccounts',variables('storage-account-name')),'2017-10-01').keys[0].value]"
                        }
                    }
                ]
            },
            "dependsOn": [
                "[resourceId('Microsoft.Storage/storageAccounts/fileServices/shares',variables('storage-account-name'), 'default', variables('nginx-share-name'))]"
            ]
        }
    ]
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64037748

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档