Skip to content

Commit 5a29b9c

Browse files
author
Scott Miller
authored
Merge pull request #2 from rhythmictech/shasum
shasum
2 parents 50bd75a + 8b7f30a commit 5a29b9c

File tree

4 files changed

+64
-13
lines changed

4 files changed

+64
-13
lines changed

.github/workflows/lambda_zip.yaml

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Create a zipped lambda func for deployment
1+
name: release
22

33
on:
44
release:
@@ -16,13 +16,43 @@ jobs:
1616
- name: Build Lambda Function
1717
run: |
1818
zip lambda.zip rolling-restart.py
19+
ls
1920
20-
- name: Upload lambda to assets
21-
uses: actions/upload-release-asset@v1.0.2
21+
- name: upload zip artifact
22+
uses: actions/upload-artifact@v2
23+
with:
24+
name: lambda.zip
25+
path: ${{ github.workspace }}/lambda.zip
26+
if-no-files-found: error
27+
28+
- name: get checksum
29+
run: cat lambda.zip | openssl dgst -binary -sha256 | base64 > lambda.sha256base64
30+
31+
- name: upload shasum artifact
32+
uses: actions/upload-artifact@v2
33+
with:
34+
name: lambda.sha256base64
35+
path: ${{ github.workspace }}/lambda.zip
36+
if-no-files-found: error
37+
38+
- name: Upload zip
39+
id: upload-zip
40+
uses: actions/upload-release-asset@v1
2241
env:
2342
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2443
with:
2544
upload_url: ${{ github.event.release.upload_url }}
2645
asset_path: ./lambda.zip
2746
asset_name: lambda.zip
2847
asset_content_type: application/zip
48+
49+
- name: Upload shasum
50+
id: upload-shasum
51+
uses: actions/upload-release-asset@v1
52+
env:
53+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
54+
with:
55+
upload_url: ${{ github.event.release.upload_url }}
56+
asset_path: ./lambda.sha256base64
57+
asset_name: lambda.sha256base64
58+
asset_content_type: text/plain

getsha.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#! /usr/bin/env bash
2+
ARGS=($(jq -r --unbuffered '.repo_full_name,.tag'))
3+
curl -Ls "https://github.com/${ARGS[0]}/releases/download/${ARGS[1]}/lambda.sha256base64" | jq -cR '{"sha": .}'

main.tf

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
module "tags" {
2-
source = "git::https://github.com/rhythmictech/terraform-terraform-tags.git?ref=v0.0.2"
2+
source = "rhythmictech/tags/terraform"
3+
version = "~> 1.1"
34
tags = var.tags
4-
5+
56
names = [
67
var.name,
78
"rolling-restart",
@@ -15,7 +16,7 @@ module "lambda_version" {
1516

1617
repo_name = local.repo_name
1718
repo_owner = local.repo_owner
18-
version_constraint = "~1.0.1-rc5"
19+
version_constraint = var.lambda_version_constraint
1920
}
2021

2122
locals {
@@ -29,10 +30,20 @@ resource "null_resource" "lambda_zip" {
2930
}
3031

3132
provisioner "local-exec" {
32-
command = "curl -Lso ${path.module}/lambda.zip https://github.com/${local.repo_full_name}/releases/download/${local.lambda_version_tag}/lambda.zip"
33+
command = "curl -Lso lambda-${local.lambda_version}.zip https://github.com/${local.repo_full_name}/releases/download/${local.lambda_version_tag}/lambda.zip"
3334
}
3435
}
3536

37+
data "external" "sha" {
38+
program = [
39+
"${path.module}/getsha.sh"
40+
]
41+
42+
query = {
43+
repo_full_name = local.repo_full_name
44+
tag = local.lambda_version_tag
45+
}
46+
}
3647

3748
data "aws_iam_policy_document" "lambda_assume_role_policy" {
3849
statement {
@@ -82,7 +93,6 @@ data "aws_iam_policy_document" "lambda_policy_doc" {
8293
"*"
8394
]
8495
}
85-
8696
}
8797

8898
resource "aws_iam_role_policy" "this" {
@@ -98,26 +108,28 @@ resource "aws_iam_role_policy_attachment" "lambda-execution-role-attach" {
98108

99109
resource "random_uuid" "lambda_uuid" {}
100110

101-
102111
resource "aws_lambda_function" "this" {
103-
filename = "${path.module}/lambda.zip"
112+
filename = "lambda-${local.lambda_version}.zip"
104113
function_name = "${module.tags.name32}_${substr(random_uuid.lambda_uuid.result, 0, 31)}"
105114
role = aws_iam_role.this.arn
106115
handler = "rolling-restart.handler"
107116
runtime = "python3.6"
108117
timeout = 600
109-
source_code_hash = data.archive_file.this.output_base64sha256
118+
source_code_hash = data.external.sha.result.sha
110119
tags = module.tags.tags
120+
111121
environment {
112122
variables = {
113123
ASG_NAME = var.asg_name
114124
LOGLEVEL = var.loglevel
115125
}
116126
}
127+
117128
lifecycle {
118129
ignore_changes = [
119-
filename,
120-
last_modified,
130+
last_modified
121131
]
122132
}
133+
134+
depends_on = [null_resource.lambda_zip]
123135
}

variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ locals {
1010
repo_name = "terraform-aws-asg-rolling-restart-lambda"
1111
}
1212

13+
variable "lambda_version_constraint" {
14+
default = "~1.0.1-rc9"
15+
description = "NPM style version constraint to apply when looking for the correct version of the lambda code"
16+
type = string
17+
}
18+
1319
variable "loglevel" {
1420
type = string
1521
default = "INFO"

0 commit comments

Comments
 (0)