Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Issue]: Terraform should only build+deploy Lambdas with changes #66

Closed
TylerHendrickson opened this issue Apr 28, 2023 · 2 comments · Fixed by #284 or #291
Closed

[Issue]: Terraform should only build+deploy Lambdas with changes #66

TylerHendrickson opened this issue Apr 28, 2023 · 2 comments · Fixed by #284 or #291
Labels
enhancement New feature or request good first issue Good for newcomers Grant Finder

Comments

@TylerHendrickson
Copy link
Member

Why is this issue important?

Building, uploading, and publishing all Lambda functions on every terraform apply makes iterating on Terraform changes slower than it needs to be. As a (much) secondary concern, it also uploads/publishes more Lambda artifacts than are necessary.

Current State

When terraform apply runs, every Lambda function is re-deployed regardless of whether they have changed.

The terraform-aws-modules/lambda/aws Terraform module that we use to facilitate Lambda deployments has facilities for comparing checksums of local builds against previous local builds (cached in terraform/builds), and should also be able to compare against remote (S3-hosted) artifacts. However, that doesn't seem to be having any effect in our current setup, which for the most part is customized by the source_path input to each Lambda module and looks like this:

source_path = [{
  path = var.lambda_code_path
  commands = [
    "task build-DownloadGrantsGovDB",
    "cd bin/DownloadGrantsGovDB",
    ":zip",
  ],
}]

Additionally, our Taskfile configuration (which is used by Terraform in order to build Lambdas) also short-circuits builds when relevant source files are unmodified, which is worth being aware of when exploring solutions to this issue.

Expected State

Lambda functions only get deployed during terraform apply when the source code and/or local build artifacts are modified (at the very least in local (localstack) environments).

Implementation Plan

Explore the documentation for the terraform-aws-modules/lambda/aws module and/or explore other alternatives to optimize this aspect of the build process.

Relevant Code Snippets

No response

@TylerHendrickson TylerHendrickson added enhancement New feature or request good first issue Good for newcomers labels Apr 28, 2023
@TylerHendrickson TylerHendrickson moved this from 🆕 New to 📋 Backlog in Grants Team Agile Planning Apr 28, 2023
@TylerHendrickson TylerHendrickson moved this from 📋 Backlog to 🔖 Ready in Grants Team Agile Planning Apr 28, 2023
@jakekreider
Copy link
Contributor

A related issue discussed in Slack:
If the lambdas fail to build, at least in Localstack, it will still try to deploy them and can get stuck during the zip phase trying to package the parent directory. This probably wouldn't affect the AWS environments since the failed build would fail the CI check, but it can snarl local environments in the right circumstances. Ideally, if any steps in the commands fail, it would stop there & fail the tf apply.

TylerHendrickson added a commit that referenced this issue Aug 22, 2023
* Add TF module for building Lambda artifacts

* Refactor terraform to build Lambdas with new module

* Taskfile: add PersistFFISData to task:build helper

* Add go and taskfile setup to "Validate and plan terraform" CI job
@github-project-automation github-project-automation bot moved this from 🔖 Ready to ✅ Done in Grants Team Agile Planning Aug 22, 2023
@TylerHendrickson
Copy link
Member Author

Builds currently generate inconsistent checksums in different VCS scenarios (git state is clean/dirty, different checked out commits, etc.). Reopening to address.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers Grant Finder
Projects
Archived in project
3 participants