属性值类型不正确。 sttributes "subnets: set of string required." 的值不合适

Incorrect attribute value type. Inappropriate value for sttributes "subnets: set of string required."

我已经多次传递子网 ID,以前从未遇到过此错误,我真的不确定为什么或如何解决它。

我的 VPC 模块中有我的子网资源块:

resource "aws_subnet" "subnet_1" {
  vpc_id            = aws_vpc.vpc_1.id
  cidr_block        = "10.0.0.0/24"
  availability_zone = var.region_az

  tags = {
    Name = "pcp-subnet-1"
  }
}

这是我的子网输出的输出文件的样子:

output "subnet_1" {
  value = aws_subnet.subnet_1.id
}

这是我调用子网id输出的根模块

module "ecs" {
  source = "./ecs"

  service_subnets  = module.vpc.subnet_1
  pcp_service_sg = module.vpc.pcp_service_sg
}

在我的 ecs 模块中,变量文件中列出了这里的变量

variable "service_subnets" {
  type = string
}

这是我发生错误的ecs资源

resource "aws_ecs_service" "ecs-service" {
  name            = "python-cloud-project"
  cluster         = aws_ecs_cluster.cluster.id
  task_definition = aws_ecs_task_definition.pcp-ecs-task-definition.arn
  launch_type     = "FARGATE"
  network_configuration {
    subnets         = var.service_subnets
    security_groups = var.pcp_service_sg
    assign_public_ip = true
  }
  desired_count = 1
}

network_configuration 需要一个子网列表,您只传递一个子网。您可以做的是创建一个包含一个元素的列表:

module "ecs" {
  source = "./ecs"

  service_subnets  = [module.vpc.subnet_1]
  pcp_service_sg = module.vpc.pcp_service_sg
}