Skip to content

Commit 50bd75a

Browse files
authored
Merge pull request #3 from rhythmictech/ENG-1412.1
Eng 1412.1
2 parents b32ea24 + 6a0f01c commit 50bd75a

File tree

4 files changed

+59
-8
lines changed

4 files changed

+59
-8
lines changed

.github/workflows/lambda_zip.yaml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Create a zipped lambda func for deployment
2+
3+
on:
4+
release:
5+
types:
6+
- created
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
# create the zip file
12+
steps:
13+
- name: Checkout code
14+
uses: actions/checkout@v2
15+
16+
- name: Build Lambda Function
17+
run: |
18+
zip lambda.zip rolling-restart.py
19+
20+
- name: Upload lambda to assets
21+
uses: actions/upload-release-asset@v1.0.2
22+
env:
23+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
24+
with:
25+
upload_url: ${{ github.event.release.upload_url }}
26+
asset_path: ./lambda.zip
27+
asset_name: lambda.zip
28+
asset_content_type: application/zip

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
.vscode
22
venv
3+
.terraform

main.tf

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,39 @@
11
module "tags" {
22
source = "git::https://github.com/rhythmictech/terraform-terraform-tags.git?ref=v0.0.2"
33
tags = var.tags
4-
4+
55
names = [
66
var.name,
77
"rolling-restart",
88
"lambda",
99
]
1010
}
1111

12-
data "archive_file" "this" {
13-
type = "zip"
14-
source_file = "${path.module}/rolling-restart.py"
15-
output_path = "${path.module}/tmp/lambda.zip"
12+
module "lambda_version" {
13+
source = "rhythmictech/find-release-by-semver/github"
14+
version = "~> 1.0"
15+
16+
repo_name = local.repo_name
17+
repo_owner = local.repo_owner
18+
version_constraint = "~1.0.1-rc5"
19+
}
20+
21+
locals {
22+
lambda_version = module.lambda_version.target_version
23+
lambda_version_tag = module.lambda_version.version_info.release_tag
24+
}
25+
26+
resource "null_resource" "lambda_zip" {
27+
triggers = {
28+
on_version_change = local.lambda_version
29+
}
30+
31+
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+
}
1634
}
1735

36+
1837
data "aws_iam_policy_document" "lambda_assume_role_policy" {
1938
statement {
2039
actions = [
@@ -81,7 +100,7 @@ resource "random_uuid" "lambda_uuid" {}
81100

82101

83102
resource "aws_lambda_function" "this" {
84-
filename = data.archive_file.this.output_path
103+
filename = "${path.module}/lambda.zip"
85104
function_name = "${module.tags.name32}_${substr(random_uuid.lambda_uuid.result, 0, 31)}"
86105
role = aws_iam_role.this.arn
87106
handler = "rolling-restart.handler"

variables.tf

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@ data "aws_caller_identity" "current" {}
33

44

55
locals {
6-
account_id = data.aws_caller_identity.current.account_id
7-
region = data.aws_region.current.name
6+
account_id = data.aws_caller_identity.current.account_id
7+
region = data.aws_region.current.name
8+
repo_full_name = "${local.repo_owner}/${local.repo_name}"
9+
repo_owner = "rhythmictech"
10+
repo_name = "terraform-aws-asg-rolling-restart-lambda"
811
}
912

1013
variable "loglevel" {

0 commit comments

Comments
 (0)