terraform-aws-modules / terraform-aws-lambda

Terraform module, which takes care of a lot of AWS Lambda/serverless tasks (build dependencies, packages, updates, deployments) in countless combinations 🇺🇦
https://registry.terraform.io/modules/terraform-aws-modules/lambda/aws
Apache License 2.0
909 stars 681 forks source link

Bug: Added support for triggers in docker-build module when hash changes #517

Closed IlyesDemineExtVeolia closed 8 months ago

IlyesDemineExtVeolia commented 10 months ago

Description

Even if triggers parameters is set, docker image is always rebuild.

Terraform plan result :

  # module.docker_image_lambda_actiflo_effluent_predict.docker_image.this will be created
  + resource "docker_image" "this" {
      + force_remove = false
      + id           = (known after apply)
      + image_id     = (known after apply)
      + keep_locally = false
      + name         = "423671310539.dkr.ecr.eu-west-1.amazonaws.com/vwt-insight-actiflo-effluent-predict-dev:1.0"
      + repo_digest  = (known after apply)
      + triggers     = {
          + "dir_lambda" = "304b10ee4074f39e8fb3ccc5eca832dadca25bea"
          + "dir_layer"  = "ffc5d2f69b1723ffb97a743f9632e922c31f9b59"
        }
      + build {
          + cache_from   = []
          + context      = "./.."
          + dockerfile   = "lambdas/actiflo_effluent/effluent/Dockerfile"
          + extra_hosts  = []
          + remove       = true
          + security_opt = []
          + tag          = []
        }
    }
  # module.docker_image_lambda_actiflo_effluent_predict.docker_registry_image.this must be replaced
-/+ resource "docker_registry_image" "this" {
      ~ id                   = "sha256:00b4edb112e88997f64c2d440ca76aa6d9ca27e3d0ef39117aa12877be17797e" -> (known after apply)
        name                 = "423671310539.dkr.ecr.eu-west-1.amazonaws.com/vwt-insight-actiflo-effluent-predict-dev:1.0"
      ~ sha256_digest        = "sha256:00b4edb112e88997f64c2d440ca76aa6d9ca27e3d0ef39117aa12877be17797e" -> (known after apply)
      ~ triggers             = { # forces replacement
          - "image_id" = "sha256:adab56e502a001ca849997c22bcbd8b2a656457ca208aedd2d3e052d3f4aab7d"
        } -> (known after apply) # forces replacement
        # (2 unchanged attributes hidden)
    }

⚠️ Note

Before you submit an issue, please perform the following first:

  1. Remove the local .terraform directory (! ONLY if state is stored remotely, which hopefully you are following that best practice!): rm -rf .terraform/
  2. Re-initialize the project root to pull down modules: terraform init
  3. Re-attempt your terraform plan or apply and check if the issue still persists

Versions

Terraform v1.5.2 on darwin_amd64

Reproduction Code

module "docker_image_lambda_actiflo_effluent_predict" {
  source  = "terraform-aws-modules/lambda/aws//modules/docker-build"
  version = "6.5.0"

  create_ecr_repo  = true
  ecr_repo         = "${local.project_name_actiflo_effluent}-predict-${var.env_name}"
  image_tag        = "1.0"
  docker_file_path = "lambdas/actiflo_effluent/effluent/Dockerfile"
  source_path      = "${path.module}/.."
  scan_on_push     = true
  triggers = { # rebuild only when one of this files changes
    dir_lambda = sha1(join("", [for f in fileset("${path.module}/..", "lambdas/actiflo_effluent/effluent/*") : filesha1("${path.module}/../${f}")])),
    dir_layer  = sha1(join("", [for f in fileset("${path.module}/..", "layers/utils_actiflo/*") : filesha1("${path.module}/../${f}")]))
  }
}

Steps to reproduce the behavior:

Expected behavior

No rebuild if files no changes

Actual behavior

Docker image is always rebuild

Terminal Output Screenshot(s)

image

Additional context

IlyesDemineExtVeolia commented 10 months ago

https://github.com/terraform-aws-modules/terraform-aws-lambda/pull/510

github-actions[bot] commented 9 months ago

This issue has been automatically marked as stale because it has been open 30 days with no activity. Remove stale label or comment or this issue will be closed in 10 days

github-actions[bot] commented 8 months ago

This issue was automatically closed because of stale in 10 days

github-actions[bot] commented 7 months ago

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.