Skip to content

Instantly share code, notes, and snippets.

@sergsoares
Created May 9, 2022 14:32
Show Gist options
  • Save sergsoares/0199487d425a347fea988d8a98f36565 to your computer and use it in GitHub Desktop.
Save sergsoares/0199487d425a347fea988d8a98f36565 to your computer and use it in GitHub Desktop.
Terraform example for process a list of names, adding a domain and join all in a single string.
# File: main.tf
locals {
# Static variables
domain = "domain.com"
name_list = [
"name1",
"name2",
"name3"
]
# Formatted variables
list_format = formatlist("%s.${local.domain}", local.name_list)
string_variable = join(",", formatlist("%s.${local.domain}", local.name_list))
}
$ terraform console
> local.domain
"domain.com"
> local.name_list
[
"name1",
"name2",
"name3",
]
> local.list_format
tolist([
"name1.domain.com",
"name2.domain.com",
"name3.domain.com",
])
> local.string_variable
"name1.domain.com,name2.domain.com,name3.domain.com"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment