Regex error with aws_ami data function

When I execute the following, I get the desire results in the Ami name.
2023-05-16-77777-xxx-aaa-wwww #The name of the customer’s AMI

However, when I try to use regex to get the xxx column of the customer’s AMI name (version number). after commenting out example one
and uncomment example Two.
I get the following error:

Error: Invalid function argument

on line 33, in output "customer_ami_name"
33:  value = regex("^(?:[^-]+-){4}([^-]+)",]) will be know only after apply
 Invalid value for "string" parameter: string requried 
#Declare the aws providers
terraform {
   required_version = "~> 1.2"
   required_providers {
      aws = {
	    source = "hashicorp/aws"
		version = "2.2.0"

provider "aws" {
  region = "us-east-1"

locals {
     cus_ami_id = "ami-xxxxxxxxx"

data "aws_ami" "customer_ami" {
    owners = ["xxxxxxxxxx"]
	filter {
	   name = "image-id"
	   values =  ["${local.cus_ami_id}"]

output "customer_ami_name" {
   #value = [] #example One
   value = regex("^(?:[^-]+-){4}([^-]+)",]) #example Two


Hi @mmauney,

The configuration examples you shared seem to have invalid syntax and so could not possibly produce the error message you shared. It looks like you have also edited the error message text since it contains some spelling errors that don’t match the exact text Terraform would produce in that situation.

I’m afraid I can’t help if you cannot share exactly the configuration you tried and exactly the error message Terraform returned, because otherwise I’d be trying to debug some code that you didn’t actually run.

If your code contains parts that you cannot share for some reason then an alternative would be to reproduce just your specific problem in a separate small Terraform configuration that doesn’t include anything else and then, once you’ve confirmed that the smaller configuration produces an equivalent error, share that configuration and your error. The exercise of producing a simpler example can also sometimes be helpful in solving a problem for yourself, because it requires looking at the problem from a different perspective.