Home > Software design >  Incorrect attribute value type. Inappropriate value for sttributes "subnets: set of string requ
Incorrect attribute value type. Inappropriate value for sttributes "subnets: set of string requ

Time:04-12

I've passed subnet ids many times and haven't encountered this error before, I'm really not sure why or how to fix it.

I have my subnet resource block right here in my VPC module:

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"
  }
}

This is what the outputs file looks like for my subnet output:

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

This is my root module calling the subnet id output

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

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

In my ecs module I have the variable listed here in my variables file

variable "service_subnets" {
  type = string
}

This is my ecs resource where the error is occurring

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
}

CodePudding user response:

network_configuration requires a list of subnets, you are passing only one subnet. What you can do is to create a list with one element:

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

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