我使用這個模塊在 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。這就是為什么我depends_on在 ECS 節中添加了該部分,但它一直回傳相同的錯誤。
更新
我count在 app_security_group 模塊上指定為 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"]
}
uj5u.com熱心網友回復:
我看了一下那個模塊。問題是3.17.0模塊的版本根本沒有security_group_id. 您使用的是非常舊的版本。
該站點的最新版本是4.7.0,您可能希望升級到此版本。事實上,上面的任何版本4.0.0都有security_group_id,所以你至少需要4.0.0.
uj5u.com熱心網友回復:
當您使用計數時,請嘗試以下操作。
network_configuration {
security_groups = [module.app_security_group[0].security_group_id]
subnets = module.vpc.private_subnets
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/377884.html
標籤:亚马逊网络服务 地形 亚马逊-ecs terraform-provider-aws
