Pierre-Alexandre
Pierre-Alexandre

Reputation: 775

regex to string

I am trying to just use the value before the @ symbol as a value for my name during the creation of my ressource. However, I got an error: Inappropriate value for attribute "email": string required. my regex is working on the terraform console so I think it's more an error on where I am applying this regex function.

main.tf

resource "aws_organizations_account" "account" {
  for_each  = local.all_users
  name      = "${regex("(.*)@", "[email protected]")}"
  email     = "[email protected]"
  role_name = "Administrator"
  parent_id = var.sandbox_organizational_unit_id
}

I also tried "${tostring(regex("(.*)@", "[email protected]"))}" and I got a different error, Invalid value for "v" parameter: cannot convert tuple to string.

Upvotes: 0

Views: 137

Answers (1)

Marcin
Marcin

Reputation: 238897

It should be:

name      = regex("(.*)@", "[email protected]")[0]

Upvotes: 2

Related Questions