Azure / bicep

Bicep is a declarative language for describing and deploying Azure resources
MIT License
3.27k stars 757 forks source link

Ignore changes feature to avoid resource recreation #14477

Open aarthyramesh1988 opened 5 months ago

aarthyramesh1988 commented 5 months ago

Is your feature request related to a problem? Please describe. In the resource deployments in bicep, we have added a tag with creation date as current datetime. So, in subsequent redeployments, the resources are recreated since the date has changed.

param creationDate string = utcNow('yyyy-MM-ddTHH:MM:ssZ')
var tags = {
  product: 'xx'
  application: 'xx'
  region: locationTag
  environment: envTag
  'creation-date': creationDate
}

resource userAssignedId 'Microsoft.ManagedIdentity/userAssignedIdentities@2022-01-31-preview' = {
  name: 'id-test-${subscriptionName}'
  location: location
  tags: tags 
}

Describe the solution you'd like In terraform this can be handled with lifecycle block where the list of properties can be ignored. Please can this be implemented in bicep; it is a pain that we can't ignore such changes and it leads to recreation of resources every time.

aarthyramesh1988 commented 4 months ago

Hi, Is there any update to this? @alex-frankel

alex-frankel commented 4 months ago

Sorry about the delay! The short answer is Bicep always re-deploys all resources by design so that we always seek out the goal state.

The longer answer:

For this specific pattern of capturing creation time, there is a set of system level properties that ARM tracks for you automatically called systemData so that you shouldn't have to do this. Here's an example:

{
    "location": "eastus",
    "properties": {},
    "systemData": {
        "createdBy": "alfran@microsoft.com",
        "createdByType": "User",
        "createdAt": "2024-07-10T17:28:35.7655839Z",
        "lastModifiedBy": "alfran@microsoft.com",
        "lastModifiedByType": "User",
        "lastModifiedAt": "2024-07-10T17:28:36.3352979Z"
    },
    "id": "...",
    "type": "Microsoft.Resources/templateSpecs",
    "name": "..."
}

Unfortunately, it is up to each resource provider to implement this property and it looks like managed identities have not implemented it. I can try following up with the ARM team responsible for getting the RPs to onboard to this.

alex-frankel commented 4 months ago

cc @ifeoluwaokunoren / @jennyhunter-msft

alex-frankel commented 4 months ago

Just circling back as I mentioned I would, but confirmed that it is up to the RP to implement the systemData property and there is no ETA for the ManagedIdentity RP implementing this. Unfortunately that means that there is not a great solution for keeping track of this metadata via the bicep deployment. Going to leave this open for reference but tagging the initial request with "Won't Fix" for clarity.