title: AWS VPC module public and private subnets - Terraform
body: <p>I'm trying to create AWS vpc environment with public and private subnet which I create with "template_file", however, I'm facing issues with defining the public and private subnets inside the VPC module.</p>
  
  <p>I'v generated my subnets using:</p>
  
  <pre><code>data "template_file" "cidrsubnets" {
    count = var.subnet_count[terraform.workspace]
  
    template = "$${cidrsubnet(vpc_cidr,8,current_count)}"
  
    vars = {
      vpc_cidr      = var.network_address_space[terraform.workspace]
      current_count = count.index
    }
  }
  </code></pre>
  
  <p>Inside the VPC module, the above code adds all my subnets into public subnets (works):</p>
  
  <pre><code>module "vpc" {
    source = "terraform-aws-modules/vpc/aws"
    name   = "${local.prefix}-vpc"
  
    cidr            = var.network_address_space[terraform.workspace]
    azs             = slice(data.aws_availability_zones.available.names, 0, var.subnet_count[terraform.workspace])
    public_subnets  = data.template_file.cidrsubnets[*].rendered
    private_subnets = []
  
    create_database_subnet_group = false
    enable_dns_hostnames         = true
    enable_nat_gateway           = true
    enable_s3_endpoint           = true
    enable_dynamodb_endpoint     = true
  
    tags = local.common_tags
  }
  </code></pre>
  
  <p>However, I want to add the even subnets in the list to the public subnets and the odd subnets in the list to the private subnets.
  I still haven't split the subnets into private and public automatically (that what I need), but tried to add specific elements inside the lists and got the error above:
  <a href="https://i.stack.imgur.com/MI8ER.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/MI8ER.png" alt="enter image description here"></a></p>
  
  <p>Can you help with this? Thank you for the response.</p>