【问题标题】:Simple ARM template not working in Azure Cli简单的 ARM 模板在 Azure Cli 中不起作用
【发布时间】:2021-05-24 18:49:26
【问题描述】:

我有一个简单的 ARM 部署脚本

az deployment group create \
  --name <NAME> \
  --resource-group <ResourceGroup> \
  --template-file template.json \
  --parameters @parameters.json

这有一个模板文件

{
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "connections_ftp_name": {
            "defaultValue": "ftp",
            "type": "String"
        }
    },
    "variables": {},
    "resources": [
        {
            "type": "Microsoft.Web/connections",
            "apiVersion": "2016-06-01",
            "name": "[parameters('connections_ftp_name')]",
            "location": "ukwest",
            "kind": "V1",
            "properties": {
                "displayName": "[parameters('connections_ftp_name')]",
                "customParameterValues": {},
                "api": {
                    "id": "[concat('/subscriptions/SUBSCRIPTION/providers/Microsoft.Web/locations/ukwest/managedApis/', parameters('connections_ftp_name'))]"
                }
            }
        }
    ]
}

还有一个参数文件

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "connections_ftp_name": {
            "value": "my-name"
        }
    }
}

当我通过 Azure CLI 运行时出现错误

az deployment group create \
>   --name DeployMonitorFtp5 \
>   --resource-group middleware.prod.rg \
>   --template-file template.json \
>   --parameters @parameters.json
←[K←[K←[91mDeployment failed. Correlation ID: 1f5b34ad-3105-4dfd-b4ca-d38a98fb800a. {
  "error": {
    "code": "ApiNotFound",
    "message": "The API 'my-name' could not be found."
  }
}←[0m

鉴于我想创建资源,这根本没有意义!

有人可以帮忙吗?

保罗

【问题讨论】:

    标签: c# azure templates azure-resource-manager


    【解决方案1】:

    IT 与Az Cli 无关。 api 元素不应引用参数connections_ftp_name。应该是:

    "api": {
      "id": "[concat('/subscriptions/SUBSCRIPTION/providers/Microsoft.Web/locations/ukwest/managedApis/ftp')]"
    }
    

    在创建逻辑应用连接器时,还应指定连接器,这里是创建 ftp 连接器的完整示例:

    {
      "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
      "contentVersion": "1.0.0.0",
      "parameters": {
        "ftpConnectionAPIName": {
          "type": "string",
          "metadata": {
            "description": "The name of the connection api to access the ftp."
          }
        },
        "ftpServerAddress": {
          "type": "string",
          "metadata": {
            "description": "The name of the ftp server address."
          }
        },
        "ftpUsername": {
          "type": "string",
          "metadata": {
            "description": "The name of the ftp user name."
          }
        },
        "ftpPassword": {
          "type": "securestring",
          "metadata": {
            "description": "The name of the ftp password."
          }
        }
      },
      "resources": [
        {
          "type": "Microsoft.Web/connections",
          "name": "[parameters('ftpConnectionAPIName')]",
          "apiVersion": "2016-06-01",
          "location": "[resourceGroup().location]",
          "scale": null,
          "properties": {
            "displayName": "[parameters('ftpConnectionAPIName')]",
            "parameterValues": {
              "serverAddress": "[parameters('ftpServerAddress')]",
              "userName": "[parameters('ftpUsername')]",
              "password": "[parameters('ftpPassword')]"
            },
            "api": {
              "id": "[concat('subscriptions/', subscription().subscriptionId, '/providers/Microsoft.Web/locations/', resourceGroup().location, '/managedApis/ftp')]"
            }
          }
        }
      ]
    }
    

    【讨论】:

    • 啊好的谢谢我希望我的资源有一个特定的名称,而不仅仅是 ftp,我可以使用你放在这里的东西:)
    • 您的连接器名称将取决于 name 属性,所以它会很好。 api 元素代表一个 azure api。
    • 谢谢,效果很好。理想情况下,我希望在 ARM 模板中包含其他框,例如二进制传输、禁用证书验证等,但是当我从 Azure 生成模板时,这些框会丢失吗?
    • 您可以手动创建连接器并使用az rest 查询 ARM API,它将为您提供有关可能的属性/值的更多信息
    • 好的,谢谢,我在 az rest 之后还放了什么?我设法获得了其他复选框,只是试图找到端口号一而不是端口号
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多