Retrieve FQDN of Azure SQL from a linkted template

2019-08-26 20:49发布

I'm looking for a valid property to retrieve FQDN of a managed Azure SQL server from a deployment of linked template. The one below seems not to be valid

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

and where can I find all supported parameters? It seems to be challenging to find enough info from Microsoft Docs.

1条回答
家丑人穷心不美
2楼-- · 2019-08-26 21:05

Looks like your linked template did not have an output property named as 'fullyQualifiedDomainName'.

To get an output value from a linked template, retrieve the property value with syntax like "[reference('deploymentName').outputs.propertyName.value]" as explained here -> https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-group-linked-templates#get-values-from-linked-template

Please find below sample parent and linked templates to accomplish your requirement of retrieving FQDN of a managed Azure SQL server.

Parent template named as "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]"
        }
    }
}

Linked template named as "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]"
        }
    }
}

Both the above mentioned templates are placed in Storage blob container.

Deployment:

enter image description here

Illustration of retrieval of FQDN from the deployment:

enter image description here

In the above example and illustration, the output property name in linked template is named as "MessageOne" and as we need FQDN of managed Azure SQL server so the value of that "MessageOne" output property is referenced to "fullyQualifiedDomainName".

And regarding finding all the supported parameters, one of the easiest ways is to get all the properties of any resource by using 'Get-Member' as shown in below example.

enter image description here

Hope this helps!! Cheers!!

查看更多
登录 后发表回答