|
1 | 1 | module "tags" { |
2 | 2 | source = "git::https://github.com/rhythmictech/terraform-terraform-tags.git?ref=v0.0.2" |
3 | 3 | tags = var.tags |
4 | | - |
5 | 4 | names = [ |
6 | 5 | var.name, |
7 | 6 | "rolling-restart", |
8 | 7 | "lambda", |
9 | 8 | ] |
10 | 9 | } |
11 | 10 |
|
| 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 | +
|
12 | 35 | data "archive_file" "this" { |
13 | 36 | 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" |
16 | 38 | } |
17 | 39 |
|
18 | 40 | data "aws_iam_policy_document" "lambda_assume_role_policy" { |
@@ -81,7 +103,7 @@ resource "random_uuid" "lambda_uuid" {} |
81 | 103 |
|
82 | 104 |
|
83 | 105 | resource "aws_lambda_function" "this" { |
84 | | - filename = data.archive_file.this.output_path |
| 106 | + filename = data.github_release.this.zipball_url.output |
85 | 107 | function_name = "${module.tags.name32}_${substr(random_uuid.lambda_uuid.result, 0, 31)}" |
86 | 108 | role = aws_iam_role.this.arn |
87 | 109 | handler = "rolling-restart.handler" |
|
0 commit comments