'Output of Build.Repository.Name from a powershell script running in data external of Terraform

I need to fetch the Azure DevOps Repository Name (output of Build.Repository.Name) from a powershell script that is running in Terraform external data source in Terraform script. But I am getting blank output. Below is the script to refer. Am I calling the system build variable correctly in powershell? Kindly check and help here.

Terraform main.tf

    data "external" "repo" {
  program = ["pwsh", "${abspath(path.module)}/fetch_repo_name.ps1"]
  query = {
    always = timestamp()
  }
}

Powershell Script

    [CmdletBinding()]
$jsonpayload = [Console]::In.ReadLine()
$json = ConvertFrom-Json $jsonpayload

$always = $json.always

$outputJson = @{RepoName = $($env:BUILD_Repository_Name);} | ConvertTo-Json

    Write-Output $outputJson

Output

Plan: 0 to add, 0 to change, 0 to destroy.

Changes to Outputs:
  + repo-name = [
      + (known after apply),
    ]
data.external.repo: Reading...
data.external.repo: Read complete after 1s [id=-]

Apply complete! Resources: 0 added, 0 changed, 0 destroyed.

Outputs:

repo-name = [
  tomap({
    "RepoName" = ""
  }),
]


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source