From f93c938487211a3e0127f7c690f89fa7295f43a3 Mon Sep 17 00:00:00 2001 From: magodo Date: Tue, 23 Apr 2024 14:15:43 +0800 Subject: [PATCH] `azurerm_storage_share_file` - Post hex decode then base64 encode the value of `content_md5`, to align with Azure expectation --- .../storage/storage_share_file_resource.go | 14 ++++++++++++-- website/docs/r/storage_share_file.html.markdown | 2 ++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/internal/services/storage/storage_share_file_resource.go b/internal/services/storage/storage_share_file_resource.go index 50d60e3ba0cf..4ea6732b3a37 100644 --- a/internal/services/storage/storage_share_file_resource.go +++ b/internal/services/storage/storage_share_file_resource.go @@ -159,7 +159,12 @@ func resourceStorageShareFileCreate(d *pluginsdk.ResourceData, meta interface{}) } if v, ok := d.GetOk("content_md5"); ok { - input.ContentMD5 = utils.String(v.(string)) + // Azure uses a Base64 encoded representation of the standard MD5 sum of the file + contentMD5, err := convertHexToBase64Encoding(v.(string)) + if err != nil { + return fmt.Errorf("failed to hex decode then base64 encode `content_md5` value: %s", err) + } + input.ContentMD5 = &contentMD5 } var file *os.File @@ -237,7 +242,12 @@ func resourceStorageShareFileUpdate(d *pluginsdk.ResourceData, meta interface{}) } if v, ok := d.GetOk("content_md5"); ok { - input.ContentMD5 = utils.String(v.(string)) + // Azure uses a Base64 encoded representation of the standard MD5 sum of the file + contentMD5, err := convertHexToBase64Encoding(v.(string)) + if err != nil { + return fmt.Errorf("failed to hex decode then base64 encode `content_md5` value: %s", err) + } + input.ContentMD5 = &contentMD5 } if _, err = client.SetProperties(ctx, id.ShareName, id.DirectoryPath, id.FileName, input); err != nil { diff --git a/website/docs/r/storage_share_file.html.markdown b/website/docs/r/storage_share_file.html.markdown index 26afab421758..b89439480652 100644 --- a/website/docs/r/storage_share_file.html.markdown +++ b/website/docs/r/storage_share_file.html.markdown @@ -59,6 +59,8 @@ The following arguments are supported: * `content_md5` - (Optional) The MD5 sum of the file contents. Changing this forces a new resource to be created. +~> **NOTE:** This property is intended to be used with the Terraform internal [filemd5](https://www.terraform.io/docs/configuration/functions/filemd5.html) and [md5](https://www.terraform.io/docs/configuration/functions/md5.html) functions when `source` is defined. + * `content_encoding` - (Optional) Specifies which content encodings have been applied to the file. * `content_disposition` - (Optional) Sets the file’s Content-Disposition header.