Unable to archive source code directory in terraform/terragrunt: archive has not been created as it would be empty

85 Views Asked by At

The error occured when trying to use data "archive_file" to zip the source code directory, the path of the directory is correct, but the console does not recognize the source code file inside the directory.

Below is the code snippet in cloud_functions.tf:

data "archive_file" "source" {
  type        = "zip"
  source_dir  = "../../../source/"
  output_path = "../../../source/temp/test_source.zip"
}

Below is the error:

│ Error: Archive creation error
│ 
│   with data.archive_file.source,
│   on cloud_function.tf line 28, in data "archive_file" "source":
│   28: data "archive_file" "source" {
│ 
│ error creating archive: error archiving directory: archive has not been
│ created as it would be empty

The folder structure looks like below:

.
├── env
│   └── npe
│       └── cloud-function
│           └── terragrunt.hcl
│           └── vars.hcl
├── modules
│   └── cloud-function
│       └── cloud_function.tf
│       └── variables.tf
├── source
│   └── main.py
├── .gitlab-ci.yml
└── terragrunt.hcl

When using resource "google_storage_bucket_object" to upload the single main.py the error is similar by saying "no such file or directory".

Any help would be appreciated!

1

There are 1 best solutions below

1
user22640058 On BEST ANSWER

Question solved, the source folder needs to be placed under the module folder.

.
├── modules
│   └── cloud-function
│       └── source
│           └── main.py
│       └── cloud_function.tf
│       └── variables.tf