【发布时间】:2023-03-29 04:19:02
【问题描述】:
我使用this module 在 VPC 中创建了一个安全组。其中一个输出是security_group_id,但我收到了这个错误:
│ Error: Unsupported attribute
│
│ on ecs.tf line 39, in resource "aws_ecs_service" "hello_world":
│ 39: security_groups = [module.app_security_group.security_group_id]
│ ├────────────────
│ │ module.app_security_group is a object, known only after apply
│
│ This object does not have an attribute named "security_group_id".
我需要 ECS 服务的安全组:
resource "aws_ecs_service" "hello_world" {
name = "hello-world-service"
cluster = aws_ecs_cluster.container_service_cluster.id
task_definition = aws_ecs_task_definition.hello_world.arn
desired_count = 1
launch_type = "FARGATE"
network_configuration {
security_groups = [module.app_security_group.security_group_id]
subnets = module.vpc.private_subnets
}
load_balancer {
target_group_arn = aws_lb_target_group.loadbalancer_target_group.id
container_name = "hello-world-app"
container_port = 3000
}
depends_on = [aws_lb_listener.loadbalancer_listener, module.app_security_group]
}
我了解安全组 ID 创建后才能知道。这就是为什么我在 ECS 节中添加了 depends_on 部分,但它一直返回相同的错误。
更新
我在 app_security_group 模块上将 count 指定为 1,这是我现在遇到的错误。
│ Error: Unsupported attribute
│
│ on ecs.tf line 39, in resource "aws_ecs_service" "hello_world":
│ 39: security_groups = module.app_security_group.security_group_id
│ ├────────────────
│ │ module.app_security_group is a list of object, known only after apply
│
│ Can't access attributes on a list of objects. Did you mean to access an attribute for a specific element of the list, or across all elements of the list?
更新二
这是模块声明:
module "app_security_group" {
source = "terraform-aws-modules/security-group/aws//modules/web"
version = "3.17.0"
name = "${var.project}-web-sg"
description = "Security group for web-servers with HTTP ports open within VPC"
vpc_id = module.vpc.vpc_id
# ingress_cidr_blocks = module.vpc.public_subnets_cidr_blocks
ingress_cidr_blocks = ["0.0.0.0/0"]
}
【问题讨论】:
-
你在
app_security_group模块上有count吗? -
@ErvinSzilagyi 我现在添加了一个,计数为 1,但我仍然收到类似的错误。请查看我更新的问题。
-
什么是模块声明?
-
不,您不应该添加
count,只要它不是必需的(例如:您需要多个资源)。当您在模块上有count时,可能会在某些情况下出现此错误This object does not have an attribute named。看来这不是您的问题 -
@MattSchuchard 我已将其添加到问题中
标签: amazon-web-services terraform amazon-ecs terraform-provider-aws