英文:
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 -> 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) 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 = "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
<br/>provider registry.terraform.io/hashicorp/archive v2.2.0
<br/>provider registry.terraform.io/hashicorp/aws v4.15.1
<br/>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 >= 4.25.0.
[1]: https://github.com/hashicorp/terraform-provider-aws/blob/main/CHANGELOG.md#4250-august--4-2022
</details>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论