terraform-provider-local icon indicating copy to clipboard operation
terraform-provider-local copied to clipboard

Output property of generated file for local_file resource

Open jack-parsons-bjss opened this issue 3 years ago • 1 comments

Terraform CLI and Provider Versions

Terraform v1.2.9
on linux_amd64
+ provider registry.terraform.io/hashicorp/archive v2.2.0
+ provider registry.terraform.io/hashicorp/aws v4.29.0
+ provider registry.terraform.io/hashicorp/local v2.2.3

Use Cases or Problem Statement

We appear to be unable to depend on the output of this resource; we are trying to use this to generate a file from some content we pass in to create an AWS Lambda function. The Lambda resource is throwing errors that the file location does not exist on the disk, even after apparently data sourcing the local file resource:

│ 
│   on ../../modules/lambdacron/lambda_function.tf line 33, in resource "aws_lambda_function" "main":
│   33:         filebase64sha256(var.function_zip_base64 == null ? local.archive_path : data.local_file.archive[0].filename) :
│     ├────────────────
│     │ data.local_file.archive[0].filename is "./work/bjss-494849242700-eu-west-2-prod-granted-lambdacron-idp-sync/function.zip"
│     │ local.archive_path is "./work/bjss-494849242700-eu-west-2-prod-granted-lambdacron-idp-sync/function.zip"
│     │ var.function_zip_base64 is "UEsDBAoAAAAAAI97KFUQIvvVBQAAAAUAAAAIABwAaW5kZXguanNVVAkAAw78GWMO/BljdXgLAAEE6AMAAARkAAAAZXhpdApQSwECHgMKAAAAAACPeyhVECL71QUAAAAFAAAACAAYAAAAAAABAAAApIEAAAAAaW5kZXguanNVVAUAAw78GWN1eAsAAQToAwAABGQAAABQSwUGAAAAAAEAAQBOAAAARwAAAAAA"
│ 
│ Call to function "filebase64sha256" failed: open work/bjss-494849242700-eu-west-2-prod-granted-lambdacron-idp-sync/function.zip: no such file or directory.
╵

Proposal

Output an attribute of the generated file - the octal permissions perhaps, or a file hash - which would allow us to depend on the attribute without needing to duplicate the content of the file in the output.

How much impact is this issue causing?

Low

Additional Information

No response

Code of Conduct

  • [X] I agree to follow this project's Code of Conduct

jack-parsons-bjss avatar Sep 09 '22 08:09 jack-parsons-bjss

#142 looks like it would solve this too.

tristanmorgan avatar Sep 13 '22 22:09 tristanmorgan

Hi @jack-parsons-bjss 👋 Thank you for raising this. As @tristanmorgan mentions above, recent versions of the local_file data source and resource now include additional attributes containing hashes of file contents. This is the correct and expected method for getting those values. Built-in Terraform configuration functions, such as file handling ones, only operate during configuration parsing rather than participating in the graph.

bflad avatar May 03 '23 20:05 bflad

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

github-actions[bot] avatar May 23 '24 07:05 github-actions[bot]