Created
April 24, 2020 20:05
-
-
Save assertnotnull/5389053f4074679edf4ee09472e3b1cf to your computer and use it in GitHub Desktop.
Use commit hash for file in s3 in terraform
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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