2

Resource Type

Microsoft.Cdn/profiles/originGroups/origins

Api Version

2021-06-01

I'm trying to deploy Azure Front Door for multiple Azure App Services with custom domain names. I am able to deploy multiple custom domain names and associate them with their own route and similar to their own WAF policy. However, I am struggling with creating multiples Origin Groups and adding their own origin.

Whenever I try to reference a parent resource frontDoorOriginGroup I get an error as below

'The template resource '[format('{0}/{1}/{2}', parameters('frontDoorName'), format('{0}-origins', replace(parameters('origins')[range(0, length(parameters('origins')))[parameters('origins')[copyIndex()]]], '.', '-')), replace(parameters('origins')[copyIndex()], '.', ''))]' at line '1' and column '5424' is not valid: Unable to evaluate named property or non-integer index 'web-app-name.azurewebsites.net' on an array value...

My Bicep code

resource frontDoorOriginGroup 'Microsoft.Cdn/profiles/originGroups@2021-06-01' = [for i in range(0, length(origins)): {
  name: replace(origins[i], '.', '-')
  parent: frontDoorProfile
  properties: {
    loadBalancingSettings: {
      sampleSize: 4
      successfulSamplesRequired: 2
    }
    healthProbeSettings: {
      probePath: healthCheckPath
      probeRequestType: 'GET'
      probeProtocol: 'Https'
      probeIntervalInSeconds: 120
    }
  }
}]

resource frontDoorOrigin 'Microsoft.Cdn/profiles/originGroups/origins@2021-06-01' = [for origin in origins: {
  name: frontDoorOriginGroup[origin].name
  parent: frontDoorOriginGroup[origin]
  properties: {
    hostName: '${origin}'
    httpPort: 80
    httpsPort: 443
    originHostHeader: '${origin}'
    priority: 1
    weight: 50
    enabledState: 'Enabled'
  }
}]

Is there a way to reference a child resource to a parent resource as an array? I read this documentation Set name and type for child resources in Bicep didn't work for me, or do I do something wrong? Please, assist. Thanks!

iMAN
  • 57
  • 4
  • 1
    you need to loop through using index in your second loop, same way you re doing it for the first loop – Thomas May 08 '23 at 23:23
  • 1
    Thanks, @Thomas for the heads up, with a bit of playing with the loop it worked finally! :) – iMAN May 09 '23 at 07:56

1 Answers1

1

So, got it working with a change as below if someone struggles with the similar issue

resource frontDoorOriginGroup 'Microsoft.Cdn/profiles/originGroups@2021-06-01' = [for i in range(0, length(origins)): {
  name: replace(origins[i], '.', '-')
  parent: frontDoorProfile
  properties: {
    loadBalancingSettings: {
      sampleSize: 4
      successfulSamplesRequired: 2
    }
    healthProbeSettings: {
      probePath: healthCheckPath
      probeRequestType: 'GET'
      probeProtocol: 'Https'
      probeIntervalInSeconds: 120
    }
  }
}]

resource frontDoorOrigin 'Microsoft.Cdn/profiles/originGroups/origins@2021-06-01' = [for i in range(0, length(origins)): {
  name: frontDoorOriginGroup[i].name
  parent: frontDoorOriginGroup[i]
  properties: {
    hostName: origins[i]
    httpPort: 80
    httpsPort: 443
    originHostHeader: origins[i]
    priority: 1
    weight: 50
    enabledState: 'Enabled'
  }
}]
iMAN
  • 57
  • 4