Search code examples
terraformazure-storageazure-storage-files

Is it possible to upload files to Azure Share using terraform?


I use terraform to configure the storage account, containers, shares.

A question arised - can I upload a file to an Azure storage account file share with terraform? I cannot find the respective resource.

EDIT 1

An idea that comes is to use the null_resource. I wonder how it fits with the benefits of using terraform, which are in my opinion:

  1. It can also be viewed as the documentation of your infrastructure.
  2. It can tell you what it is about to do before doing it.
  3. A variant of (2) - it gives you the ability to inspect the plan automatically and enforce policies.
  4. Its state can be used to answer audit questions about what exactly has the release pipeline provisioned.
  5. It has a very simple declarative language.

Other potential benefits could be enforcing the desired state, though, this is more potentially and in the future, rather than current. Indeed, try deleting a resource outside of terraform. In theory and in the future it could recognise it and recreate, today it just fails. But the potential is there.

All these benefits are enough to justify using it, even though I sometimes want to bang my head on the wall trying to do something with it.

Now, how all these benefits fit into running a custom script within a null_resource? Surely inspecting the plan would not help with a general purpose script inside a resource. I wonder how it fares against the other benefits?


Solution

  • For anyone coming from Google, it's worth pointing out you should now be able to use azurerm_storage_share_file. This worked great for me to upload a single file. To upload multiple files it looks like you will require multiple resources

    https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/storage_share_file

    resource "azurerm_storage_share_file" "example" {
      name             = "test.txt"
      storage_share_id = azurerm_storage_share.example.id
      source           = "${path.root}/TestFile/test.txt"
    }