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

Hi.

Upgrading the AWS provider:

$ terraform --version
Terraform v1.6.4
on darwin_amd64
+ provider registry.terraform.io/cloudflare/cloudflare v4.20.0
+ provider registry.terraform.io/hashicorp/aws v5.28.0
+ provider registry.terraform.io/hashicorp/external v2.3.2
+ provider registry.terraform.io/hashicorp/local v2.4.0
+ provider registry.terraform.io/hashicorp/time v0.9.2

Your version of Terraform is out of date! The latest version
is 1.6.5. You can update by downloading from https://www.terraform.io/downloads.html

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, var.name, 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/load_balancer.tf 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
+ ruleset.aws (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.