Created
November 5, 2020 07:45
-
-
Save amacal/7a7968b1d5bd2c7daf3cfd879746546b to your computer and use it in GitHub Desktop.
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
# variables | |
variable "layer_file" {} | |
variable "layer_name" {} | |
variable "layer_runtime" {} | |
variable "deployment_bucket" {} | |
variable "deployment_file" {} | |
# compute hash | |
data "external" "hash" { | |
program = ["/bin/sh", "${path.module}/filebase64sha256.sh", var.layer_file] | |
} | |
# upload layer to S3 | |
resource "null_resource" "file" { | |
triggers = { | |
hash = data.external.hash.result.binary | |
from = var.layer_file | |
to = var.deployment_key | |
} | |
provisioner "local-exec" { | |
command = "aws s3 cp ${var.layer_file} s3://${var.deployment_bucket}/${var.deployment_key}-${data.external.hash.result.binary}" | |
} | |
} | |
# create/update the layer | |
resource "aws_lambda_layer_version" "layer" { | |
layer_name = var.layer_name | |
compatible_runtimes = [var.layer_runtime] | |
s3_bucket = var.deployment_bucket | |
s3_key = var.deployment_key | |
source_code_hash = data.external.hash.result.filebase64sha256 | |
depends_on = [null_resource.file] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment