【问题标题】:Terraform data dynamically using variables使用变量动态地形化数据
【发布时间】:2021-08-16 17:10:23
【问题描述】:

我想知道是否可以根据这样的变量动态获取不同的数据

data.terraform_remote_state.vm.outputs.vm_***var.vmname***

或者类似的东西?我目前没有重新设计输出的选项,这将大大降低在创建新的 terraform 部署时失败的机会

谢谢!

【问题讨论】:

    标签: azure terraform infrastructure-as-code


    【解决方案1】:

    Terraform 中有可用的输入变量。这些变量允许您定义在terraform apply 时预期的输入。这些值可以通过交互式终端输入或在.tfvars 文件中提供。

    variable "vmname" {
      type        = string
      description = "The name of the virtual machine."
    }
    

    然后你可以通过扩展来使用它们:

    "data.terraform_remote_state.vm.outputs.vm_${var.vmname}"
    

    如需更多参考,请参阅https://www.terraform.io/docs/language/values/variables.html

    【讨论】:

      猜你喜欢
      • 2016-03-24
      • 1970-01-01
      • 1970-01-01
      • 2020-04-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-27
      • 2016-02-04
      相关资源
      最近更新 更多