amazon-web-servicesterraformterraform-provider-awsaws-application-load-balanceraws-elb

Terraform application load balancer argument is not expected here


I currently work on an AWS architecture that looks like this : NLB -> ALB -> API Gateway -> Lambda

When I deploy my architecture, the Preserve host header attribute of the ALB is set to false. I want it set to true.

As from Terraform doc https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/lb :

Here is my Application Load Balancer configuration :

resource "aws_lb" "alb_to_api_gateway" {
      name               = "prd-alb-toapigw"
      internal           = true
      load_balancer_type = "application"
      security_groups = [var.default_SG]
      subnets    = [var.subnet_backend_a, var.subnet_backend_b]
    
      preserve_host_header = true
    
      access_logs {
        bucket  = aws_s3_bucket.elb_logs.id
        prefix  = "ALB"
        enabled = true
      }
    
      depends_on = [
       aws_s3_bucket_policy.policy_alb
      ]
    }

This configuration worked perfectly until I added the preserve_host_header argument which creates this error :

│ Error: Unsupported argument
│ 
│   on elb.tf line 12, in resource "aws_lb" "alb_to_api_gateway":
│   12:   preserve_host_header = true
│ 
│ An argument named "preserve_host_header" is not expected here.

I use Terraform v1.3.9 on linux_amd64
provider registry.terraform.io/hashicorp/archive v2.2.0
provider registry.terraform.io/hashicorp/aws v4.15.1
aws-cli/2.11.0 Python/3.11.2 Linux/5.4.0-1045-aws exe/x86_64.ubuntu.20 prompt/off

Thank you


Solution

  • The preserve_host_header argument was added in version 4.25.0 of the AWS provider, and you would therefore need to update the provider from 4.15.1 to >= 4.25.0.