Reputation: 5224
I got this API Management ARM template
{
"apiVersion": "2017-03-01",
"name": "[variables('am-apimanagement-service-name')]",
"type": "Microsoft.ApiManagement/service",
"location": "North Europe",
"sku": {
"name": "[parameters('am-sku')]",
"capacity": "[parameters('am-skuCount')]"
},
"properties": {
"publisherEmail": "[parameters('am-publisher-email-p')]",
"publisherName": "[parameters('am-publisher-name-p')]"
},
"resources": [
{
"type": "apis",
"apiVersion": "2017-03-01",
"name": "test",
"dependsOn": [
"[concat('Microsoft.ApiManagement/service/',variables('am-apimanagement-service-name'))]"
],
"properties": {
"displayName": "test",
"description": "",
"serviceUrl": "[concat('https://test-',parameters('environment'),'.azurewebsites.net')]",
"path": "test",
"protocols": [
"https"
],
"isCurrent": true
},
"resources": [
{
"apiVersion": "2017-03-01",
"type": "operations",
"name": "GetTEst",
"dependsOn": [
"[concat('Microsoft.ApiManagement/service/', variables('am-apimanagement-service-name'), '/apis/test')]"
],
"properties": {
"displayName": "GET",
"method": "GET",
"urlTemplate": "/api/sites",
"description": "Get"
}
}
]
}
]
}
And this Web API ARM template
{
"apiVersion": "2016-03-01",
"name": "[variables('swa-name')]",
"type": "Microsoft.Web/sites",
"properties": {
"name": "[variables('swa-name')]",
"serverFarmId": "[variables('swa-hosting-plan-name')]",
"hostingEnvironment": "[parameters('swa-hosting-environment')]",
"siteConfig": {
"appSettings": [
{
"name": "Test:ConnectionString",
"value": "[concat('Server=tcp:', reference(resourceId('Microsoft.Sql/servers/', variables('db-serverName'))).fullyQualifiedDomainName, ',1433;Initial Catalog=', variables('db-databaseName'), ';Persist Security Info=False;User ID=', parameters('db-administratorLogin'), ';Password=', parameters('db-administratorLoginPassword'), ';MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;')]"
}
],
"ipSecurityRestrictions": [
{
"ipAddress": "[variables('test-ip-address')]",
"subnetMask": "255.255.255.255"
}
]
}
},
"location": "[parameters('swa-location')]",
"tags": {
},
"kind": "api",
"dependsOn": [
"[concat('Microsoft.Web/serverfarms/', variables('swa-hosting-plan-name'))]"
]
}
How do I use the reference function to get IP address of the API Management resource from the Web API ? I want to put the API Management IP address in the ipSecurityRestrictions. I can not figure it out, and it is frustrating me quite a bit.
I have tried this from the web api resource resource section of the ARM template:
"ipSecurityRestrictions": [
{
"ipAddress": "[variables('test-ip-address')]",
"subnetMask": "255.255.255.255"
},
{
"ipAddress": "[reference(variables('am-apimanagement-service-name')).publicIPAddresses[0]]",
"subnetMask": "255.255.255.255"
}
]
But it doesnt work. Maybe I am not able to get the IP address in this step of the process? I am reading about outputs and linked templates. Maybe this is the solution?
Upvotes: 3
Views: 2672
Reputation: 5224
The crazy thing here is that I need two things:
The thing is that a free tier API Management resource is actually not assigned a static IP, but a dynamic ip. Still the static ip address is assigned to the staticIp property of the referenced object:
"ipAddress": "[reference(variables('am-apimanagement-service-name'),'2017-03-01').staticIps[0]]"
This will reference the IP correctly.
Upvotes: 5
Reputation: 75
I think you should add the api version to your reference, as the API management is not deployed in the same template as where you're refering to it.
Something like this
{
"ipAddress": "[reference(variables('am-apimanagement-service-name'), '2017-03-01').publicIPAddresses[0]]",
"subnetMask": "255.255.255.255"
}
Upvotes: 3