从链接的模板中检索Azure SQL的FQDN

问题描述 投票:0回答:1

我正在寻找一个有效的属性来从链接模板的部署中检索托管Azure SQL服务器的FQDN。下面的一个似乎没有效果

[reference(variables('sqlDeployment')).outputs.fullyQualifiedDomainName.value]"

我在哪里可以找到所有支持的参数?从Microsoft Docs中找到足够的信息似乎很有挑战性。

azure-sql-database azure-resource-manager arm-template
1个回答
1
投票

看起来您的链接模板没有名为“fullyQualifiedDomainName”的输出属性。

要从链接模板获取输出值,请使用类似“[reference('deploymentName')。outputs.propertyName.value]”的语法检索属性值,如此处所述 - > https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-group-linked-templates#get-values-from-linked-template

请在下面找到示例父模板和链接模板,以满足检索托管Azure SQL服务器的FQDN的要求。

名为“parenttemplate.json”的父模板:

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "location": {
            "type": "string",
            "defaultValue": "[resourceGroup().location]",
            "metadata": {
              "description": "Location for all resources."
            }
        }
    },
    "variables": {
        "sqlserverName": "gttestsqlserver",
        "sqlAdministratorLogin": "gttestuser",
        "sqlAdministratorLoginPassword": "gttestpassword2#",
        "sqlDeployment": "linkedTemplate"
    },
    "resources": [
      {
        "apiVersion": "2017-05-10",
        "name": "[variables('sqlDeployment')]",
        "type": "Microsoft.Resources/deployments",
        "properties": {
          "mode": "Incremental",
          "templateLink": {
            "uri": "[uri(deployment().properties.templateLink.uri, 'linkedtemplate.json')]",
            "contentVersion": "1.0.0.0"
          }
        }
      }
    ],
    "outputs": {
        "messageFromLinkedTemplate": {
            "type": "string",
            "value": "[reference(variables('sqlDeployment')).outputs.MessageOne.value]"
        }
    }
}

链接的模板名为“linkedtemplate.json”:

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "location": {
            "type": "string",
            "defaultValue": "[resourceGroup().location]",
            "metadata": {
              "description": "Location for all resources."
            }
        }
    },
    "variables": {
        "sqlserverName": "gttestsqlserver",
        "sqlAdministratorLogin": "gttestuser",
        "sqlAdministratorLoginPassword": "gttestpassword2#"
    },
    "resources": [
        {
            "name": "[variables('sqlserverName')]",
            "type": "Microsoft.Sql/servers",
            "location": "[parameters('location')]",
            "tags": {
              "displayName": "gttestsqlserver"
            },
            "apiVersion": "2014-04-01",
            "properties": {
                "administratorLogin": "[variables('sqlAdministratorLogin')]",
                "administratorLoginPassword": "[variables('sqlAdministratorLoginPassword')]",
                "version": "12.0"
            }
        }
    ],
    "outputs": {
        "MessageOne": {
            "type" : "string",
            "value": "[reference(variables('sqlserverName')).fullyQualifiedDomainName]"
        }
    }
}

上述两个模板都放在Storage blob容器中。

部署:

enter image description here

从部署中检索FQDN的插图:

enter image description here

在上面的示例和图示中,链接模板中的输出属性名称被命名为“MessageOne”,因为我们需要托管Azure SQL服务器的FQDN,因此“MessageOne”输出属性的值被引用为“fullyQualifiedDomainName”。

关于查找所有支持的参数,最简单的方法之一是使用“Get-Member”获取任何资源的所有属性,如下例所示。

enter image description here

希望这可以帮助!!干杯!!

© www.soinside.com 2019 - 2024. All rights reserved.