-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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
Using ${path.module} in aws_lambda_function filename results in incorrect "difference" between user machines #7613
Comments
+1 I'm seeing this too. |
Ahh yes, we've seen this sort of issue before with paths in config. It was one of the reasons why we moved to primarily using the A different workaround could be to write a A different way to do it would be to make the A further way we addressed this in some cases in the past was to make the |
I'm running into this as well. Using the path.module saves the variable in the tfstate file. Is there a command that will not save a path in the tfstate but instead always interpolate the path at runtime? |
A possible workaround in the short term would be to use the ignore_changes = ["filename"] I didn't test this, but I believe it should cause Terraform to not generate a diff when only the filename has changed. |
I had a similar issue with the |
We now have a feature in helper/schema to allow attributes to customize their diffing behavior, so we might be in a better position to do what I described earlier around ignoring this attribute for diffing purposes, or changing it to normalize the path in some way. What do you think, @jen20? ( I am thinking of the thing you did to allow us to normalize IAM policies when diffing.) |
@apparentlymart I actually think the diffing should be based on the hash of the contents of the file, unfortunately. Normalizing the path would likely be fairly tedious/difficult. The particularly annoying part about this function is that it is sometimes used to upload fairly large (megabytes) files and if you have a lot, then reading and hashing all of them on a Hm. |
Dup of #8204, we'll use that there. |
I found a workaround to this using the current working directory data "archive_file" "slack_notification_zip" {
type = "zip"
output_path = "${path.module}/lambda.zip"
source_dir = "${path.module}/source/"
}
resource "aws_lambda_function" "slack_notification" {
filename = "${substr(data.archive_file.slack_notification_zip.output_path, length(path.cwd) + 1, -1)}"
// +1 for removing the "/"
} |
For reference, You can also solve this problem by doing something like data "null_data_source" "path-to-some-file" {
inputs {
filename = "${substr("${path.module}/path/to/file", length(path.cwd) + 1, -1)}"
}
}
resource "aws_lambda_function" "slack_notification" {
filename = "${data.null_data_source.path-to-some-file.outputs.filename}"
} (useful in the general case when it's not necessarily an archive_file) |
Just ran into this issue using shared state on Terraform Community Module https://github.com/terraform-aws-modules/terraform-aws-notify-slack/ |
@etaty I assume in your workaround that the state does change for the In the docs on paths and embedded files, it says
In the OP's question the example is The way I read it, ...I think I've just answered my question which was why does this work, or more to the point, how is this workaround any different from just using a relative path? Seems it is because Terraform is caching modules into these UUID directories which |
The terraform filename parameter encodes an absolute path to the module, which can be different when run on different machines. This changes it to key on a relative path, per the recommendation here: hashicorp/terraform#7613 (comment)
* Use a relative path to prevent spurious terraform changes. The terraform filename parameter encodes an absolute path to the module, which can be different when run on different machines. This changes it to key on a relative path, per the recommendation here: hashicorp/terraform#7613 (comment) * Add debug logging
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. |
I'm writing this as a bug report, but it's possible I'm just not using
path.module
correctly (I followed the recommendation https://www.terraform.io/docs/modules/create.html). Let me know if there's an easy workaround!Terraform Version
Terraform v0.6.16
Affected Resource(s)
Terraform Configuration Files
This is logging/main.tf, which is used as a module by parent:
Expected Behavior
After a
terraform apply
is run by user A, new tfstate is committed to repo. User B pulls and runsterraform plan
. It is expected that there are no changes.Actual Behavior
Because
filename = "${path.module}/lambda.zip"
, the filename stored in state looks something like"filename": "/Users/josh/path/to/terraform/.terraform/modules/79cd4d17db98b26baebfcf1024aade92/lambda.zip"
. As a result, when damon runsterraform plan
, he gets:Steps to Reproduce
Please list the steps required to reproduce the issue, for example:
The text was updated successfully, but these errors were encountered: