Skip to content
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

Output property of generated file for local_file resource #140

Closed
1 task done
jack-parsons-bjss opened this issue Sep 9, 2022 · 3 comments
Closed
1 task done

Comments

@jack-parsons-bjss
Copy link

jack-parsons-bjss commented Sep 9, 2022

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

  • I agree to follow this project's Code of Conduct
@tristanmorgan
Copy link
Member

#142 looks like it would solve this too.

@bflad
Copy link
Contributor

bflad commented May 3, 2023

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 bflad closed this as completed May 3, 2023
Copy link

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 github-actions bot locked as resolved and limited conversation to collaborators May 23, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants