How do I handle the removal of vpc_id on an alb_lb_target_group for a lambda function?


Upgrading the AWS provider:

$ terraform --version
Terraform v1.6.4
on darwin_amd64
+ provider v4.20.0
+ provider v5.28.0
+ provider v2.3.2
+ provider v2.4.0
+ provider v0.9.2

Your version of Terraform is out of date! The latest version
is 1.6.5. You can update by downloading from

My original code for the AWS provider v4 was:

resource "aws_lb_target_group" "lambda" {
  for_each    = var.lb_collection
  name        = substr(replace(format("%s-%s-%s", var.app_ids.unique_env_code,, each.key), "_", "-"), 0, 32)
  target_type = "lambda"
  vpc_id      = var.vpc_id

All worked with no errors or warnings. All happy.

Upgrading to v5 and got the message:

│ Warning: Invalid Attribute Combination
│   with module.lambdas["queue_admin"].aws_lb_target_group.lambda["wildcards"],
│   on modules/lambda_resources/ line 4, in resource "aws_lb_target_group" "lambda":
│    4: resource "aws_lb_target_group" "lambda" {
│ Attribute "vpc_id" cannot be specified when "target_type" is "lambda".
│ This will be an error in a future version.
│ (and 2 more similar warnings elsewhere)

Read about it in Terraform Registry, and removed the vpc_id = var.vpc_id line.

Re-ran the plan and got exactly the same error. The plan hasn’t changed.

Running terraform show and extracting what the current state shows for the resource DOES have the vpc_id present (right value but now no longer required).

Sadly, terraform validate does not show this as an error, only as a warning as part of the plan. Also, using tflint:

$ tflint --version
TFLint version 0.48.0
+ (0.27.0)
+ ruleset.terraform (0.4.0-bundled)

with the latest ruleset doesn’t show this as an error.

I’m assuming applying the update to update the tfstate will remove the value from the tfstate and so make the code compatible?

It was sorted as part of the apply.