file hash or last update time function
- Dominant language
- Bicep
- Stars
- 3.6k
- Forks
- 830
- Avg merge
- 1d 21m
- Merged PRs (30d)
- 79
Description
**Is your feature request related to a problem? Please describe.**
When deploying a VM custom script extension, there is a property called `forceUpdateTag` - I have seen this cocnept crop up in a few other resources as well:
```bicep
resource vmCustomScriptExtension 'Microsoft.Compute/virtualMachines/extensions@2022-08-01' = if (!empty(customScriptExtensionSettings)) {
parent: vm
name: 'vmScriptExtension-${name}'
location: location
properties: {
publisher: 'Microsoft.Azure.Extensions' //'Microsoft.Compute'
forceUpdateTag: customScriptExtensionSettings.forceUpdateTag ?? null // empty(customScriptExtensionSettings.forceUpdateTag) ? null : customScriptExtensionSettings.forceUpdateTag
type: 'CustomScript'
typeHandlerVersion: '2.1'
autoUpgradeMinorVersion: true
settings: customScriptExtensionSettings.settings
protectedSettings: finalCustomSciptProtectedSettings
}
}
```
The idea here (I believe) is that you need to set this value to something different in order to force ARM to detect a change to the resource and have the script run again. If you never change this value, it will only be run once and never again.
Whilst I am developing I am making changes to the script file locally that this custom script extension runs. So I set this forceUpdateTag based on the time now() function (can't remember the exactl bicep function for this but hopefully you get it!) - so that ARM always re-deploys this resource and runs the current idempotent script - even if it hasn't changed.
However in the case it hasn't changed, this always adds a minute or two onto my deployment and seems wasteful. What would be better is if I could set this tag based on the last updated time of the script file itself, or a hash of the file content - that way, ARM would only redeploy this resource when there was a modification to the script file.
**Describe the solution you'd like**
A function to get the last updated time of a local file, and / or get a `hash` from a file's contents (that would be compatible in length such that it could be used for this property.)
I am aware there are various hash functions but I am not sure of the appropriate one to use in this scenario, so perhaps if I should be using something existing please let me know. From what I could see the existing functions were designed to be used with specific strings like names or id's - it didn't feel necessarily correct to use them with an entire file's contents as an input string.
Contributor guide
Research direction
Start by reviewing Bicep's existing string and hash-related functions and how expressions are evaluated during deployment. Determine whether local file timestamps or contents are available to Bicep, and whether the requested value could support forceUpdateTag. Done means a clearly scoped supported approach, or documentation explaining why an existing function is appropriate or the request cannot be supported.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- azure
- Domain
- cloud
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100