How to extract an archive using terraform

Viewed 1585

I am trying to deploy a website on azure storage. For that I need to

  • download the files from artifactory as tar.gz or zip file
  • extract the archive
  • upload files as blobs to the storage account

I can do every step but extracting the archive. Can somebody tell me how to extract an zip or tarball archive using terraform?

1 Answers

you might use null_resource with the provisioner "local-exec" inside to do so. It might be any command line or simple bash script wrapper. https://www.terraform.io/docs/language/resources/provisioners/local-exec.html

resource "null_resource" "extract_my_tgz" {
  provisioner "local-exec" {
    command = "tar xzf my_file.tgz"
  }
}

there same you might use for zip files as well.

resource "null_resource" "extract_my_zip" {
  provisioner "local-exec" {
    command = "unzip my_file.zip"
  }
}
Related