Is there a pulumi way to do the following? As in z...
# typescript
w
Is there a pulumi way to do the following? As in zip a file/directory and get the md5 hash like this.
Copy code
data "archive_file" "source_archive" {
  source_dir  = var.source_directory
  output_path = "./main.zip"
  type        = "zip"
}

resource "google_storage_bucket_object" "archive" {
  name   = "${lower(replace(base64encode(data.archive_file.source_archive.output_md5), "=", ""))}.zip"
  bucket = google_storage_bucket.source_bucket.name
  source = data.archive_file.source_archive.output_path
}
I saw https://www.pulumi.com/docs/intro/concepts/assets-archives/#archives but as far as I can tell, it just represents an archive. It does not actually create the archive... Please correct me if i'm wrong.
g
AssetArchive will create the zip file for you.
w
Many thanks @gentle-diamond-70147. Could you recommend a library or method to do the md5 hash?
Hi @gentle-diamond-70147, I landed on this in the end.
Copy code
import * as SparkMD5 from 'spark-md5'
import * as pulumi from '@pulumi/pulumi'
import * as gcp from '@pulumi/gcp'

        const source_archive = new pulumi.asset.FileArchive(args.source_directory)

      
        const source_object = new gcp.storage.BucketObject('source_object', {
            name: pulumi.output(source_archive.path).apply(file => `${SparkMD5.hash(file)}.zip`),
            bucket: source_bucket.name,
            source: source_archive.path
        })
g
Looks great!
193 Views