-
Notifications
You must be signed in to change notification settings - Fork 63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The archive_file resource now zips directories during terraform plan and ignores depends_on #78
Comments
This does not seem likely to be an issue with the |
I have the same problem on my configuration when i try to create an lambda : Error: error archiving directory: could not archive missing directory: ./.terraform/temp/GTUKucTyx-0/lambda-response on AWS-App_FE.tf line 115, in data "archive_file" "lambda_edge_function_files": Try to do this with terraform 0.13.2 |
Same for me. All work with terraform 0.12.29 but not with version ^0.13 |
Any traction on this at all? Still blocking upgrade to v0.13. |
Hello any news ? |
Anyone find a workaround or solution to this? I'm blocked on the same. |
This seems to be happening when terraform is refreshing the state. So it works (for me at least, w/ v0.13.5) on the initial apply, but if the |
@dparker2 - confirmed, I'm seeing the same. My only workaround at this point is to run |
@apparentlymart - It looks like this might be the bug described in 0.14.0 release notes. Can you confirm if this looks like it may be related to that issue?
... as listed here in 0.14.0-rc1 release notes regarding fix described here: hashicorp/terraform#26270 Also:
|
Thanks @aaronsteers, this type of issue will be resolved with 0.14. |
Thanks, @jbardin ! By chance is there an expected release date for 0.14 or a ticket I can follow which would cover that timeline? For my case, we've already upgraded to 0.13.4, including our our state files - so rolling back to 0.12.x would be a very difficult option for us. |
Update: I found the forum on Discuss - looks like ETA for 0.14.0 GA is next week. https://discuss.hashicorp.com/t/terraform-v0-14-0-rc1-released/15752/14 I'll start testing with the RC1 with the expectation/hope we'll make a quick transition once released. |
Still have the problem with terraform 0.14 |
@antondemidov - I can't speak to any remnants of the However, I do know there was a workaround described in another ticket (long ago, I'm afraid), in which there was a recommendation to pipe dependencies through a UPDATE: this stack overflow answer seems to describe the workaround concisely: https://stackoverflow.com/a/58585612/4298208 And the related issues pointed to in the stackoverflow are: |
Thanks, @aaronsteers. I'll take a look btw, I've found some workaround. Just to use
|
@jbardin So other than the workaround mentioned by @antondemidov how is one to migrate from 12 to 14, if the 14 migration docs specifically mention that you need to do at least one apply with 13 before going to 14 this seems like it is kind of a blocker for anyone migrating from 12, if they cannot migrate to 13. I tried the null_data_source workaround mentioned by @aaronsteers and it did not help. |
@antondemidov - RE:
I was actually going in this direction also when you posted this. In terms of the right 'terraform way', I think the solution is worth merit. New platform-agnostic solution for using native zip on any OS.I followed the same general approach as @antondemidov - except that I needed it to work on Windows as well as Linux-based systems. (Caveat: Even though I've now tested this on both Ubuntu and Windows 10, I don't know that I have the
locals {
source_files_hash = join(",", [
for filepath in local.source_files :
filebase64sha256("${var.local_metadata_path}/${filepath}")
])
unique_hash = md5(local.source_files_hash)
unique_suffix = substr(local.unique_hash, 0, 4)
}
resource "null_resource" "create_dependency_zip" {
triggers = {
version_increment = 1.1 # can be bumped to manually force a refresh
source_files_hash = local.source_files_hash
}
provisioner "local-exec" {
interpreter = local.is_windows ? ["Powershell", "-Command"] : ["/bin/bash", "-c"]
command = join(local.is_windows ? "; " : " && ", flatten(
# local.local_requirements_file == null ? [] :
local.is_windows ?
[
[
"echo \"Creating target directory '${abspath(local.temp_build_folder)}'...\"",
"New-Item -ItemType Directory -Force -Path ${abspath(local.temp_build_folder)}",
"echo \"Copying directory contents from '${abspath(var.lambda_source_folder)}/' to '${abspath(local.temp_build_folder)}/'...\"",
"Copy-Item -Force -Recurse -Path \"${abspath(var.lambda_source_folder)}/*\" -Destination \"${abspath(local.temp_build_folder)}/\"",
"echo \"Granting execute permissions on temp folder '${local.temp_build_folder}'\"",
"icacls ${local.temp_build_folder} /grant Everyone:F",
"icacls ${local.temp_build_folder}/* /grant Everyone:F",
],
local.local_requirements_file == null ? [] : !fileexists(local.local_requirements_file) ? [] :
[
"echo \"Running pip install from requirements '${abspath(local.local_requirements_file)}'...\"",
"${local.pip_path} install --upgrade -r ${abspath(local.local_requirements_file)} --target ${local.temp_build_folder}",
],
[
"sleep 3",
"echo \"Changing working directory to temp folder '${abspath(local.temp_build_folder)}'...\"",
"cd ${abspath(local.temp_build_folder)}",
"echo \"Zipping contents of ${abspath(local.temp_build_folder)} to '${abspath(local.local_dependencies_zip_path)}'...\"",
"ls",
"tar -acf ${abspath(local.local_dependencies_zip_path)} *",
]
] :
[
[
"echo \"Creating target directory '${abspath(local.temp_build_folder)}'...\"",
"set -e",
"mkdir -p ${local.temp_build_folder}",
"echo \"Copying directory contents from '${abspath(var.lambda_source_folder)}/' to '${abspath(local.temp_build_folder)}/'...\"",
"cp ${var.lambda_source_folder}/* ${local.temp_build_folder}/",
],
local.local_requirements_file == null ? [] : !fileexists(local.local_requirements_file) ? [] :
[
"echo \"Running pip install from requirements '${abspath(local.local_requirements_file)}'...\"",
"${local.pip_path} install --upgrade -r ${local.temp_build_folder}/requirements.txt --target ${local.temp_build_folder}",
],
[
"sleep 3",
"echo \"Granting execute permissions on temp folder '${local.temp_build_folder}'\"",
"chmod -R 755 ${local.temp_build_folder}",
"cd ${abspath(local.temp_build_folder)}",
"echo \"Zipping contents of '${abspath(local.temp_build_folder)}' to '${abspath(local.local_dependencies_zip_path)}'...\"",
"zip -r ${abspath(local.local_dependencies_zip_path)} *",
]
]
))
}
}
Quick note regarding native
|
I don't seem to have the problem in 0.14. I'm using v0.14.9 with this smaller test: # main.tf
resource "null_resource" "zip" {
triggers = {
# Not the best to use here but works well enough
create_file = fileexists("${path.module}/folder_to_zip/new_file")
}
provisioner "local-exec" {
working_dir = "folder_to_zip"
command = "touch new_file"
}
}
data "archive_file" "zip" {
depends_on = [null_resource.zip]
type = "zip"
source_dir = "folder_to_zip"
output_path = "output.zip"
} Commands I ran: mkdir folder_to_zip
terraform init
terraform apply The Unless maybe I misunderstood the problem here. |
I think this simply highlights a race condition. Touching a file is incredibly fast. Running pip install isn't. Not to mention your directory already exists before you start whereas some are attempting to move the source files to a new folder, build dependencies, then zipping. Local_exec and archive_file are running in parallel on different threads and thus you did not hit the problem. You can test this by replacing command = "touch new_file" with command = "sleep 20; touch new_file". Seems sad but the only way I see to solve this issue is to do the zipping inside local_exec, which makes cross platform quite painful. Overall it seems to me to be a problem with how archive_file is implemented. A Resource is an object you wish Terraform to create an manage. A Datasource is an object that exists that you want Terraform to refer to. In my mind its obvious if we are creating an archive file that concept would be a Resource to Terraform. I'm sure there are good deeper level reasons why the team decided change this provider in the way they did. These guys are smart. But it seems to violate the design principals of Terraform itself. |
Any update on this? |
This issue was originally opened by @rluckey-tableau as hashicorp/terraform#26064. It was migrated here as a result of the provider split. The original body of the issue is below.
Terraform Version
Terraform Configuration Files
Debug Output
Crash Output
Expected Behavior
Actual Behavior
Steps to Reproduce
terraform init
terraform plan
Additional Context
This is running on GitLab CI/CD runners. It has been working fine for at least the past year on various versions of Terraform 0.12 up through Terraform 0.12.21.
In case it is useful, here are the provider versions being pulled when using Terraform 0.13.1:
Edit: Tested the same TF code with a 0.12.29 image and
terraform plan
passed with no issues, even though it is pulling the same provider versions.References
The text was updated successfully, but these errors were encountered: