Reading env variable thats a list of regions?

Packer 1.7.8

I have a shell script that contains a command that makes a list

AWS_REGIONS=$(aws ec2 --region=us-east-1 describe-regions | jq -r '.Regions[].RegionName'  | awk '{ print "\""$0"\""}'  | paste -sd "," - )

and its set as an env variable.

then packer is supposed to pick the list up and use it for ami_regions in an amazon-ebs block.

it does this in a variable like so

variable "aws_ami_regions" { 
  default = [ env("AWS_REGIONS") ] 
}

this fails with a misleading error

* Error Copying AMI (ami-123456789) to region ("af-south-1","eu-north-1","ap-south-1","eu-west-3","eu-west-2","eu-west-1","ap-northeast-3","ap-northeast-2","ap-northeast-1","sa-east-1","ca-central-1","ap-southeast-1","ap-southeast-2","eu-central-1","us-east-1","us-east-2","us-west-1","us-west-2"): MissingEndpoint: 'Endpoint' configuration is required for this service

I have tried different ways of formatting the list and all fail.
if i take the list directly from the error and paste it into the variable, it works.

variable "aws_ami_regions" { 
  default = [ "af-south-1","eu-north-1","ap-south-1","eu-west-3","eu-west-2","eu-west-1","ap-northeast-3","ap-northeast-2","ap-northeast-1","sa-east-1","ca-central-1","ap-southeast-1","ap-southeast-2","eu-central-1","us-east-1","us-east-2","us-west-1","us-west-2" ] 
}

i tried passing it through with:
packer build -var AWS_REGIONS="$AWS_REGIONS"

packer console is your friend in these situations:

$ cat main.pkr.hcl 
variable "aws_ami_regions" { 
  default = [ env("AWS_REGIONS") ] 
}

variable "aws_ami_regions2" {
  default = [ "af-south-1","eu-north-1","ap-south-1","eu-west-3","eu-west-2","eu-west-1","ap-northeast-3","ap-northeast-2","ap-northeast-1","sa-east-1","ca-central-1","ap-southeast-1","ap-southeast-2","eu-central-1","us-east-1","us-east-2","us-west-1","us-west-2" ]
}

 $ packer console main.pkr.hcl 
> variables
> > input-variables:

var.aws_ami_regions: "[\n  \"\\\"eu-north-1\\\",\\\"ap-south-1\\\",\\\"eu-west-3\\\",\\\"eu-west-2\\\",\\\"eu-west-1\\\",\\\"ap-northeast-3\\\",\\\"ap-northeast-2\\\",\\\"ap-northeast-1\\\",\\\"sa-east-1\\\",\\\"ca-central-1\\\",\\\"ap-southeast-1\\\",\\\"ap-southeast-2\\\",\\\"eu-central-1\\\",\\\"us-east-1\\\",\\\"us-east-2\\\",\\\"us-west-1\\\",\\\"us-west-2\\\"\",\n]"
var.aws_ami_regions2: "[\n  \"af-south-1\",\n  \"eu-north-1\",\n  \"ap-south-1\",\n  \"eu-west-3\",\n  \"eu-west-2\",\n  \"eu-west-1\",\n  \"ap-northeast-3\",\n  \"ap-northeast-2\",\n  \"ap-northeast-1\",\n  \"sa-east-1\",\n  \"ca-central-1\",\n  \"ap-southeast-1\",\n  \"ap-southeast-2\",\n  \"eu-central-1\",\n  \"us-east-1\",\n  \"us-east-2\",\n  \"us-west-1\",\n  \"us-west-2\",\n]"