Azure-docs: Dependent resources on conditional resources fail

Created on 17 Jan 2019  Â·  11Comments  Â·  Source: MicrosoftDocs/azure-docs

having a template looking like this fails to deploy:

resources: [
  {
    type: web/certs
    name: sslcert,
    condition: isProduction
  },
  {
    type: web/sites,
    name: webapp,
  },
  {
    type: web/sites/hostNameBindings,
    name: sslBinding,
    condition: isProduction,
    properties: {
      thumbpring: reference(sslcert).thumbprint
    },
    dependsOn: [
      webapp,
      sslcert
    ]
  }
]

This assumes the isProduction variable returns true or false.
This template fails to deploy because the host name binding resource depends on the ssl certificate and even when both's deployment depends on the same condition the dependsOn of the binding still evaluates and breaks because the certificate is not present.

I think since the binding is also not being deployed because of the condition, the dependsOn property should also be ignored.

The error below would not appear if I remove the binding from the template:
Resource Microsoft.Web/certificates 'sslcert' failed with message '{ "error": { "code": "ResourceNotFound", "message": "The Resource 'Microsoft.Web/certificates/sslcert' under resource group '<my resource group name>' was not found." } }'


Document Details

⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

Pri2 azure-resource-managesvc resolved triaged

Most helpful comment

@haveyoumetcp, I agree the behavior should be as you described, and the current behavior should be considered a bug.
I think the issue was closed because this is just the documentation repo.
Glad the post helped!

All 11 comments

@artmasa Thanks for the Comment. We are actively investigating and will get back to you soon.

@artmasa Please contact Microsoft support or use the MSDN Azure forum for specific user issues. I would check whether the certificate resource has been created successfully from the Azure portal. You can find more information about this error at https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-manager-not-found-errors.

@mumian, thanks for your response.
I have updated the issue. After investigating further I found out that the problem is not the dependency on the certificate resource, but the reference to it.
I think it would be nice if references inside a conditional object can be evaluated after the check on condition. In my case both resources should not be created when condition isProduction returns false; but because the reference is evaluated regardless of conditions, the whole deployment fails.

@artmasa I am glad you resolved the issue.

please-close

@artmasa Closing this issue for now. If there are further questions regarding this matter, please reply and we will gladly continue the discussion.

Thanks @artmasa .. Your post helped me find similar non-descriptive error in my templates.

Thanks @artmasa for the write up. Helped me get past this problem.

However, I really feel like this is a bug. You would think since you have a condition on the a section it wouldn't evaluate the reference.

@haveyoumetcp, I agree the behavior should be as you described, and the current behavior should be considered a bug.
I think the issue was closed because this is just the documentation repo.
Glad the post helped!

@spottedmahn - thank you for the comment. The information is covered in https://docs.microsoft.com/en-us/azure/azure-resource-manager/conditional-resource-deployment#runtime-functions. Because the tutorials are covering common usages, I will leave it as is for now.

please close

Hi @mumian - I think you meant to comment on https://github.com/MicrosoftDocs/azure-docs/issues/42431 😀. Correct me if I'm wrong.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

paulmarshall picture paulmarshall  Â·  3Comments

JeffLoo-ong picture JeffLoo-ong  Â·  3Comments

spottedmahn picture spottedmahn  Â·  3Comments

AronT-TLV picture AronT-TLV  Â·  3Comments

monteledwards picture monteledwards  Â·  3Comments