Azure ARM template - add tag unless it already exist? Ie not update it RRS feed

  • Question

  • Is there a way to specify in an ARM template that a specific tag should only be added if doesn't exist already? Or, only during the creation of a resource. Ie it should never overwrite a tag that already exists.

    We are currently adding the tag "creationDate" to all our resources, since Azure doesn't give us an easy way to see when a resource was created. It works fine for newly created resources, but it overwrites the tag when using the same ARM template to update the resource. And we of course don't want that.

    The best would be if it was possible to have a conditional tag somehow, that would only be added if the resource is new, or if the tag doesn't already exist.

    Another option maybe could be that the ARM template somehow extracted the existing tag value, so that it technically still overwrites the tag but using the same value as before.

    Is anything like this possible?

    Wednesday, November 27, 2019 7:56 AM

All replies

  • Hi,

    ARM templates operate in idempotent way where you set desired state and that is being executed. This means tags act the same way- via template you set the desired tags and those are applied no matter the previous value. If you are using ARM template to deploy and manage resources just include that tag in your templates with value that needs to be provided as parameter. This of course assumes that you do not use other methods to configure your resources or at least to not modify the tags. Of course this suggestion will not work if you do not use just ARM templates to manage your resources.

    Friday, November 29, 2019 3:03 PM
  • Well, I wouldn't really call it idempotent, since the exact same ARM template, with the exact same parameters, run on identical environments, can have different results depending on what day they are run.

    I can of course understand the general idea about idempotence here, and why it is a desirable aspect most of the times. But not being able to keep some existing things unmodified when wanted seems like a real drawback.

    Friday, November 29, 2019 3:16 PM