terraform-aws-lambda icon indicating copy to clipboard operation
terraform-aws-lambda copied to clipboard

Ability to ignore changes to image_uri when function updates are performed outside of Terraform

Open danielwhatmuff opened this issue 11 months ago • 19 comments

Is your request related to a new offering from AWS?

No

Is your request related to a problem? Please describe.

When managing docker/ECR based lambda deployments outside of Terraform (e.g. through CI/CD using the AWS CLI aws lambda update-function-code --image-uri ...) it would be good to have the ability to ignore image_uri.

This would enable consumers to continue making changes to function configuration and IAM policy etc using Terraform but continously deploy new image versions to the function via CI/CD.

Describe the solution you'd like.

Support a new boolean variable to ignore changes to image_uri e.g. ignore_image_uri. Similar to the ignore_source_code_hash variable used for ignoring changes to zip based functions. Due to the frustrating limitation of not being able to conditionally define lifecycle ignore_changes, this would likely need to be two lambda resource blocks - one with, one without the ignore.

Describe alternatives you've considered.

No known alternative, ignore_source_code_hash does not ignore changes to image_uri.

Additional context

A workflow I use to manage Lambda functions is to initially provision functions using Terraform with a placeholder image held in ECR and then setup CI/CD to iterate the docker image version. When changes to IAM policy or concurrency are made in Terraform there is unwanted drift detected with image_uri.

danielwhatmuff avatar Jan 02 '25 14:01 danielwhatmuff

Would also love this.

StanDeeks avatar Jan 22 '25 23:01 StanDeeks

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] avatar Feb 22 '25 00:02 github-actions[bot]

Commenting here to remove stale, this is absolutely a requirement for our use case also. We need to initialise the "shell" of the lambda using Terraform but then use a separate CI/CD process to actually build and release the referenced container

jgalliers avatar Mar 03 '25 04:03 jgalliers

+1

I'll fork this for now and make my own edits since I'll never need to track the image_uri.

johnecapps avatar Mar 26 '25 13:03 johnecapps

+1 Also forking since I do need this change too. It's important to have it

fergo2910 avatar Apr 11 '25 18:04 fergo2910

+1, this would be very helpful!

apenney avatar Apr 14 '25 14:04 apenney

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] avatar May 15 '25 00:05 github-actions[bot]

Not stale, also looking for solution to this.

jussapaavo avatar May 15 '25 06:05 jussapaavo

i cant use this because of this same issue, environment variables as well.

tylerbartlett-fq avatar Jun 13 '25 14:06 tylerbartlett-fq

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] avatar Jul 14 '25 00:07 github-actions[bot]

+1

ggrangia avatar Jul 14 '25 12:07 ggrangia

+1

young-arbital avatar Aug 09 '25 01:08 young-arbital

For anyone who needs a workaround, this is what I do:

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

  function_name = "foo"
  image_uri     = "${var.image_uri}:${data.aws_ssm_parameter.image_tag.value}"

  [...]
}

resource "aws_ssm_parameter" "image_tag" {
  name  = "/lambdas/foo/image_tag"
  type  = "String"
  value = "latest"

  lifecycle {
    ignore_changes = [value]
  }
}

data "aws_ssm_parameter" "image_tag" {
  name = aws_ssm_parameter.image_tag.name
}

The application's pipeline builds and pushes a new container image to ECR, then calls aws lambda update-function-code to point the Lambda to that image. It also updates the image_tag SSM parameter so that Terraform’s computed image_uri remains in sync, avoiding drift while still letting Terraform manage the function’s other config.

ntse avatar Aug 12 '25 10:08 ntse

We are facing this issue too @fergo2910 @johnecapps can you share your fork?

simonweil avatar Aug 17 '25 14:08 simonweil

Also facing this issue.

lumenisaac avatar Sep 15 '25 19:09 lumenisaac

+1

juliancuretti-bc avatar Oct 07 '25 19:10 juliancuretti-bc

Can't we just mimic the ignore_source_code_hash? Sadly, I cannot do it as I need the fix for an older version, as I cannot upgrade the aws provider, so I cannot test this

But I found a quick workaround

data "aws_lambda_function" "api_function_xsmall" {
  count         = local.create_xsmall_lambda ? 1 : 0
  function_name = format("%s-api-xsmall", var.env)
}

Then added to the module

image_uri      = coalesce(try(data.aws_lambda_function.api_function_xsmall[0].image_uri, null), local.lambda_image_uri)

So if it's the first time installing it will take the version of latest version or anything else you want, but after that it will always take the current version

ofirshtrull avatar Oct 15 '25 18:10 ofirshtrull

+1 This can be very useful.

talsh-oasis avatar Nov 11 '25 12:11 talsh-oasis

+1 Here i need ignore env variables

axel-wejungle avatar Nov 14 '25 14:11 axel-wejungle