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

Setting docker_additional_options --platform causes package build to fail #512

Closed Jake-Gillberg closed 8 months ago

Jake-Gillberg commented 10 months ago

Description

Please provide a clear and concise description of the issue you are encountering, and a reproduction of your configuration (see the examples/* directory for references that you can copy+paste and tailor to match your configs if you are unable to copy your exact configuration). The reproduction MUST be executable by running terraform init && terraform apply without any further changes.

If your request is for a new feature, please use the Feature request template.

⚠️ 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

Reproduction Code [Required]

provider "aws" {
  region = "eu-west-1"
}

resource "random_pet" "this" {
  length = 2
}

module "lambda_function" {
  source = "terraform-aws-modules/lambda/aws"

  publish = true

  function_name = "${random_pet.this.id}-lambda-simple"
  handler       = "index.lambda_handler"
  runtime       = "python3.8"

  source_path = "${path.module}/../fixtures/python3.8-app1/"

  source_path = [
    "${path.module}/../fixtures/python3.8-app1/index.py",
    {
      pip_requirements = "${path.module}/../fixtures/python3.8-app1/requirements.txt"
      prefix_in_zip = "vendor"
    }
  ]

  build_in_docker = true
  docker_file = "${path.module}/../fixtures/python3.8-app1/docker/Dockerfile"
  docker_build_root = "${path.module}/../../docker"
  docker_image = "myImage"
  docker_additional_options = [
    "--platform", "linux/amd64"
  ]
}

Steps to reproduce the behavior:

Not using workspaces, have tried clearing the local cache.

On an aarch64 machine with multi-platform capabilities: Build the above example

Expected behavior

Lamda package builds successfully using the platform specified in docker_additional_options

Actual behavior

Lambda package build fails: the docker image is built without passing in the additional docker options, resulting in an image with the host architecture (aarch64), causing the package step to fail when it tries to find the docker image with the specified additional platform (linux/amd64), but can't find it.

tgip-work commented 10 months ago

Hi @Jake-Gillberg, maybe this helps: It is the other way around: building arm64 based packages on x86 system while - from my understanding - you want to build x86 on arm64 (mac m2?), right?. I use this terraform module within a Github workflow to build Lambda Layers for platform "linux/arm64". As the public Github Runners are x86_x64 based, just setting docker_additional_options = ["--platform", "linux/arm64"] does not work and leads to an error error.

So I installed QEMU (via Github action) before running terraform apply and it works now.

      - name: Install QEMU
        uses: docker/setup-qemu-action@68827325e0b33c7199eb31dd4e31fbe9023e06e3 # v3.0.0
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.