简体   繁体   English

Terraform 可以将来自 for_each 循环的变量与字符串连接起来吗

[英]Can Terraform concatenate variables fed from a for_each loop with a string

I am building some webapps in Azure.我正在 Azure 中构建一些 webapps。 I have a variables.tf file with a list of webapps.我有一个带有 webapps 列表的 variables.tf 文件。 Along with a few other variables Sorry if the formatting is a bit wonky连同其他一些变量 对不起,如果格式有点不稳定

variable "webapps" {
    type = map
     default = {
        app1 = "apple"
        app2 = "pear"
        app3 = "peach"
 }
variable "location" {
        type = string
         default = "westus"
     }
variable "platform" {
        type = string
         default = "qa"
     }

I have a webapps.tf file in which currently I am doing aa simple for_each loop to assign the name.我有一个 webapps.tf 文件,目前我正在执行一个简单的 for_each 循环来分配名称。

resource "azurerm_app_service" "web"
    for_each = var.webapps
    name = each.value
    ... the rest of the code for the app service

Now that works well enough it creates the apps with the names from the variable file.现在它运行得很好,它使用变量文件中的名称创建应用程序。

However I would like to do something like但是我想做类似的事情

resource "azurerm_app_service" "web"
    for_each = var.webapps
    name = each.value join("",["-dev", var.location, var-platform])

I have not been able to figure it out.我一直无法弄清楚。 I saw some older code using length and count.index, but I was hoping I could do something a little simpler.我看到一些使用 length 和 count.index 的旧代码,但我希望我可以做一些更简单的事情。

Any thoughts?有什么想法吗?

You can just write:你可以写:

name = join("",[each.value, "-dev", var.location, var.platform])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM