Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Modify simple list/array in Terraform

I have a next list:

azs = ["us-east-1a", "us-east-1b", "us-east-1c"]

And I am using it during subnets creation. In names of subnets I would like to use short names like a, b, c so I need a list ["a", "b", "c"]. Obviously I need to generate it dynamically (in locals block for example) when azs will be set manually.

How to create such list with Terraform?

like image 833
ipeacocks Avatar asked Feb 01 '26 13:02

ipeacocks


1 Answers

You can use the formatlist function here to format a list.

It uses the string format syntax, taking n lists and returning a single list.

So in your case you probably want something like:

locals {
  azs = [
    "a",
    "b",
    "c",
  ]
}

output "azs" {
  value = "${formatlist("us-east-1%s", local.azs)}"
}
like image 123
ydaetskcoR Avatar answered Feb 03 '26 02:02

ydaetskcoR