Azure / azure-quickstart-templates

Azure Quickstart Templates
https://aka.ms/azqst
MIT License
14.06k stars 16.12k forks source link

Impossible to retreive dynamic IP address after deployment #4234

Open MCKLMT opened 6 years ago

MCKLMT commented 6 years ago

Issue Details

It's possible to retrieve a static IP address in outputs of a template but not a dynamic IP.

Repro steps

This template works, the IP is in the outputs:

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "publicIPAddresses_name": {
            "type": "String"
        }
    },
    "variables": {},
    "resources": [
        {
            "type": "Microsoft.Network/publicIPAddresses",
            "name": "[parameters('publicIPAddresses_name')]",
            "apiVersion": "2017-06-01",
            "location": "westeurope",
            "properties": {
                "publicIPAddressVersion": "IPv4",
                "publicIPAllocationMethod": "Static",
                "idleTimeoutInMinutes": 4
            }
        }
    ],
    "outputs": {
        "resourceID": {
            "type": "String",
            "value": "[resourceId('Microsoft.Network/publicIPAddresses', parameters('publicIPAddresses_name'))]"
        },
        "ipaddress": {
            "type": "String",
            "value": "[reference(parameters('publicIPAddresses_name')).ipAddress]"
        }
    }
}

This template does not work:

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "publicIPAddresses_name": {
            "type": "String"
        }
    },
    "variables": {},
    "resources": [
        {
            "type": "Microsoft.Network/publicIPAddresses",
            "name": "[parameters('publicIPAddresses_name')]",
            "apiVersion": "2017-06-01",
            "location": "westeurope",
            "properties": {
                "publicIPAddressVersion": "IPv4",
                "publicIPAllocationMethod": "Dynamic",
                "idleTimeoutInMinutes": 4
            }
        }
    ],
    "outputs": {
        "resourceID": {
            "type": "String",
            "value": "[resourceId('Microsoft.Network/publicIPAddresses', parameters('publicIPAddresses_name'))]"
        },
        "ipaddress": {
            "type": "String",
            "value": "[reference(parameters('publicIPAddresses_name')).ipAddress]"
        }
    }
}

The error message is:

{  
   "code":"DeploymentOutputEvaluationFailed",
   "message":"Unable to evaluate template outputs: 'ipaddress'. Please see error details and deployment operations. Please see https://aka.ms/arm-debug for usage details.",
   "details":[  
      {  
         "code":"DeploymentOutputEvaluationFailed",
         "target":"ipaddress",
         "message":"The template output 'ipaddress' is not valid: The language expression property 'ipAddress' doesn't exist, available properties are 'provisioningState, resourceGuid, publicIPAddressVersion, publicIPAllocationMethod, idleTimeoutInMinutes'.."
      }
   ]
}

Why is it working for static IP but not dynamic?

Thanks

michaelsync commented 6 years ago

Hi team, Any update on this issue?

CC @zjpjack

MCKLMT commented 6 years ago

Hi, I solved my issue with the help of a PM whom shared with me a trick. This template can help you to understand how: https://github.com/Azure/azure-quickstart-templates/tree/master/201-application-gateway-webapp-iprestriction

iteal commented 2 years ago

The link from @MCKLMT has changed to: https://github.com/Azure/azure-quickstart-templates/tree/master/quickstarts/microsoft.network/application-gateway-webapp-iprestriction