-
-
Notifications
You must be signed in to change notification settings - Fork 29
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
Use relative paths for archives #11
Conversation
@raymondbutcher thanks for this fix! Makes sense. This was a bug =) |
main.tf
Outdated
@@ -47,13 +47,13 @@ data "aws_iam_policy_document" "ami_backup" { | |||
data "archive_file" "ami_backup" { | |||
type = "zip" | |||
source_file = "${path.module}/ami_backup.py" | |||
output_path = "${path.module}/ami_backup.zip" | |||
output_path = ".terraform/terraform-aws-ec2-ami-backup/backup-${md5(file("${path.module}/ami_backup.py"))}.zip" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm concerned with the portability of hardcoding both .terraform
and the module name terraform-aws-ec2-ami-backup
which is subject to change in forks.
I propose the following:
- create a new variable called
tfstate_dir
and default it to.terraform
- use a
local
calledmodule_name
which is derived frombasename(path.module)
- use a
local
to define anoutput_dir
which is equal to${tfstate_dir}/${module_name}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is also a nice fix: hashicorp/terraform#8204 (comment)
Take your pick =)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See inline comments.
Thanks @osterman, fair points. I've done a (nicer IMO) variation of hashicorp/terraform#8204 (comment) that was suggested and this is the resulting plan:
As per my commit message:
I think it's safe to assume that. hashicorp/terraform#8204 (comment) makes the same assumption. |
This fixes issues when multiple people are working on the same project and they have the project located in different places.
This removes the assumption about Terraform making a .terraform directory in the current working directory, and removes the need to use md5 to handle multiple module versions in the same project as Terraform deals with that itself. It now assumes that the module is located within the current working directory.
0eccf57
to
f0ba1b9
Compare
We have one other PR we should merge before this one. We will take care of this today. |
what
why
This fixes issues when multiple people are working on the same project and they have the project located in different places.
Before this change, we were seeing plans like:
We've tested this change and the plans are now clean.
I've used relative paths like this in other modules/projects, putting archives in the
.terraform
directory, and haven't had any issues so far. An md5 is used in the filename to avoid conflicts with multiple versions of this module being used in the same project (unlikely but it's better to be safe).