How to add unequal number of vpc settings to diff aws systems?

We have a code deployed in 2 different environments in aws: test system & prod system.

In the test system, we have 3 subnets & 1 security group which have to be attached to the lambda.

In the prod system, we have 1 subnet & 2 security groups that have to be attached to the lambda. ( I know it is not a good practice to have just 1 subnet).

I would like to declare these in the serverless.yml file itself. I tried

provider:
  name: aws
  runtime: python3.6
  stage: ${opt:stage, 'test'}
  lambdaHashingVersion: 20201221
  region: ${env:AWS_DEFAULT_REGION}
  vpc:
    securityGroupIds:
      - ${self:custom.securityGroupIds.${self:provider.stage}1}
      - ${self:custom.securityGroupIds.${self:provider.stage}2}
    subnetIds:
      - ${self:custom.subnetIds.${self:provider.stage}1}
      - ${self:custom.subnetIds.${self:provider.stage}2}
      - ${self:custom.subnetIds.${self:provider.stage}3}

custom:
  securityGroupIds:
    test1: sg-xxxxxxxxxxx
    test2: ''
    prod: sg-yyyyyyyyyyy
  subnetIds:
    test1: subnet-xxxxxxxxxx
    test2: subnet-yyyyyyyyyy
    test3: subnet-zzzzzzzzzz
    prod1: subnet-aaaaaaaaaa
    prod2: ''
    prod3: ''
  pythonRequirements:
    dockerizePip: non-linux

functions:
  ec-frankfurt:
    handler: lambda_function.lambda_handler
    timeout: 60
    memorySize: 512

When the code is deployed via CI/CD, it throws an error.

Is there a way how I can declare the vpc settings for this case?

Thanks