How to fetch data of Terraform .tf file using PowerShell? like we use for XML files:
(Get-Content -Path "C:\Desktop\strings.xml") -as [xml]
Is there is other way to fetch terraform file?
If you do not mind using an open source project I would suggest converting HCL to JSON by applying hcl2json library. The executable can be downloaded from here: https://github.com/tmccombs/hcl2json/releases
Then you can invoke the process from PowerShell against your .tf or .tfvars file. The outcome should be this:
(& .\hcl2json_windows_amd64.exe -simplify "dev.shared.tfvars" | ConvertFrom-Json).key_vault_settings
Terraform has its own configuration language. You need a custom parser for being able to parse that into PowerShell data structures. However, the documentation mentions that Terraform supports JSON format as an alternative to the native language. You should be able to import configuration files written as JSON like this:
Get-Content 'C:\Desktop\input.tf.json' | Out-String | ConvertFrom-Json
or like this if you're running PowerShell v3 or newer:
Get-Content 'C:\Desktop\input.tf.json' -Raw | ConvertFrom-Json