-
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
provider/archive: Converting to datasource. #8492
Conversation
59e495a
to
848b67a
Compare
outputDirectory := path.Dir(outputPath) | ||
if outputDirectory != "" { | ||
if _, err := os.Stat(outputDirectory); err != nil { | ||
if err := os.MkdirAll(outputDirectory, 0777); err != nil { |
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 would prefer '0755' to be here.
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.
Good stuff.
I should probably do 0644 actually.
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.
If you do, you won't be able to enter the directory created. :)
@kwilczynski Done! |
98a1f03
to
9aaf9a1
Compare
@apparentlymart rebased to fix build, ready for review |
@BSick7 For informative purposes, could you explain a bit how did you avoid the flapping between runs from the code? (and was |
@Ninir The original resource code had an Exists function that returned true only if the archive file already existed. Since the file never survives the current plan in Atlas, it would appear as if it needed to always create the resource. Since it's now a datasource, the archive file is always generated. The sha is set as the id at the end of the read. This is what terraform uses to decipher whether the datasource appears new. |
@BSick7 Ok got it, thank you for the explanation! 👍 |
Hi @BSick7! This looks like a nice improvement - I'm going to pull it locally and verify the tests all still pass before merging. Thanks for the pull request! |
@@ -4,20 +4,15 @@ import ( | |||
"crypto/sha1" | |||
"encoding/hex" | |||
"fmt" | |||
"github.com/hashicorp/terraform/helper/schema" |
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 needs goimports
running. I'll do this when I pull locally.
HI @BSick7! I've pulled this into a branch in our repository (archive-data-source) and fixed up a few minor things. One thing I have noticed is that the tests are failing:
This makes sense since we never delete the file - we should determine whether that is correct behaviour or not and update the destroy check if so. |
Data sources don't have a Perhaps we could make this feel better as a data source by making the file it creates be explicitly a temporary file (e.g. in |
I like the idea of using |
It looks like we use When I originally suggested this I was thinking about the explicit provider "Close" step that we ostensibly support, which could in principle allow the archive provider to keep a list of all the files it created and then delete them once it is closed. However, digging deeper into the code I see that So this doesn't seem as straightforward as it did when I originally suggested it. We could try to add support for a So I think perhaps my suggestion can't be done right now without some core Terraform work. We could potentially just start using |
@jen20 @apparentlymart I'm still a little confused by the dangling resource issue. |
@BSick7 I think the issue is that the |
161f739
to
37257ea
Compare
Now fixes #8501 by adding |
c7aaf5e
to
b4fcb02
Compare
Updating docs.
b4fcb02
to
57314c4
Compare
It would be nice if this archive data source didn't require writing the file to disk. Instead there could be a source output which could be fed into other resources, eg aws_lambda_function. EDIT: Actually i just realized why this is a bad idea. We probably don't want people creating massive archives and then those being stored in the statefile. |
Can't wait to have this, so many issues will be resolved with this! thank you @BSick7 :) |
@jen20 I believe I have fixed this. |
Thanks @BSick7! One of us will review this over the next day or two for inclusion in the next version of Terraform. |
Hi @BSick7 This works now as expected :)
Thanks for the work here! |
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. |
Since the output file is always generated, you will get flapping between runs.
It makes sense to just convert to datasource and always generate a new archive file, but only show as new if sha of output file is different.