Terraform应用负载均衡器参数不应在此处。

huangapple go评论72阅读模式
英文:

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 :

  • preserve_host_header - (Optional) 表示应用负载均衡器是否应在HTTP请求中保留Host标头并将其发送到目标而不进行任何更改。默认值为false.

Here is my Application Load Balancer configuration:

      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:


  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.```

<details>
<summary>英文:</summary>

I currently work on an AWS architecture that looks like this :
NLB -&gt; ALB -&gt; API Gateway -&gt; 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 :

 - `preserve_host_header` - (Optional) Indicates whether the Application Load Balancer should preserve the Host header in the HTTP request and send it to the target without any change. Defaults to false.


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  = &quot;ALB&quot;
    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
&lt;br/&gt;provider registry.terraform.io/hashicorp/archive v2.2.0
&lt;br/&gt;provider registry.terraform.io/hashicorp/aws v4.15.1
&lt;br/&gt;aws-cli/2.11.0 Python/3.11.2 Linux/5.4.0-1045-aws exe/x86_64.ubuntu.20 prompt/off

Thank you

</details>


# 答案1
**得分**: 3

`preserve_host_header`参数是在AWS提供程序的[版本4.25.0][1]中添加的,因此您需要将提供程序从4.15.1更新到≥4.25.0。

[1]: https://github.com/hashicorp/terraform-provider-aws/blob/main/CHANGELOG.md#4250-august--4-2022

<details>
<summary>英文:</summary>

The `preserve_host_header` argument was added in [version 4.25.0][1] of the AWS provider, and you would therefore need to update the provider from 4.15.1 to &gt;= 4.25.0.


  [1]: https://github.com/hashicorp/terraform-provider-aws/blob/main/CHANGELOG.md#4250-august--4-2022

</details>



huangapple
  • 本文由 发表于 2023年4月13日 23:36:45
  • 转载请务必保留本文链接:https://go.coder-hub.com/76007319.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定