terraform-cdk icon indicating copy to clipboard operation
terraform-cdk copied to clipboard

Provide Common Temporary Directory

Open skorfmann opened this issue 3 years ago • 5 comments

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Description

I've been repeating this pattern across several test projects:

    const tmpWorkDir = path.join(process.cwd(), 'tmp', 'build', 'data-sources')
    fs.mkdirSync(tmpWorkDir, { recursive: true })
    const filePath = path.join(tmpWorkDir, `${name}-data-source.js`)

That's useful whenever a user wants to write generated files to disk and use it in conjunction with TerraformAsset.

It would be nice to have something like:

const tmpFile = new TmpFile(this, 'my-file', {
  content: `my file contents`
})

new TerraformAsset(this, 'data-source-asset', {
  path: tmpFile.path,
  type: AssetType.FILE,
});

// or perhaps even just like this

new TmpFile(this, 'my-file', {
  content: `my file contents`
  distributeAs: AssetType.FILE
})

References

skorfmann avatar Jul 08 '21 08:07 skorfmann

Sounds interesting!

Just a random idea: Why not extending TerraformAsset (or composing with it in some other way), so that the TmpFile itself would "be the Asset". Or is there any use case to just writing the TmpFile?

How I would imagine using it:

const tmpFile = new TmpFile(this, 'file', {
  content: `<html><body>Welcome to my empty website</body></html>`
})

new S3BucketObject(this, "index", {
      bucket: bucket.bucket,
      key: 'index.html',
      source: tmpFile.path,
});

ansgarm avatar Jul 08 '21 13:07 ansgarm

Why not extending TerraformAsset (or composing with it in some other way), so that the TmpFile itself would "be the Asset".

I think that would make sense indeed 👍

Perhaps it's more something like GeneratedFile or FileGenerator?

skorfmann avatar Jul 08 '21 13:07 skorfmann

InlineFile? 😄 (I'm not 100% satisfied with this name though)

ansgarm avatar Jul 08 '21 14:07 ansgarm

InlineFile? 😄

Hm, not bad - I like that 👍

skorfmann avatar Jul 08 '21 19:07 skorfmann

@skorfmann @ansgarm can you guys plz explain little bit more about this issue. I am interested in working on it.

aayushharwani-aidash avatar May 07 '22 11:05 aayushharwani-aidash