Skip to content

Commit 5a22ace

Browse files
author
Roberto Sanchez
committed
modified variables.tf, main.tf and added github action to create the artifact based on release tag
1 parent d58de89 commit 5a22ace

File tree

3 files changed

+46
-27
lines changed

3 files changed

+46
-27
lines changed

.github/workflows/lambda_zip.yaml

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,32 +8,26 @@ on:
88

99
jobs:
1010
build:
11-
run-on: ubuntu-latest
12-
# create the zip file
11+
runs-on: ubuntu-latest
12+
# create the zip file
1313
steps:
1414
- name: Checkout code
1515
uses: actions/checkout@v2
16+
1617
- name: Build Lambda Function
1718
run: |
18-
zip -9yr lambda.zip rolling-start.py
19-
- name: Create release
20-
id: create_release
21-
uses: actions/create-release@v1
22-
env:
23-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
24-
with:
25-
tag_name: ${{ github.ref }}
26-
release_name: Release ${{ github.ref }}
27-
draft: false
28-
prelease: true
19+
zip lambda.zip rolling-restart.py
20+
ls
21+
22+
- name: Get tag
23+
id: get_tag
24+
run: |
25+
echo ::set-output name=VTAG::$( echo $GITHUB_REF | cut -d / -f 3 )
26+
2927
- name: Upload lambda to assets
3028
id: upload-lambda-asset
31-
uses: actions/upload-release-assets@v1
32-
env:
33-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
29+
uses: AButler/[email protected]
3430
with:
35-
upload_url: ${{ steps.create_release.outputs.upload_url }}
36-
asset_path: ./lambda.zip
37-
asset_name: lambda.zip
38-
asset_content_type: application/zip
39-
31+
repo-token: ${{ secrets.GITHUB_TOKEN }}
32+
files: '*.zip'
33+
release-tag: ${{ steps.get_tag.outputs.VTAG }}

main.tf

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,40 @@
11
module "tags" {
22
source = "git::https://github.com/rhythmictech/terraform-terraform-tags.git?ref=v0.0.2"
33
tags = var.tags
4-
54
names = [
65
var.name,
76
"rolling-restart",
87
"lambda",
98
]
109
}
1110

11+
module "lambda_version" {
12+
source = "rhythmictech/find-release-by-semver/github"
13+
version = "~> 1.0"
14+
15+
repo_name = local.repo_name
16+
repo_owner = local.repo_owner
17+
version_constrain = "~2.0.1"
18+
}
19+
20+
locals {
21+
lambda_version = module.lambda_version.target_version
22+
lambda_version_tag = module.lambda_version.version_info.release_tag
23+
}
24+
25+
resource "null_resource" "lambda_zip" {
26+
triggers = {
27+
on_version_change = local.lambda_version
28+
}
29+
}
30+
31+
provisioner "local-exec" {
32+
command = "curl -Lso ${path.module/lambda.zip https://github.com/${local.repo_full_ame}/releases/download/${local.lambda_version_tag}/lambda.zip"
33+
}
34+
1235
data "archive_file" "this" {
1336
type = "zip"
14-
source_file = "${path.module}/rolling-restart.py"
15-
output_path = "${path.module}/tmp/lambda.zip"
37+
output_path = "${path.module}/lambda.zip"
1638
}
1739
1840
data "aws_iam_policy_document" "lambda_assume_role_policy" {
@@ -81,7 +103,7 @@ resource "random_uuid" "lambda_uuid" {}
81103
82104
83105
resource "aws_lambda_function" "this" {
84-
filename = data.archive_file.this.output_path
106+
filename = data.github_release.this.zipball_url.output
85107
function_name = "${module.tags.name32}_${substr(random_uuid.lambda_uuid.result, 0, 31)}"
86108
role = aws_iam_role.this.arn
87109
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+
full_repo_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)