英文:
Error: Unsupported argument terraform ecs with load balancer
问题
我理解你遇到了一个Terraform配置文件的问题。你的问题是如何选择在alb
模块中定义的目标组。根据你的配置文件,你可以在aws_ecs_service
资源的load_balancer
块中使用target_group_arns
参数来选择目标组,像这样:
load_balancer {
target_group_arns = [module.alb.target_group_arns[0]]
container_name = "${aws_ecs_task_definition.nodejs.family}"
container_port = 8080
}
在这里,我们使用[0]
来选择alb
模块中的第一个目标组。这应该解决你的问题。
如果你还有其他问题,请随时提出。
英文:
appreciate your support in solving this issue i have main.tf file like below
resource "aws_ecs_service" "nodejs-service" {
name = "nodejs-service"
cluster = aws_ecs_cluster.project_cluster.id
task_definition = aws_ecs_task_definition.nodejs.arn
launch_type = "FARGATE"
desired_count = 1
load_balancer {
target_group_arns = module.alb.target_group_arns
container_name = "${aws_ecs_task_definition.nodejs.family}"
container_port = 8080 # Specifying the container port
}
network_configuration {
subnets = var.vpc.public_subnets
assign_public_ip = true
}
}
module "alb" {
source = "terraform-aws-modules/alb/aws"
version = "~> 8.0"
name = var.namespace
load_balancer_type = "application"
vpc_id = var.vpc.vpc_id
subnets = var.vpc.public_subnets
security_groups = [var.sg.lb]
http_tcp_listeners = [
{
port = 80
protocol = "HTTP"
target_group_index = 0
}
]
target_groups = [
{ name_prefix = "nodejs-service"
backend_protocol = "HTTP"
backend_port = 8080
target_type = "instance"
}
]
}
i receive error
│ Error: Unsupported argument
│
│ on modules/ecs/main.tf line 58, in resource "aws_ecs_service" "nodejs-service":
│ 58: target_group_arns = module.alb.target_group_arns
│
│ An argument named "target_group_arns" is not expected here. Did you mean "target_group_arn"?
even if i changed target_groups on the service parameters to be target_group_arn i receive error "target_group_arn" is not defined
also with module.alb.target_groups[0] the same error appear with terraform plan
load_balancer {
target_group_arn = module.alb.target_groups[0]
container_name = "${aws_ecs_task_definition.nodejs.family}"
container_port = 8080 # Specifying the container port
}
Error:
│ Error: Unsupported attribute
│
│ on modules/ecs/main.tf line 58, in resource "aws_ecs_service" "nodejs-service":
58: target_group_arn = module.alb.target_groups[0]
├────────────────
│ module.alb is a object
This object does not have an attribute named "target_groups".
as per main.tf file how can i select the target group which is defined in alb module
Thanks,
tried: terraform plan and expected alb with target group pointing on nodejs-service container
terraform {
required_version = ">= 1.0"
required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 4.27"
}
null = {
source = "hashicorp/null"
version = ">= 2.0"
}
}
}
答案1
得分: 1
来自模块 alb 的输出是一个数组。
在你的情况下,它将是 module.alb.target_group_arns[0]
。
请将其替换为以下代码:
load_balancer {
target_group_arns = module.alb.target_group_arns[0]
container_name = "${aws_ecs_task_definition.nodejs.family}"
container_port = 8080 # 指定容器端口
}
英文:
output from the module alb is an array.
In your case it would be module.alb.target_group_arns[0]
Replace it with this code
load_balancer {
target_group_arns = module.alb.target_group_arns[0]
container_name = "${aws_ecs_task_definition.nodejs.family}"
container_port = 8080 # Specifying the container port
}
答案2
得分: 1
问题并不在模块中,而是在你尝试在aws_ecs_service
资源中使用的参数中。你目前将其设置为target_group_arns
,而参数是单数的,即target_group_arn
[1]:
load_balancer {
target_group_arn = module.alb.target_group_arns[0]
container_name = "${aws_ecs_task_definition.nodejs.family}"
container_port = 8080 # 指定容器端口
}
这个示例是使用模块返回的第一个目标组,所以请确保你正在使用正确的目标组。
英文:
The issue is not in the module, rather in the argument you are trying to use in the aws_ecs_service
resource. You are currently setting it to target_group_arns
while the argument is singular, i.e., target_group_arn
[1]:
load_balancer {
target_group_arn = module.alb.target_group_arns[0]
container_name = "${aws_ecs_task_definition.nodejs.family}"
container_port = 8080 # Specifying the container port
}
The example is with the first of the target groups returned from the module, so make sure you are using the correct one.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论