Skip to content

Instantly share code, notes, and snippets.

@assertnotnull
Created April 24, 2020 20:05
Show Gist options
  • Save assertnotnull/5389053f4074679edf4ee09472e3b1cf to your computer and use it in GitHub Desktop.
Save assertnotnull/5389053f4074679edf4ee09472e3b1cf to your computer and use it in GitHub Desktop.
Use commit hash for file in s3 in terraform
locals {
file_path = "${var.path}/${var.file_name}"
commit_hash = data.external.commit_hash.result.commit
}
data "external" "commit_hash" {
program = ["echo", "{ \"commit\" : \"$(git rev-parse HEAD)\"}"]
}
resource "null_resource" "upload_zip_to_s3" {
triggers = {
zip_file_changed = filebase64sha256(local.file_path) // handle update latest version case
}
provisioner "local-exec" {
command = "aws s3 cp ${local.file_path} s3://${var.s3_bucket}/${var.s3_folder}/${data.external.commit_hash.result}.zip --profile ${var.aws_profile}"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment