Upload image file to Azure Devops repo

I’m trying to upload a PNG file to an Azure Devops/Githuib repo using
resource "azuredevops_git_repository_file" ïmage_file"
content = filebase64sha256("wiki.png")
The actual upload works but the content no longer matches the original and is not ‘detected’ as a proper image file anymore.

Well, of course - if you check the documentation for the filebase64sha256 function you are using, you will see that it does not return the content of the file!

However there is a larger problem here too - Terraform strings can only store UTF-8 text. Therefore, there is no way to use the azuredevops_git_repository_file resource to upload a binary image file.

I would suggest looking for a non-Terraform way to achieve this.

Thanks. Might have to look into using a null resource and a git command to do just that :frowning:

Providers that support uploading files will often support binary data (assuming the underlying API does) by offering a separate argument that takes the base64 encoding of the data, which you can then assign with filebase64.

It doesn’t seem like this particular resource type currently has that capability, but the provider development team might be willing to support it if you share your use-case in the provider’s GitHub repository, and if the underlying API can itself support raw binary data here.

It is just a ‘normal’ PNG image file to be used on a WIKI.
Might try it with a different file type.

With the current design of the provider it can only accept file contents that are UTF-8-encoded text. This will be true whatever file type you use.

In the provider implementation I see it setting the content type to “raw text”:

The valid content type values don’t have detailed documentation associated with them but I notice that the other option here is base64Encoded, so it does seem like the underlying API could support uploading binary data as base64, but the Terraform provider does not expose that functionality. You will not be able to use it until the provider is updated to support it.

I suggest to open an issue in the provider’s GitHub repository to describe what you are trying to do, and then the provider development team will hopefully update the provider to expose the base64Encoded mode as an option.

The typical design for this in other Terraform providers is to offer both a content argument and a content_base64 argument, where these arguments are exclusive so you can only set one of them. If the provider were changed to follow that convention then your configuration would change like this:

resource "azuredevops_git_repository_file" "image_file" {
  # ...
  # INVALID: The provider does not yet support this argument
  content_base64 = filebase64("${path.module}/wiki.png")
  # ...

Internally within the provider’s code the logic would need to check whether content or content_base64 is set, and use that to choose between setting ContentType to either RawText for content or base64Encoded for content_base64.

I see that the GitHub issue template for that repository asks for a “Potential Terraform Configuration”, so you could perhaps use my example above as the potential Terraform configuration if you choose to open an enhancement request issue.

Thanks @apparentlymart. Ticket raised. Might not fix the immediate requirement but for future use that would be good.