I am using azurerm provider and more specifically the file share resource to upload a file.
resource "azurerm_storage_share_file" "file" {
name = local.file_name
storage_share_id = azurerm_storage_share.storage_share.id
path = "${local.root_path}/${local.file_name}"
source = var.file_path
content_type = local.content_type_json
}
This is working fine. However, terraform does not really load the contents of my local file and thus, if I change the contents of it, terraform will not see any change in the plan stage. The resource also supports a checksum property. By using the md5 function, I can create a new checksum every time which results in a force replacement regardless if the file contents has changed or not.
content_md5 = md5(var.file_path)
It works but it is not ideal since I will always have the replacement, even if the contents have not changed:
-/+ resource "azurerm_storage_share_file" "file" {
~ content_length = 100 -> (known after apply)
- content_md5 = "g...." -> "123" # forces replacement
Is there a way to only replace/upload the file if the contents of the file has changed that is already uploaded to the file share? Perhaps there is a way to calculate a checksum in a different way that only changes when the file contents changes?
Update:
I have also now tried filemd5
function instead. It is strange however. On first creating, say I get checksum “123”. Then on the next plan I get checksum “789”. I hit apply which replaces the file. Then I plan again and I get “123” again! Strange.