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

path.module returning absolute paths #22708

Closed
007 opened this issue Sep 5, 2019 · 8 comments
Closed

path.module returning absolute paths #22708

007 opened this issue Sep 5, 2019 · 8 comments
Labels
bug config v0.12 Issues (primarily bugs) reported against v0.12 releases

Comments

@007
Copy link

007 commented Sep 5, 2019

Terraform Version

Terraform v0.12.5
+ provider.aws v2.15.0
+ provider.null v2.1.2
+ provider.random v2.1.2
+ provider.template v2.1.2

Can't update to 0.12.8 without coordinating with all other devs. That's a separate problem...

Terraform Configuration Files

resource "aws_lambda_function" "function_def" {
  filename      = "${path.module}/build/lambda.zip"
  function_name = var.lambda_name

Debug Output

Too sensitive / too much, can isolate if required.

Expected Behavior

State file should store relative path to lambda file. (../modules/lambda/reschedule/build/lambda.zip)

Actual Behavior

State file is storing absolute path to lambda file. (/Users/OTHERUSER/src/BRANCH/operations/tf/env-staging/.terraform/modules/CRAZY-HASH/build/lambda.zip)

  # module.reschedule.aws_lambda_function.function_def will be updated in-place
  ~ resource "aws_lambda_function" "function_def" {
        arn                            = "arn:aws:lambda:us-west-2:ACCOUNTID:function:reschedule"
      ~ filename                       = "/Users/OTHERUSER/src/BRANCH/operations/tf/env-staging/.terraform/modules/CRAZY-HASH/build/lambda.zip" -> "../modules/lambda/reschedule/build/lambda.zip"

Steps to Reproduce

  • Make a lambda with a path.module relative path for the file.
  • Use module from another directory.
  • Have user1 run apply and complete succesfully
  • Have user2 run plan

References

@hashibot hashibot added bug config v0.12 Issues (primarily bugs) reported against v0.12 releases labels Sep 5, 2019
@jbardin
Copy link
Member

jbardin commented Sep 6, 2019

Hi @007,

Sorry this is making the upgrade more difficult. From your description the current behavior is what you want. The path.module value in 0.12 is the relative path from the root module, and once you have upgraded the paths should all be identical across different systems.

If you need an absolute path similar to the 0.11 format, there is the abspath function. Note that this absolute path to the module in 0.12 still may not match because of differences in the module storage.

@jbardin jbardin closed this as completed Sep 6, 2019
@007
Copy link
Author

007 commented Sep 7, 2019

@jbardin I think you missed Terraform v0.12.5 - this is using 0.12 already, and still broken.

@jbardin
Copy link
Member

jbardin commented Sep 8, 2019

Hi @007, the 0.12 output above shows a new value of "../modules/lambda/reschedule/build/lambda.zip", which is a relative path. The existing absolute path you're seeing is most likely from an earlier version of terraform.

Just to ensure that the resource wasn't attempting to alter the path internally, I also created a lambda function using path.module and confirmed the relative path is stored in the state.

Are you seeing this after applying with 0.12, or is this during the upgrade process?

@007
Copy link
Author

007 commented Sep 8, 2019

We upgraded everything to 0.12 a while ago. This function was deployed since then, probably with 0.12.4, and it's still showing as an absolute path for another dev's machine when I'm deploying on 0.12.5.

@jbardin
Copy link
Member

jbardin commented Sep 8, 2019

The new path for this resource is a relative path as expected, and path.module is designed to now only return a relative path. The /CRAZY-HASH/ path segment in the example path also implies that this state was created from 0.11.

Can you show how the modules is configured, and have there been any recent configuration changes to the module at all? Can you apply these changes and see if there is still a diff after the filename is updated?

@007
Copy link
Author

007 commented Sep 9, 2019

There isn't a diff now, after the module is applied to reflect the updated relative-path.

How can the state be in 0.11 form when the transition to 0.12 - including removing all of the "${var.foo}" -> var.foo changes and updating the full state - happend in July? Is this user error, where we somehow missed a module during the full apply? Or does it not update state if it's only the path and not the underlying content that changed?

@jbardin
Copy link
Member

jbardin commented Sep 12, 2019

The only thing I can think of is that an apply was never done on this module+state after the upgrade. I don't see anything to indicate that it would have changed the value more recently, but if you think of any order of operations that could have resulted in the old path being applied, please let us know.

@ghost
Copy link

ghost commented Oct 7, 2019

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.

@ghost ghost locked and limited conversation to collaborators Oct 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug config v0.12 Issues (primarily bugs) reported against v0.12 releases
Projects
None yet
Development

No branches or pull requests

3 participants