【发布时间】:2019-07-30 05:15:52
【问题描述】:
如何使用 PowerShell 获取 Terraform .tf 文件的数据? 就像我们用于 XML 文件一样:
(Get-Content -Path "C:\Desktop\strings.xml") -as [xml]
还有其他获取 terraform 文件的方法吗?
【问题讨论】:
标签: powershell terraform terraform-template-file
如何使用 PowerShell 获取 Terraform .tf 文件的数据? 就像我们用于 XML 文件一样:
(Get-Content -Path "C:\Desktop\strings.xml") -as [xml]
还有其他获取 terraform 文件的方法吗?
【问题讨论】:
标签: powershell terraform terraform-template-file
Terraform 有自己的configuration language。您需要一个自定义解析器才能将其解析为 PowerShell 数据结构。但是,文档提到 Terraform supports JSON format 作为母语的替代品。您应该能够像这样导入以 JSON 格式编写的配置文件:
Get-Content 'C:\Desktop\input.tf' | Out-String | ConvertFrom-Json
如果您正在运行 PowerShell v3 或更新版本,则可以这样:
Get-Content 'C:\Desktop\input.tf' -Raw | ConvertFrom-Json
【讨论】: