Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Terraform upload folder to Google storage

Is there anyway i can use terraform to copy folders from local server to Google storage bucket?

I have tried file provisioner, but it is only working for VM instance, but not cloud storage.

like image 318
Vincent K Avatar asked Sep 05 '25 03:09

Vincent K


2 Answers

Another possibility to upload a group of files to a bucket

variable "files" {
  type = map(string)
  default = {
    # sourcefile = destfile
    "folder/file1" = "somefolder/file1",
    "folder2/file2"  = "somefolder/file2"
  }
}
resource "google_storage_bucket_object" "my-config-objects" {
  for_each = var.files
  name     = each.value
  source   = "${path.module}/${each.key}"
  bucket   = my-bucket-name
}
like image 200
intotecho Avatar answered Sep 07 '25 22:09

intotecho


It appear that there is a command called google_storage_bucket_object which will copy a local file to a GCS object.

See here for details:

https://www.terraform.io/docs/providers/google/r/storage_bucket_object.html

Another thought might be to run the local-exec provisioner and run gsutil to copy a directory of files.

https://www.terraform.io/docs/provisioners/local-exec.html

like image 33
Kolban Avatar answered Sep 07 '25 22:09

Kolban