From f6058c1dc770827748df3e9bf2a94ac15f8046f4 Mon Sep 17 00:00:00 2001 From: tetsuya28 Date: Mon, 1 Jan 2024 00:47:28 +0900 Subject: [PATCH] Fix release Terraform --- .github/workflows/build.yaml | 2 +- module/main.tf | 28 ++++++++++++++++++++++++---- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index fbfdf9a..196ca05 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -45,7 +45,7 @@ jobs: - name: Build run: | - GOOS=${{ matrix.os }} GOARCH=${{ matrix.arch }} go build -o aws-cost-report main.go + GOOS=${{ matrix.os }} GOARCH=${{ matrix.arch }} CGO_ENABLED=0 go build -o aws-cost-report main.go - name: Zip run: zip ${{ matrix.os }}-${{ matrix.arch }}-aws-cost-report.zip aws-cost-report diff --git a/module/main.tf b/module/main.tf index dda0fcc..94f28a8 100644 --- a/module/main.tf +++ b/module/main.tf @@ -5,15 +5,34 @@ variable "schedule_expression" { default = "cron(0 0 * * ? *)" } variable "build_version" { - default = "v0.0.0" + default = "v0.1.0" +} + +locals { + lambda_zip_file = format("%s/.terraform/%s.zip", path.root, var.build_version) +} + +data "github_release" "this" { + owner = "tetsuya28" + repository = "aws-cost-report" + retrieve_by = "tag" + release_tag = var.build_version +} + +resource "null_resource" "this" { + triggers = { + timestamp = timestamp() + } + provisioner "local-exec" { + command = "wget -O ${local.lambda_zip_file} ${data.github_release.this.assets[2].browser_download_url}" + } } resource "aws_lambda_function" "this" { function_name = var.name - s3_bucket = "tetsuya28-aws-cost-report" - s3_key = "${var.build_version}/main.zip" runtime = "go1.x" - handler = "main" + handler = "aws-cost-report" + filename = local.lambda_zip_file memory_size = 128 timeout = 10 role = aws_iam_role.this.arn @@ -23,6 +42,7 @@ resource "aws_lambda_function" "this" { "SLACK_CHANNEL" = var.slack_channel } } + depends_on = [null_resource.this] } resource "aws_cloudwatch_log_group" "this" {