hashicorp / terraform-provider-google

Terraform Provider for Google Cloud Platform
https://registry.terraform.io/providers/hashicorp/google/latest/docs
Mozilla Public License 2.0
2.33k stars 1.73k forks source link

The "gsutil rsync" command does not work in an empty directory created by google_storage_bucket_object. #15605

Open dddwsd opened 1 year ago

dddwsd commented 1 year ago

Community Note

Terraform Version

Terraform v1.5.5
on darwin_arm64

Affected Resource(s)

Terraform Configuration Files

# gsutil rsync failed
resource "google_storage_bucket_object" "train-template_base_terraform_object" {
  name   = "train-template_base_terraform/" # folder name should end with '/'
  content = " "            # content is ignored but should be non-empty
  bucket = "dddwsd-test"
}

# gsutil rsync succeed
resource "google_storage_bucket_object" "train-template_base_terraform2_object" {
  name   = "train-template_base_terraform2/empty"
  content = "empty"
  bucket = "dddwsd-test
}

Debug Output

Panic Output

 ~/test ī‚° gsutil rsync -r gs://dddwsd-test/train-template_base_terraform terraform/

WARNING: gsutil rsync uses hashes when modification time is not available at
both the source and destination. Your crcmod installation isn't using the
module's C extension, so checksumming will run very slowly. If this is your
first rsync since updating gsutil, this rsync can take significantly longer than
usual. For help installing the extension, please see "gsutil help crcmod".

Building synchronization state...
Starting synchronization...
Copying gs://dddwsd-test/train-template_base_terraform/...
Skipping attempt to download to filename ending with slash
(terraform/). This typically happens when using gsutil to download
from a subdirectory created by the Cloud Console
(https://cloud.google.com/console)
InvalidUrlError: Invalid destination path: terraform/.

Expected Behavior

in both gcs object, "gsutil rsync" operation should have completed successfully.

Actual Behavior

only "train-template_base_terrafom2" object has successfully finished "gsutil rsync"

Steps to Reproduce

  1. terraform apply
  2. mkdir terraform
  3. gsutil rsync -r gs://${bucket_name}/train-template_base_terraform terraform/

Important Factoids

  1. terraform must be connected with gcp.
  2. cloud storage architecture is not same as linux filesystem - https://cloud.google.com/storage/docs/folders?hl=ko#overview
  3. If you create a folder in the way it is shown in the official document, "gsutil rsync" does not work. - https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/storage_bucket_object.html#example-usage (According to google support, the content-length of the created folder is 1(content is " "), so the "gsutil rsync" command recognizes it as a file, not a dir.)
  4. if you create a folder with empty file, "gsutil rsync" is working successfully.
    resource "google_storage_bucket_object" "train-template_base_terraform3_object" {
    name   = "train-template_base_terraform3/empty"
    content = " "
    bucket = "dddwsd-test
    }

To sum up, I think it would be better to set the content-length to 0 or insert an empty file when creating an empty folder through google_storage_bucket_object.

References

edwardmedia commented 1 year ago

b/297175715